|
modbus上位機(jī)運(yùn)行界面:
0.png (26.08 KB, 下載次數(shù): 115)
下載附件
2018-4-16 17:02 上傳
Test_SerialPort的c#源程序如下:
- /*
- //讀取串口中一個(gè)字節(jié)的數(shù)據(jù)
- String ch = mySerialPort.ReadExisting();
- switch (ch)
- {
- case "$":
- //接收到串口頭
- ReceiveData = "";
- break;
- case "\n":
- //接收到串口尾
- //在擁有此控件的基礎(chǔ)窗口句柄的線程上執(zhí)行委托Invoke(Delegate)
- //即在控件textBoxInformation的父窗口form中執(zhí)行委托.
- 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:
- //接收到串口頭,清空數(shù)組
- 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();
- }
- //在擁有此控件的基礎(chǔ)窗口句柄的線程上執(zhí)行委托Invoke(Delegate)
- //即在控件textBoxInformation的父窗口form中執(zhí)行委托.
- textBoxInformation.Invoke
- (
- new MethodInvoker
- (
- delegate
- {
- //textBoxInformation.AppendText(ReceiveData);
- textBoxReceiveData.Text = str;
- }
- )
- );
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
0.jpg (30.07 KB, 下載次數(shù): 111)
下載附件
2018-4-16 17:03 上傳
所有資料51hei提供下載:
串口Mudbud.rar
(79.71 KB, 下載次數(shù): 273)
2018-4-16 10:28 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|