久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 7563|回復: 8
收起左側

Modbus_RTU_VB源碼

[復制鏈接]
ID:424917 發表于 2018-11-12 11:29 | 顯示全部樓層 |閱讀模式
Modbus_RTU_VB源碼
0.png

參數值:
0.png

進程說明:
/******20061026
實現故障監控,errorflag=1_故障
/******20061026


/******20061102
完成提示,優化界面
/******20061102

/******20061111-12
優化串行發送接收
/******20061111-12

/******20061114
優化串行發送接收,字符間隔精確,T1.5=4ms
/******20061114

/******20061114
監視兩臺,監視地址固定。讀參數地址可變
/******20061114


/******20061114
監視兩臺,監視地址固定。讀參數地址可變
/******20061114


/******20061117
發現功能碼03、06返回參數處理出錯
例如:收回十六進制0708處理成十進制為120
十六進制0708 →→78→→十進制120
修正后:
十六進制0708 →→708→→十進制1800
/******200611117

vb源程序如下:
  1. Private Function Hexsent(ByVal smf_code As String, ByVal sdata_saddr As String, ByVal sdata_num As String, ByVal intGetDataLen As Integer, ByVal intdisnum As Integer, ByVal Hexsent_String As String) As Integer
  2.     Dim hexchrlen%, Hexchr As String, hexcyc%, hexmid As Byte
  3.     Dim hexchrgroup() As Byte, hexchrgrouprgt() As Byte
  4.     Dim j%
  5.     Dim dfMinus, dfFreq, dfTim As Double
  6.    
  7.     Dim msn1, msn2 As String
  8. '接收的數據
  9.     Dim bytReceiveArray() As Byte
  10.    
  11. '接收的變體數據
  12.     Dim VarReceiveData As String
  13.     Dim b As Variant
  14.     Dim i As Long, ii As Long, num_flag0&, num_flag1&, m As Long
  15.     On Error Resume Next
  16.    
  17.    
  18.     hexchrlen = Len(Hexsent_String)
  19.    
  20. '檢查參數值是否合適
  21.     For hexcyc = 1 To hexchrlen
  22.         Hexchr = Mid(Hexsent_String, hexcyc, 1)
  23.         If InStr("0123456789ABCDEFabcdef", Hexchr) = 0 Then
  24.             MsgBox "無效的數值,請重新輸入", , "錯誤信息"
  25.             Exit Function
  26.         End If
  27.     Next
  28.    
  29. '將參數值分成兩個、兩個
  30.     ReDim hexchrgroup(1 To hexchrlen \ 2) As Byte
  31.     For hexcyc = 1 To hexchrlen Step 2
  32.         i = i + 1
  33.         Hexchr = Mid(Hexsent_String, hexcyc, 2)
  34.         hexmid = Val("&H" & CStr(Hexchr))
  35.         hexchrgroup(i) = hexmid
  36.     Next
  37.                
  38. ''主站開始的空閑時間T3.5''主站開始的空閑時間T3.5''主站開始的空閑時間T3.5'主站開始的空閑時間T3.5
  39.     If FstHexSent = 1 Then
  40.         FstHexSent = 0
  41.         Call timedelays(T3_5)
  42.         idle = 1
  43.     ElseIf idle = 0 Then
  44.     Do
  45.     If GetQueueStatus(QS_ALLINPUT) Then DoEvents     '如果正在發送或接收數據則等待到發送或接收完成
  46.     Loop Until idle = 1
  47.     End If

  48. '查詢一個從機
  49.      If Mid(Hexsent_String, 1, 2) > 0 And idle = 1 Then
  50.         idle = 0
  51.         retry_num = 3
  52.         replytimeoutflag = 0
  53.         MSComm1.InBufferCount = 0
  54.         hexchrgrouprgt = hexchrgroup
  55.         MSComm1.Output = hexchrgrouprgt
  56.    
  57.         
  58. '是否發送完畢
  59.         Do Until MSComm1.OutBufferCount = 0
  60.             If GetQueueStatus(QS_ALLINPUT) Then DoEvents
  61.         Loop
  62.         Call timedelays(T3_5)
  63.         QueryPerformanceCounter overreptim
  64.         idle = 1
  65. Wait_reply:
  66.         Do
  67.             If MSComm1.InBufferCount And idle = 1 Then
  68.                 idle = 0
  69.                 VarReceiveData = MSComm1.Input
  70.                 bytReceiveArray = VarReceiveData
  71.                 If Mid(Hexsent_String, 1, 2) = Tran(Hex(Val(bytReceiveArray(0))), 16) Then            '地址校驗
  72.                     Unexpection_sl = 0
  73.                     GoTo Datareceive
  74.                 Else
  75.                     idle = 1
  76.                     Unexpection_sl = 1
  77.                     GoTo Wait_reply
  78.                 End If
  79.             Else
  80.                 QueryPerformanceFrequency f
  81.                 QueryPerformanceCounter l
  82.                 dfTim = (l.lowpart - overreptim.lowpart) / f.lowpart
  83.             End If
  84.         Loop Until dfTim > 2
  85.         
  86.         replytimeoutflag = 1
  87.         GoTo processing_error
  88.         
  89. Datareceive:
  90.         VarReceiveData = VarReceiveData & MSComm1.Input
  91.         QueryPerformanceCounter k
  92.         Do
  93.             If MSComm1.InBufferCount Then
  94.                 GoTo Datareceive
  95.             Else
  96.                 QueryPerformanceCounter l
  97.                 dfTim = (l.lowpart - k.lowpart) / f.lowpart
  98.             End If
  99.         Loop Until dfTim > 0.001 '判斷T1.5超時
  100.         '幀控制(CRC校驗)
  101.         bytReceiveArray = VarReceiveData
  102.         msn = bytReceiveArray
  103.       
  104.         i = LenB(msn)
  105.         ii = i
  106.         msn = ""
  107.         Text6text = ""
  108.         For j = 0 To i - 1
  109.             m = Tran(Hex(Val(bytReceiveArray(j))), 16)
  110.             If m <= 16 Then
  111.                Text6text = Text6text & "0" & Hex(Val(bytReceiveArray(j))) & " "
  112.                msn = msn & "0" & Hex(Val(bytReceiveArray(j)))
  113.             Else
  114.                Text6text = Text6text & Hex(Val(bytReceiveArray(j))) & " "
  115.                msn = msn & Hex(Val(bytReceiveArray(j)))
  116.         
  117.             End If
  118.         Next j
  119.         msn1 = Right$(msn, 4)
  120.         msn2 = Mid(msn, 1, (i - 2) * 2)
  121.         msn2 = RTUcheckString(msn2)
  122.         msn2 = Mid(msn2, (i - 1) * 2 - 1, 4)
  123.         i = StrComp(msn1, msn2, 1)
  124.         If i = 0 Then
  125.             Frameok_flag = 1
  126.         Else
  127.             Frameok_flag = 0
  128.             GoTo processing_error
  129.         End If
  130.         
  131.         'T3.5超時判斷
  132.         Do
  133.             QueryPerformanceCounter l
  134.             dfTim = (l.lowpart - k.lowpart) / f.lowpart
  135.         Loop Until dfTim > T3_5
  136.         
  137.         If Frameok_flag = 0 Then
  138.             GoTo processing_error
  139.         Else
  140.             GoTo process_reply
  141.         End If
  142. processing_error: ''''''''''''''''''''''''''''''''''處理到這里了|||||||||||||||||||||||||||||||||
  143.                      If RESTART = 1 Then
  144.                         '7'If replytimeoutflag = 1 Then
  145.                         '7'   Hexsent = 1
  146.                         '7'   replytimeoutflag = 0
  147.                         '7'   idle = 1
  148.                         '7'   ERR = ERR + 1
  149.                         '7'Else
  150.                            Hexsent = 0
  151.                            RESTART = 0
  152.                         '7'End If
  153.                      
  154.                      ElseIf replytimeoutflag = 1 Then
  155.                         Hexsent = 1
  156.                         replytimeoutflag = 0
  157.                         idle = 1
  158.                         ERR = ERR + 1
  159.                      ElseIf Frameok_flag = 0 Then
  160.                         Hexsent = 2
  161.                         idle = 1
  162.                         ERR = ERR + 1
  163.                      End If
  164.                      Exit Function
  165.                      
  166.                 ''''''2'''     retry_num = retry_num - 1
  167.                 ''''''2'''     If retry_num >= 0 Then
  168.                 ''''''2'''        GoTo retry
  169.                 ''''''2'''     Else
  170.                 ''''''2'''        idle = 1
  171.                 ''''''2'''        Exit Function
  172.                 ''''''2'''     End If
復制代碼

所有資料51hei提供下載:
Modbus_RTU_VB源碼 _Modbus_RTU_VB源碼.rar (4.27 MB, 下載次數: 163)
回復

使用道具 舉報

ID:224365 發表于 2019-1-15 16:36 | 顯示全部樓層
需要這個資料看一看
回復

使用道具 舉報

ID:82988 發表于 2019-1-16 22:35 | 顯示全部樓層
謝謝樓主分享
回復

使用道具 舉報

ID:89841 發表于 2019-6-24 09:06 | 顯示全部樓層

謝謝樓主分享
回復

使用道具 舉報

ID:57896 發表于 2019-6-27 22:31 | 顯示全部樓層
樓主你好!我用VB6.0打開提示“未注冊”,怎么回事?
回復

使用道具 舉報

ID:89841 發表于 2019-9-30 10:17 | 顯示全部樓層
謝謝學習學習
回復

使用道具 舉報

ID:522147 發表于 2019-11-7 15:51 | 顯示全部樓層
謝謝學習學習,共同進步
回復

使用道具 舉報

ID:522147 發表于 2020-4-10 15:40 | 顯示全部樓層
學習學習,共同進步
回復

使用道具 舉報

ID:774313 發表于 2020-6-9 19:33 | 顯示全部樓層
需要這個資料
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美视频在线观看 | 国产免费观看久久黄av片涩av | 91极品视频 | 亚洲成人av | 欧美一区二区三区在线 | 精品亚洲二区 | 365夜爽爽欧美性午夜免费视频 | 伊人艹| 性高湖久久久久久久久aaaaa | 免费成年网站 | 伊人久久大香线 | 69热视频在线观看 | 亚洲aⅴ | 午夜免费精品视频 | 99国产精品视频免费观看一公开 | 国产精品国产精品国产专区不片 | 亚洲区一区二 | 99国产精品久久久久老师 | 一区二区国产精品 | 久久精品久久精品久久精品 | 欧美福利| 国产高清视频 | 99久久精品国产一区二区三区 | 中文字幕欧美在线观看 | 四虎影视免费在线 | 伊人网在线播放 | 日本一区二区不卡 | 中文字幕日韩在线观看 | 中文字幕av在线播放 | 亚洲一区在线播放 | 在线看av的网址 | 一区二区日本 | 国产欧美日韩一区二区三区 | 日韩成人久久 | www.中文字幕.com | 人人鲁人人莫人人爱精品 | 欧美视频在线播放 | 亚洲国产精品suv | 精品久久99| 狠狠的日| 91高清视频在线观看 |