Poderosa项目 - 终端控制与串行端口连接一起使用 [英] Poderosa Project - Terminal Control use with serial port connection

查看:102
本文介绍了Poderosa项目 - 终端控制与串行端口连接一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将SerialPort接收的数据导向终端控件。

你可以指导我如何实现它吗??

i尝试了以下内容:

I'm trying to direct the SerialPort received data to the terminal control.
can you direct me how to achieve it..?
i tried the following:

SerialTerminalParam stp = new SerialTerminalParam();
stp.BaudRate = int.Parse(cmbBaudRate.Text);
stp.FlowControl = FlowControl.None;
stp.Parity = Poderosa.ConnectionParam.Parity.NOPARITY;
stp.Port = 1;
stp.StopBits = Poderosa.ConnectionParam.StopBits.ONESTOPBIT;
stp.TerminalType = TerminalType.XTerm;

      
           
IntPtr pt = new IntPtr();
SerialTerminalConnection con = new SerialTerminalConnection(stp,  pt,624, 249);
ConnectionTag ct = new ConnectionTag(con);
TerminalDataReceiver tdr = new TerminalDataReceiver(ct);





但我得到一个错误说:对象引用未设置为对象的实例。

在以下行(@ TerminalControl \Terminal\connections.cs ):

GEnv.Connections.KeepAlive.SetTimerToConnectionTag(this);



你知道什么是打开串行连接所需的步骤?而是你给出的SSH连接作为例子...



but i'm getting an error saying: Object reference not set to an instance of an object.
at the following line (@ TerminalControl\Terminal\connections.cs):
GEnv.Connections.KeepAlive.SetTimerToConnectionTag(this);

do you know what are the required steps to open a serial connection? instead SSH connection you gave as an example...

推荐答案

int Port = 2;
int BaudRate = 115200;
ConnectionMethod = ConnectionMethod.Serial;
 
public void Connect()
        {
            // Save old log info in case this is a reconnect
            Poderosa.ConnectionParam.LogType logType = Poderosa.ConnectionParam.LogType.Default;
            string file = null;
            if (this.TerminalPane.Connection != null)
            {
                logType = this.TerminalPane.Connection.LogType;
                file = this.TerminalPane.Connection.LogPath;
                //GApp.GetConnectionCommandTarget().Close();
                this.TerminalPane.Connection.Close();
                this.TerminalPane.Detach();
            }
 
            try
            {
                if ((Poderosa.ConnectionParam.ConnectionMethod)this.Method == Poderosa.ConnectionParam.ConnectionMethod.Telnet)
                {
                    TelnetTerminalParam tel = new TelnetTerminalParam(this.Host);
                    tel.Port = Port;
                    tel.TerminalType = TerminalType.VT100;
                    tel.RenderProfile = new RenderProfile();
                    tel.Encoding = EncodingType.ISO8859_1;
 
                    CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient();
                    Size sz = this.Size;
 
                    SocketWithTimeout swt;
                    swt = new TelnetConnector((Poderosa.ConnectionParam.TelnetTerminalParam)tel, sz);
                    swt.AsyncConnect(s, tel.Host, tel.Port);
                    ConnectionTag ct = s.Wait(swt);
 
                    this.TerminalPane.FakeVisible = true;
                    this.TerminalPane.Attach(ct);
                    ct.Receiver.Listen();
 
                    if (file != null)
                        this.SetLog((LogType)logType, file, true);
                    this.TerminalPane.ConnectionTag.RenderProfile = new RenderProfile();
                    this.SetPaneColors(Color.White, Color.Black);
 
                }
                else if ((Poderosa.ConnectionParam.ConnectionMethod)this.Method == Poderosa.ConnectionParam.ConnectionMethod.SSH2)
                {
                    //------------------------------------------------------------------------
                    SSHTerminalParam sshp = new SSHTerminalParam((Poderosa.ConnectionParam.ConnectionMethod)this.Method, this.Host, this.UserName, this.Password);
                    sshp.AuthType = this.AuthType;
                    sshp.IdentityFile = this.IdentifyFile;
                    sshp.Encoding = EncodingType.ISO8859_1;
                    sshp.Port = Port;
                    sshp.RenderProfile = new RenderProfile();
                    sshp.TerminalType = TerminalType.XTerm;
 
                    CommunicationUtil.SilentClient s = new CommunicationUtil.SilentClient();
                    Size sz = this.Size;
 
                    SocketWithTimeout swt;
                    swt = new SSHConnector((Poderosa.ConnectionParam.SSHTerminalParam)sshp, sz, sshp.Passphrase, (HostKeyCheckCallback)null);
                    swt.AsyncConnect(s, sshp.Host, sshp.Port);
                    ConnectionTag ct = s.Wait(swt);
 
                    this.TerminalPane.FakeVisible = true;
 
                    this.TerminalPane.Attach(ct);
                    ct.Receiver.Listen();
                    //-------------------------------------------------------------
                    if (file != null)
                        this.SetLog((LogType)logType, file, true);
                    this.TerminalPane.ConnectionTag.RenderProfile = new RenderProfile();
                    this.SetPaneColors(Color.White,Color.Black);
                }
                else if ((Poderosa.ConnectionParam.ConnectionMethod)this.Method == Poderosa.ConnectionParam.ConnectionMethod.Serial)
                {
                    SerialTerminalParam stp = new SerialTerminalParam();
                    stp.BaudRate = BaudRate;
                    stp.FlowControl = FlowControl.None;
                    stp.Parity = Poderosa.ConnectionParam.Parity.NOPARITY;
                    stp.Port = Port;
                    stp.StopBits = Poderosa.ConnectionParam.StopBits.ONESTOPBIT;
                    stp.TerminalType = TerminalType.XTerm;
 
                    IntPtr pt = new IntPtr();
                    SerialTerminalConnection stcon = new SerialTerminalConnection(stp, pt, this.TerminalPane.Width, this.TerminalPane.Height);
                    ConnectionTag ct = new ConnectionTag(stcon);
 
                    this.TerminalPane.FakeVisible = true;
 
                    this.TerminalPane.Attach(ct);
                    ct.Receiver.Listen();
                    //-------------------------------------------------------------
                    if (file != null)
                        this.SetLog((LogType)logType, file, true);
                    this.TerminalPane.ConnectionTag.RenderProfile = new RenderProfile();
                    this.SetPaneColors(Color.White, Color.Black);
                }
                else
                {
                    return;
                }
            }
            catch
            {
                //MessageBox.Show(e.Message, "Connection Error");
                return;
            }
        }







当我尝试打开/连接到串口(COM2)我收到错误连接到COM2时出现以下错误.WaitCommEvent失败6。




When I try to open/connect to the serial port (COM2) I got error "The following error occurred when connecting to COM2. WaitCommEvent failed 6".


这篇关于Poderosa项目 - 终端控制与串行端口连接一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆