Results 1 to 3 of 3

Thread: VB6 CRC calculation wrong output

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2012
    Posts
    8

    VB6 CRC calculation wrong output

    I am trying to figure out a CRC check for a serial controlled device. I have an example, when i send this example to the device, it responds correctly.

    This is the complete serial string wich the device responds to:

    Code:
    \x00\x17\x3d\x30\x32\x32\x30\x39\x39\x30\x30\x30\x30\x30\x30\x30\x30\x30\x37\x34\x30\x30\x30\x30\x30\x01\x28
    (The last 2 bytes (\x01\x28) are the CRC outcomes).

    Code:
    This is my code:
    
    Dim Send As String
    Dim CRC1 As String
    Dim CRC2 As String
    Dim TEMP As String
    
    Private Sub Command1_Click()
    
    Send = &H0 & &H17 & "=" & "022" & "099" & "00" & "00" & "0000074" & "00000"
    
    CRC1 = &H0
    CRC2 = &H0
    TEMP = &H0
    
    For i = 1 To Len(Send)
        TEMP = CRC1
        CRC1 = CRC2 Xor Asc(Mid$(Send, i, 1))
        CRC2 = TEMP
    
    Next i
    
    Text1.Text = "CRC1= " & CRC1 & " / CRC2= " & CRC2
    
    End Sub
    The output should be: CRC1 = 1 (decimal) and CRC2 = 40 (decimal) But i am getting 51/60.

    I think is has somnething to do with datatypes.

    This is the original CRC formule from the device:

    Code:
    Set <CRC1> and <CRC2> to zero.
    For every <CHAR> in <MSG> do
    <TEMP> = <CRC1>
    <CRC1> = <CRC2> XOR <CHAR>
    <CRC2> = <TEMP>
    Thanks in advance!

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2012
    Posts
    8

    Re: VB6 CRC calculation wrong output

    Quote Originally Posted by wqweto View Post
    Try using Chr$ like this

    Send = Chr$(&H0) & Chr$(&H17) & "=" & . . .

    cheers,
    </wqw>


    Yes, it works! Many thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width