国产免费AV|泡泡玛特欧洲总部将设在伦敦|中文天堂网www新版资源在线|一本久道综合在线中文|国精产品一二三产区的使用方法|香蕉鱼在线观看|www.27eee
ELEOK
標題:
modbus rtu串口上位機調試程序C#源碼
[打印本頁]
作者:
山海致遠
時間:
2020-5-2 02:01
標題:
modbus rtu串口上位機調試程序C#源碼
1.png
(26.98 KB)
下載附件
2020-5-2 01:59 上傳
modbus 串口C#源碼.rar
(79.71 KB, 售價: 3 E幣)
2020-5-2 02:00 上傳
點擊文件名下載附件
售價: 3 E幣
[記錄]
[
購買
]
/*
//讀取串口中一個字節的數據
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;
}
復制代碼
歡迎光臨 ELEOK (http://www.afoofa.cn/)
Powered by Discuz! X5.0