⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 Modbus RTU CRC Check
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   2205
      Left            =   885
      TabIndex        =   0
      Top             =   810
      Width           =   2265
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit


Private Sub Form_Load()

    Dim oldtime As Long
    Dim newtime As Long
    Dim kkk As Integer
    Dim i As Integer
    Dim j As Integer
    Dim SendVarr(10) As Integer
'    Dim SendVarr1(10) As Byte
    
    Dim RecVarr(100) As Byte
    Dim Rec As Long
    
    Dim StartAddr As Long
    Dim aa As Long
    Dim bb As Long
    Dim mAddress As Byte
    
    
    Dim CRCHi As Long
    Dim CRCLo As Long
    
    
    
    Dim ReHi As Long
    Dim ReLo As Long
    
    Dim Is110 As Single
    
    Dim CrcLow As Integer
    Dim CrcHig As Integer

    
    StartAddr = &H1
    mAddress = &H2
    
    SendVarr(0) = mAddress And &HFF '地址  &H01
    SendVarr(1) = &H3  '功能码 &H03
    
    SendVarr(2) = StartAddr And &HFF             '起始地址的低位
    SendVarr(3) = Fix(StartAddr / CLng((2 ^ 8))) And &HFF '起始地址的高位
    
   
    
    SendVarr(4) = &H0                   '读取字的个数低字节 &H0032
    SendVarr(5) = &H2                   '读取字的个数高字节 &H0032
    SendVarr(6) = &H2                   '读取字的个数
    
    '---CRC---CHECK <ModBus>
    
    CRCHi = 0
    CRCLo = 0

    aa = &HFF * CLng((2 ^ 8)) + &HFF

    For i = 0 To 6

        CRCHi = Fix(aa / CLng((2 ^ 8))) And &HFF
        CRCLo = Fix(aa) And &HFF


        aa = CLng((CRCHi * CLng(2 ^ 8)) And &HFF00) + CLng((CRCLo Xor SendVarr(i)) And &HFF)

        For j = 0 To 7
            bb = aa And &H1
            aa = Fix(aa / 2)
            If bb = 1 Then
                aa = aa Xor (&HA0 * CLng((2 ^ 8)) + &H1)
            End If
        Next j
    Next i

    SendVarr(6) = (aa And &HFF)              'CRC 的低位 133
    SendVarr(7) = Int(aa / &H100) And &HFF   'CRC 的高位 146



   
    
    SendVarr(7) = (aa And &HFF)              'CRC 的低位
    SendVarr(8) = Int(aa / &H100) And &HFF   'CRC 的高位
    
    

    

    
End Sub




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -