Home AMX User Forum NetLinx Studio
Options

Checksum Assistance

I'm trying to calculate a checksum, but I cannot figure out how to do it for this device. I've tried all the sample code I can find here on the forums, but none have worked for me.

The device is a Grid Connect BF-2300
In this appendix the DIO command protocol is described here to let customer’s remote
management software to access Digital I/O state through Ethernet network by a specific TCP/UDP
port(default is 50000) ,RS232 and RS485.

Command Packet Format:
Length(Bytes): Start Flag - 2, Command - 2, Data 1 - 32, Data 2 - 32, End Flag - 2, CRC - 1

Start Flag: 0xF0F0
End Flag: 0xF0F0
Command Status:the definition of command code is as following
0x0002 – ACK of Read Digital I/O state
0x0004 – ACK of Trigger Digital I/O
0x0006 – ACK of E-mail Alarm Trigger
0x0010 – Report current Digital I/O state (If Auto Report I/O Status is enabled, you will receive this
report packet from BF-2300)
0xFFFC – Flag error, incorrect Start Flag or End Flag received in command packet
0xFFFD – Length error, the length of command packet is invalid
0xFFFE – CRC error, incorrect CRC value
0xFFFF – Command error, no such command
CRC value = 0 – total sum from field of ‘Start Flag” to “End Flag”

Here are some working examples, I just don't know how to add everything together to get that checksum.
Example 1
$F0,$F0,$00,$10,$00,$01,$00,$00,$01,$01,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$F0,$F0,$21

Example 2
$F0,$F0,$00,$10,$00,$00,$01,$00,$01,$01,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$F0,$F0,$21

Example 3
$F0,$F0,$00,$10,$01,$00,$01,$00,$01,$01,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$F0,$F0,$20

Thanks

Comments

  • Options
    Jorde_VJorde_V Posts: 393
    jabramson wrote: »
    I'm trying to calculate a checksum, but I cannot figure out how to do it for this device. I've tried all the sample code I can find here on the forums, but none have worked for me.

    The device is a Grid Connect BF-2300
    In this appendix the DIO command protocol is described here to let customer’s remote
    management software to access Digital I/O state through Ethernet network by a specific TCP/UDP
    port(default is 50000) ,RS232 and RS485.
    
    Command Packet Format:
    Length(Bytes): Start Flag - 2, Command - 2, Data 1 - 32, Data 2 - 32, End Flag - 2, CRC - 1
    
    Start Flag: 0xF0F0
    End Flag: 0xF0F0
    Command Status:the definition of command code is as following
    0x0002 – ACK of Read Digital I/O state
    0x0004 – ACK of Trigger Digital I/O
    0x0006 – ACK of E-mail Alarm Trigger
    0x0010 – Report current Digital I/O state (If Auto Report I/O Status is enabled, you will receive this
    report packet from BF-2300)
    0xFFFC – Flag error, incorrect Start Flag or End Flag received in command packet
    0xFFFD – Length error, the length of command packet is invalid
    0xFFFE – CRC error, incorrect CRC value
    0xFFFF – Command error, no such command
    CRC value = 0 – total sum from field of ‘Start Flag” to “End Flag”
    

    Here are some working examples, I just don't know how to add everything together to get that checksum.
    Example 1
    $F0,$F0,$00,$10,$00,$01,$00,$00,$01,$01,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$F0,$F0,$21
    
    Example 2
    $F0,$F0,$00,$10,$00,$00,$01,$00,$01,$01,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$F0,$F0,$21
    
    Example 3
    $F0,$F0,$00,$10,$01,$00,$01,$00,$01,$01,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$01,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$F0,$F0,$20
    

    Thanks

    Only Example 3 seems right the other 2 have the checksum (1F) and add 2 for some reason

    Example 3, remove all the F0 (start + end bytes), remove the checksum 20, remove the 00, you'll be left with 16x01 and 1x10 if you calculate this (base 16) you will end up with 20. Your calculator probably has a base16 option or a 'programmer' option

    By the way the easy way to do this is take TextEdit (notepad) (I have a mac), find and replace.. find $F0 replace with nothing (but hit replace), find $00 and replace with nothing, find ',' replace with nothing, find $ replace with + and manually remove the checksum (or find and replace) and remove the front +. There you will have your sum, easy way is to count the amount of 01 and add those together in base 10 and then convert that to base 16. then you can add the big numbers together (16x01 = 10 in base 16) 10 + 10 in base 16 = 20 in base 16. (32 in base 10)
  • Options
    jabramson wrote: »
    CRC value = 0 – total sum from field of ‘Start Flag” to “End Flag”

    If you're going to do this by hand, I really enjoy SpeQ Mathematics. It's a great "programmable" calculator.

    However, if you want to calculate this checksum in NetLinx, give this function a try (this code has NOT been tested):
    DEFINE_FUNCTION CreateChecksum(CHAR sArray[71])
    {
       STACK_VAR INTEGER nByte;
       STACK_VAR INTEGER nChecksum;
    
       nChecksum = 0;
    
       FOR (nByte = 70; nByte; nByte--)
       {
          nChecksum = nChecksum + sArray[nByte];
       }
    
       sArray[71] = TYPE_CAST((0 - nChecksum) & $FF);
    }
    
  • Options
    jabramsonjabramson Posts: 106
    I used the example 3 as a test and still couldn't get the right result.

    The SpeQ calculator gives me 31
    The example you provided gives me 31

    I need to get to $20..= 32

    Scratch that, something wasn't right, getting 32 now....Thanks.
Sign In or Register to comment.