Tag:end modbus mic crc Conversion toolbar function class mod
 PUBLIC FUNCTION CHR_CRC (data () as byte) As String ' Calculation of CRC check for *rtu mode Dim CrcJ As Long dim i as integer dim j as integer CrcJ = 65535 ' *CRCJ Assignment 65535 for i = 0 to ubound (data) '- 2 ' * Number of bytes in the loop to check &nbsP; crcj = crcj xor data (i) ' * Each byte is different from the current value of CRCJ or For j = 0 to 7 ' * Cycle eight times If crcj mod 2 = 1 then ' * If the remainder of CRCJ current value except 2 equals 1 to determine if the lowest bit is 1 crcj = crcj \ 2 ' * CRCJ current value except 2 right Shift CrcJ = CrcJ Xor 40961 ' * CRCJ Current value with 40961 xor Else crcj = CrcJ \ 2 ' * If the CRCJ current value of the lowest bit is not equal to 1 then only move right End If next j next i chr_crc = right ("0000" + hex (CRCJ), 4) ' * Calculated CRCJ current value is converted to hex chr_crc = right (CHR_CRC,  2) + left (chr_crc, 2) ' * Low byte placed in front, high byte in the back End function
VB Modbus RTU CRC check