Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET Networking
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);
 
 
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...
Posted 11-Oct-10 3:54am
arik921119
Edited 11-Oct-10 4:56am
v2
Comments
Richard MacCutchan at 11-Oct-10 9:58am
   
The line with your error message is not present in your code snippet; did you post the correct portion of your program?
 
Also, what example are you referring to?
cholegm at 15-May-12 3:54am
   
Does any know why I got error "The following error occurred when connecting to COM2. WaitCommEvent failed 6" when I try to open/connect to the serial port (COM2)?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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;
            }
        }
 

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".
  Permalink  
Comments
cholegm at 15-May-12 3:53am
   
Does any know why I got error "The following error occurred when connecting to COM2. WaitCommEvent failed 6" when I try to open/connect to the serial port (COM2)?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 341
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 220
3 Praneet Nadkar 197
4 Shweta N Mishra 161
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 26 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100