Calculate simple ASCII Checksum Mod 256

keithkyll

Member
Join Date
Jul 2005
Location
Heath, TX
Posts
2,033
PLC is Automation Direct P2000. Destination device is a servo drive. Pacific Scientific SC755 with a custom program in BASIC. I have a copy of the BASIC code.

Need to do a checksum of characters. RS232 out only.
CheckSum8 Modulo 256. Sum of Bytes mod 256.
Productivity CPO command only has checksums for CRC and XOR.
Structure for the Rotate command is a single ASCII character for the command, direction bit, 4 digit speed, 8 bit checksum in HEX (00 - FF).

Only need to do this for the Rotate command. Other commands are so simple, I can just send it complete, using an ASCII chart to find HEX value for character. For example, the Enable command is "E", so I send "E45". Home = "H48". Tested with a terminal program - PuTTY.

Commands are always fixed length. For example, rotate clockwise at 10 RPM is "V" for Velocity, "1" is direction, "0010" is speed, and "48" for checksum. Using this online checksum calculator to verify.
Need code to calculate the checksum in HEX. Assume I'll use the CPO instruction to pack and send in one instruction.

Portion of BASIC program used in drive to decode command:
WHILE 1 = 1
IF MSG_COMPLETE = 1 THEN
CHECK_SUM1 = 0
MSG_LEN = LEN(MOTOR_CMD$)
FOR I = 1 TO MSG_LEN-2
CHECK_SUM1 = (CHECK_SUM1 + ASC(MID$(MOTOR_CMD$,I,1))) MOD 256
NEXT
 
May have found part of the solution.
The note in the help file for Copy Character (CPC) says it stores the ASCII value of the string character. I'll use an ASCII field for RPM on the HMI.
Add up the values in array, then figure out how to convert the HEX value to a string.
Stay tuned ...
 
Last edited:
I know nothing about the hardware you are using but it does not sound too complicated.

The code snippet should calculate the checksum. If the strings are short you should only need to mod it after adding the ascii codes up.

To hex the checksum just use
chr$((checksum div 16)+48) and chr$((checksum mod 16)+48) for the two characters
 

Similar Topics

Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
741
Good morning, I have a question. I don't know much about ST yet I would like to calculate the average number of products per hour. how do I do...
Replies
22
Views
2,871
Can someone help me with this? I'm no good at SCL - virtually everything I've done so far has been ladder logic. The return value from the...
Replies
13
Views
1,020
I want to calculate the energy consumed from instantaneous power. Can this be done using the TOT block with timebase set to Hour?
Replies
2
Views
655
Hi everyone, I have to calculate the length in millimeters of a glass that enters a transport (I don't know the speed yet) through a barrier...
Replies
15
Views
3,436
Back
Top Bottom