vb.net串口通信(求解决,代码执行到向串口发送数据,后没有返回数据信息)
privatevoidbutton1_Click(objectsender,EventArgse)//发送button{dataout=textBox1.Text;//获...
private void button1_Click(object sender, EventArgs e)//发送button
{
dataout = textBox1.Text;//获取textbox1文本框输入的数据
System.Console.WriteLine("=="+dataout+"==");
serialPort1.Write(dataout);//将获取数据写入串口serialport
System.Console.WriteLine("--"+serialPort1.ReadExisting()+"--");
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(SP__Receiving));
}
private void SP__Receiving(object serder, EventArgs e)//接收数据
{
datain =serialPort1.ReadExisting();//获取serialport1中所有可用的字节
//serialPort1.DiscardInBuffer();
textBox2.Text = datain;
} 展开
{
dataout = textBox1.Text;//获取textbox1文本框输入的数据
System.Console.WriteLine("=="+dataout+"==");
serialPort1.Write(dataout);//将获取数据写入串口serialport
System.Console.WriteLine("--"+serialPort1.ReadExisting()+"--");
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(SP__Receiving));
}
private void SP__Receiving(object serder, EventArgs e)//接收数据
{
datain =serialPort1.ReadExisting();//获取serialport1中所有可用的字节
//serialPort1.DiscardInBuffer();
textBox2.Text = datain;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询