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幣 [記錄]
[ 購買]
- /*
- //讀取串口中一個字節(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;
- }
- )
- );
- break;
- default:
- ReceiveData[ReceiveDataIndex] = ch;
- ReceiveDataIndex++;
- if (ReceiveDataIndex > ReceiveData.Length)
- {
- ReceiveDataIndex = ReceiveData.Length - 1;
- }
- break;
- }
復(fù)制代碼
【必讀】版權(quán)免責(zé)聲明
1、本主題所有言論和內(nèi)容純屬會員個人意見,與本論壇立場無關(guān)。2、本站對所發(fā)內(nèi)容真實性、客觀性、可用性不做任何保證也不負任何責(zé)任,網(wǎng)友之間僅出于學(xué)習(xí)目的進行交流。3、對提供的數(shù)字內(nèi)容不擁有任何權(quán)利,其版權(quán)歸原著者擁有。請勿將該數(shù)字內(nèi)容進行商業(yè)交易、轉(zhuǎn)載等行為,該內(nèi)容只為學(xué)習(xí)所提供,使用后發(fā)生的一切問題與本站無關(guān)。 4、本網(wǎng)站不保證本站提供的下載資源的準確性、安全性和完整性;同時本網(wǎng)站也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的損失或傷害。 5、本網(wǎng)站所有軟件和資料均為網(wǎng)友推薦收集整理而來,僅供學(xué)習(xí)用途使用,請務(wù)必下載后兩小時內(nèi)刪除,禁止商用。6、如有侵犯你版權(quán)的,請及時聯(lián)系我們(電子郵箱1370723259@qq.com)指出,本站將立即改正。
|