Home > Net >  C # serial port receiving problem
C # serial port receiving problem

Time:10-06

According to the serial port of writing is a virtual serial port com1 why cannot receive.
Click on the button
Sting st1=text1. Text;
Serialport1. Write (st1);
The timer event is set to true
String st2=serialport. Readexising ();
Text2. Text=st2:

CodePudding user response:

The forehead, virtual serial port is virtual, his a pair, you can't split open,

, that is, if you are virtual "com1" and "com2" a pair of

So that com1 of com2, com1 you want to connect with the serial port tool in com2

Ps: download the serial debugging tools, use a serial port debug tool on the other side (com2, for example, if you the com1 or com2 a pair of virtual configuration), see in the serial debugging tools

CodePudding user response:

Baud rate is in line with the inspection car when your COM access equipment,

CodePudding user response:

A serial port receive events wrote
Private void sp_DataReceived (object sender, SerialDataReceivedEventArgs e)
{
}

CodePudding user response:

You have to debug tool to open another virtual serial port, to send the data, and use the ASC code to send, simply write, send and receive will be garbled,
 
Private void button1_Click (object sender, EventArgs e)
{
String strName;
If (for the Text=="play")
{
StrName=cboCmd. Text. The Trim ();
Sp=new SerialPort (strName);
Sp. The Open ();
Timer1. Start ();
For the Text="close";
}
The else
{
If (sp) IsOpen) sp. The Close ();
Timer1. Stop ();
For the Text="open";
}
}

Private void timer1_Tick (object sender, EventArgs e)
{
String strRead="";
StrRead=sp. ReadExisting ();
RichTextBox1. AppendText (strRead);
}

Private void Form1_FormClosing (object sender, FormClosingEventArgs e)
{
If (sp) IsOpen) sp. The Close ();
Timer1. Stop ();
}

Private void button2_Click (object sender, EventArgs e)
{
Strings str1=textBox1. Text. The Trim ();
Sp. Write (str1);
}

CodePudding user response:

reference 1st floor wanghui0380 response:
well, virtual serial port is virtual, his a pair, you can't split open,

, that is, if you are virtual "com1" and "com2" a pair of

So that com1 of com2, com1 you want to connect with the serial port tool in com2

Ps: download the serial debugging tools, use a serial port debug tool on the other side (com2, for example, if you the com1 or com2 a pair of virtual configuration), in a serial port debug tool to see

How to can't preach photos, can add WeChat br20100311 have reward

CodePudding user response:

Virtual serial port is gay in pairs, regardless of the male parent,
Physical serial port are pairs of mate, male female,

CodePudding user response:

refer to 6th floor angel6709 response:
virtual serial port is gay in pairs, regardless of the male parent,
Physical serial port are pairs of mate, the male parent,

Can you add a WeChat learn can't,

CodePudding user response:

refer to 6th floor angel6709 response:
virtual serial port is gay in pairs, regardless of the male parent,
Physical serial port are pairs of mate, the male parent,

That I change how to write with a virtual serial port
  •  Tags:  
  • C#
  • Related