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 wrotePrivate 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: