VB Modbus RTU CRC check

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.