Checksum in ST

mcbridc

Member
Join Date
Jun 2015
Location
Indiana
Posts
1
Hello,

I am an intern at a company and I am trying to get an AB CompactLogix PLC to control a piece of machinery. I need to send checksum values to the controller of the machine that I am trying to control to get it to accept commands. I have the checksum code in C, but it needs to be in Structured Text. I've been working on this for a few days now and I can't seem to get anything that works. Is there anyone that can help?

The checksum function in C is:

int checksum(char*data){
int cs=0;
while(*data!=null){
cs+=*data;
data++;
}
return 255-(cs%256);
}
 
There is no way to directly translate this to A-B structured text because it uses pointers. To be creative about it you could probably copy your string data into an array of bytes and sum all of the characters in order to eliminate that loop.

If you want to stay true to the code you will have to extract each character from the string and add it to a variable of type BYTE. Then you'd return 255-(cs mod 256). Hope that helps.

Good luck,

Yosi
 
Why not simply:

For i := 0 to (MyString.Len - 1) By 1 Do
cs := cs + MyString.Data
End_For;
Result := 255 - (cs MOD 256);
 

Similar Topics

Hello all, I'm trying to recreate the following checksum calculation in the PLC. The example is written in C++ of which I am not very familiar...
Replies
8
Views
3,062
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...
Replies
2
Views
4,048
I have a PLC connected to a modem. I can tap into the modem via ethernet and read the Modbus messages coming in. So I use Modbus Poll. I'm...
Replies
10
Views
8,195
Does a change in the program always equal a checksum change? For instance, if I change a timer preset from 10 to 15 does the checksum change...
Replies
8
Views
3,511
HI, I have doubt in allen bradely plc , am using udp communication. My aim is to find the checksum of received message. what is my problem is...
Replies
1
Views
1,639
Back
Top Bottom