标题:
C#串口MudbudRTU协议编程
[打印本页]
作者:
Liruonn
时间:
2018-7-24 19:50
标题:
C#串口MudbudRTU协议编程
Modbus串口通信协议
0.png
(43.21 KB, 下载次数: 104)
下载附件
2018-7-24 23:38 上传
全部资料51hei下载地址:
C#串口MudbudRTU协议编程.zip
(260.39 KB, 下载次数: 131)
2018-7-24 19:50 上传
点击文件名下载附件
下载积分: 黑币 -5
部分源码预览:
/*
//读取串口中一个字节的数据
String ch = mySerialPort.ReadExisting();
switch (ch)
{
case "$":
//接收到串口头
ReceiveData = "";
break;
case "\n":
//接收到串口尾
//在拥有此控件的基础窗口句柄的线程上执行委托Invoke(Delegate)
//即在控件textBoxInformation的父窗口form中执行委托.
textBoxInformation.Invoke
(
new MethodInvoker
(
delegate
{
//textBoxInformation.AppendText(ReceiveData);
textBoxReceiveData.Text = ReceiveData;
}
)
);
break;
default:
ReceiveData += ch;
break;
}
int ch = mySerialPort.ReadByte();
string str = string.Empty;
switch (ch)
{
case 0x12:
//接收到串口头,清空数组
Array.Clear(ReceiveData, 0, ReceiveData.Length);
ReceiveDataIndex = 0;
break;
case 0x14:
//接收到串口尾,输出string
for (int i = 0; i < ReceiveData.Length; i++)
{
str += (ReceiveData[i] - '0').ToString();
}
//在拥有此控件的基础窗口句柄的线程上执行委托Invoke(Delegate)
//即在控件textBoxInformation的父窗口form中执行委托.
textBoxInformation.Invoke
(
new MethodInvoker
(
delegate
{
//textBoxInformation.AppendText(ReceiveData);
textBoxReceiveData.Text = str;
}
)
);
break;
default:
ReceiveData[ReceiveDataIndex] = ch;
ReceiveDataIndex++;
if (ReceiveDataIndex > ReceiveData.Length)
{
ReceiveDataIndex = ReceiveData.Length - 1;
}
break;
}
复制代码
作者:
a425623964
时间:
2020-5-16 00:15
多谢分享,谢谢!
作者:
JACKDENG288
时间:
2020-5-26 19:42
很好,多谢
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1