标题:
modbus上位机 Test_SerialPort c#源码
[打印本页]
作者:
木木棉百合
时间:
2018-4-16 10:28
标题:
modbus上位机 Test_SerialPort c#源码
modbus上位机运行界面:
0.png
(26.08 KB, 下载次数: 115)
下载附件
2018-4-16 17:02 上传
Test_SerialPort的c#源程序如下:
/*
//读取串口中一个字节的数据
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;
}
)
);
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
0.jpg
(30.07 KB, 下载次数: 111)
下载附件
2018-4-16 17:03 上传
所有资料51hei提供下载:
串口Mudbud.rar
(79.71 KB, 下载次数: 273)
2018-4-16 10:28 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
875113301
时间:
2018-10-11 13:23
感谢大佬
作者:
smilexxy
时间:
2018-11-21 14:13
感谢大佬分享
作者:
597543289
时间:
2019-1-19 15:59
挺好的一个学习的例子,可以修改成自己的项目程序
作者:
51cc
时间:
2019-2-14 17:05
正好参考。。
作者:
xtuwz
时间:
2019-3-7 17:26
急需要,怎么获取
作者:
ly81222
时间:
2019-3-13 07:45
急需要,怎么获取
作者:
Alan_zcb
时间:
2019-3-27 11:04
感谢大佬,学习了。
作者:
Garfieldsss
时间:
2019-4-9 21:48
感谢大佬
作者:
hxa4056
时间:
2019-9-27 08:46
感谢大佬
作者:
神蜂
时间:
2020-3-29 16:20
感谢大佬,下载学习
作者:
xintiandi
时间:
2020-5-11 22:05
支持一下。。。
作者:
nymz
时间:
2020-6-6 22:27
感谢大佬分享
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1