BobT (Customer) asked a question.

I'm using a Productivity1000 that communicates to a serial device and requires Checksum8 Modulo 256

It adds up all the alphanumeric characters in hex and uses the last 2 hex as the checksum. The PLC does not support this. Is there a PLC that does or is there a software workaround.

The data 1st 2 digits are address, then the data up to 16 characters, then the checksum.

Any suggestions?


  • ADC Community_02 (Automationdirect.com)

    Have you looked at the Custom Protocol Out (CPO) in Productivity Suite and if you know the checksum algorithm you should be able to generate the checksum. Another option is you could also do this in the Do-More plc and take a look at the CHECKSUM instruction (reference help topic DMD0305).

  • WireBiter665 (Customer)

    You could look into the "Copy Character (CPC)" Instruction. This will copy a string of characters into an array of integers and if you use Unsigned 8 bit for your copy to array, each character will get put into an array element. Then you can use an Array Statistics (STA) Instruction to sum the elements in the array. Then convert the result into a Hex value.

  • WireBiter665 (Customer)

    I didn't have time to finish explaining the process yesterday. If you set the output of your STA instruction as an Unsigned 16 bit integer, then use Unpack Word (UPKW) and unpack that 16 bit into 2 8 bit Unsigned integers, you'll have your 2 hex values for your Checksum. Just make sure you use the right one as your upper and lower characters (Position 1 and Position 2).

  • BobT (Customer)

    Thank you. I will definitely try this. It seems a much simpler solution than I came up with.

  • dank (Customer)

    I'm working on a similar application using the modulo 256 checksum, but I need to append the string representation of the Hex checksum to all ASCII out commands. From the previous reply, how can I convert the hex byte 6A to string 6A?

     

    EDIT:

    I'm not sure if there is an instruction that does this, but I ended up just doing a manual conversion from decimal to hex by dividing the checksum integer by 16 twice, shifting the remainder to make the decimal to ASCII conversion, then inserting that into a byte array before doing a copy character into the string.

    Expand Post
    • kewakl (Customer)

      Do you need to put the strings "6" and "A" on the wire, or the BYTE value 0x6A (106d) on the wire?

      • dank (Customer)

        The strings "6" and "A"

      • kewakl (Customer)

         

        I would think that a lookup table might be required.

        Others may have better ideas.

      • kewakl (Customer)

        Building on @WireBiter's example, I scratched a lookup table and got your "6" AND "A" strings. see attached project. I added a bit of rung commenting to describe the intent.

        I checked a couple input strings against lammertbies' webcalculator to verify the checksum results.

        I used PAC Suite 3.12.1.21