欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4854|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

C#串口MudbudRTU協(xié)議編程

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
Modbus串口通信協(xié)議


全部資料51hei下載地址:
C#串口MudbudRTU協(xié)議編程.zip (260.39 KB, 下載次數(shù): 131)


部分源碼預(yù)覽:
  1.   /*
  2.             //讀取串口中一個(gè)字節(jié)的數(shù)據(jù)
  3.             String ch = mySerialPort.ReadExisting();

  4.             switch (ch)
  5.             {
  6.                 case "$":
  7.                     //接收到串口頭
  8.                     ReceiveData = "";
  9.                     break;
  10.                 case "\n":
  11.                     //接收到串口尾

  12.                     //在擁有此控件的基礎(chǔ)窗口句柄的線程上執(zhí)行委托Invoke(Delegate)
  13.                     //即在控件textBoxInformation的父窗口form中執(zhí)行委托.
  14.                     textBoxInformation.Invoke
  15.                     (
  16.                         new MethodInvoker
  17.                         (
  18.                             delegate
  19.                             {
  20.                                 //textBoxInformation.AppendText(ReceiveData);
  21.                                 textBoxReceiveData.Text = ReceiveData;
  22.                             }
  23.                         )
  24.                      );
  25.                     break;
  26.                 default:
  27.                     ReceiveData += ch;
  28.                     break;

  29.              }

  30.             int ch = mySerialPort.ReadByte();
  31.             string str = string.Empty;
  32.             switch (ch)
  33.             {
  34.                 case 0x12:
  35.                     //接收到串口頭,清空數(shù)組
  36.                     Array.Clear(ReceiveData, 0, ReceiveData.Length);
  37.                     ReceiveDataIndex = 0;
  38.                     break;
  39.                 case 0x14:
  40.                     //接收到串口尾,輸出string
  41.                     for (int i = 0; i < ReceiveData.Length; i++)
  42.                     {
  43.                         str += (ReceiveData[i] - '0').ToString();
  44.                     }
  45.                     //在擁有此控件的基礎(chǔ)窗口句柄的線程上執(zhí)行委托Invoke(Delegate)
  46.                     //即在控件textBoxInformation的父窗口form中執(zhí)行委托.
  47.                     textBoxInformation.Invoke
  48.                     (
  49.                         new MethodInvoker
  50.                         (
  51.                             delegate
  52.                             {
  53.                                 //textBoxInformation.AppendText(ReceiveData);
  54.                                 textBoxReceiveData.Text = str;
  55.                             }
  56.                         )
  57.                      );
  58.                     break;
  59.                 default:
  60.                     ReceiveData[ReceiveDataIndex] = ch;
  61.                     ReceiveDataIndex++;
  62.                     if (ReceiveDataIndex > ReceiveData.Length)
  63.                     {
  64.                         ReceiveDataIndex = ReceiveData.Length - 1;
  65.                     }
  66.                     break;
  67.             }
復(fù)制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:165292 發(fā)表于 2020-5-16 00:15 | 只看該作者
多謝分享,謝謝!
回復(fù)

使用道具 舉報(bào)

無(wú)效樓層,該帖已經(jīng)被刪除
地板
ID:404756 發(fā)表于 2020-5-26 19:42 | 只看該作者
很好,多謝
回復(fù)

使用道具 舉報(bào)

5#
無(wú)效樓層,該帖已經(jīng)被刪除

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表