C#串口通讯问题
private void Form1_Load(object sender, EventArgs e)
{
MyPort = new SerialPort();
MyPort.PortName = "COM3";
MyPort.BaudRate = 9600;
MyPort.DataBits = 8;
MyPort.StopBits = System.IO.Ports.StopBits.One;
MyPort.Parity = System.IO.Ports.Parity.None;
}
private void button1_Click(object sender, EventArgs e)
{
if (MyPort.IsOpen != true)
{
MyPort.Open();
}
byte[] _write = new byte[] { 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xa0 };
MyPort.Write(_write, 0, 12);
}
上面是是我写的代码:
下面是串口调试精灵:

不知道为什么我发下去后下位机不能识别,但是用串口调试精灵发送后下位可以识别。
下位机在收到第一个字节后启动了一个timer若100ms没有收到第二个字节讲清空。
麻烦大家给看看
{
MyPort = new SerialPort();
MyPort.PortName = "COM3";
MyPort.BaudRate = 9600;
MyPort.DataBits = 8;
MyPort.StopBits = System.IO.Ports.StopBits.One;
MyPort.Parity = System.IO.Ports.Parity.None;
}
private void button1_Click(object sender, EventArgs e)
{
if (MyPort.IsOpen != true)
{
MyPort.Open();
}
byte[] _write = new byte[] { 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xa0 };
MyPort.Write(_write, 0, 12);
}
上面是是我写的代码:
下面是串口调试精灵:
不知道为什么我发下去后下位机不能识别,但是用串口调试精灵发送后下位可以识别。
下位机在收到第一个字节后启动了一个timer若100ms没有收到第二个字节讲清空。
麻烦大家给看看
...全文
相关推荐
串口通讯模块C# 串口通讯模块C#
串口通讯模块C串口串口通讯模块C#通串口通讯模块C#讯模块C##串口通讯模块C#
C# 串口通讯Demo(VS2010)
一个简单的C# 串口通讯Demo,可收发数据。
C# 欧姆龙PLC HostLink协议 串口通讯实例
本实例利用通过HostLink,实现同欧姆龙PLC的串口通讯,以读取数据存储区D(其他区域可以此为基础修改),另附HostLink通讯协议……在CP1E PLC上测试完全没问题。
C#通过串口与三菱PLC通讯
C#通过串口与三菱PLC通讯源代码,供大家参考学习,互相帮助
c#_多线程串口通讯_快速采集
基于C# 2008的多线程串口通讯程序,实现多台设备的快速快速不间断数据采集


