DL05 and GS4 Modbus ASCII Issue

As you were kind enough to gen a bit of code to check the check sum, can you tell me if your code gens up the same LRC?


Sure, everything after the short fake line (30 30 30 30 0D 0A) below is from that last post, and they all have Okay=True, so your LRCs agree with my algorithm.


Clear sailing!





% python lrc_check.py
{'list_compare': []}
The result is as expected: (((lrcsum & 0xff) ^ 0xff) + 1) & 0xff) is equivalent to ((-lrcsum) & 0xff)
{'URL': 'https://en.wikipedia.org/wiki/Modbus#Modbus_ASCII_frame_format_(primarily_used_on_7-_or_8-bit_asynchronous_serial_lines)', 'raw': ':F7031389000A60\r\n', 'doc_ascii': '\nTX:-3A 46 37 30 33 31 33 38 39 30 30 30 41 36 30 0D 0A'}
{'Okay': True, 'LRC': '01', 'LRCtok': '01', 'lcrsum': 255, 'rawline': '30 31 30 36 32 30 30 31 30 30 44 37 30 31'}
{'Okay': True, 'LRC': '01', 'LRCtok': '01', 'lcrsum': 255, 'rawline': '30 31 30 36 32 30 30 31 30 30 44 37 30 31'}
{'Okay': True, 'LRC': '00', 'LRCtok': '00', 'lcrsum': 256, 'rawline': '30 31 30 36 32 30 30 31 30 30 44 38 30 30'}
{'Okay': True, 'LRC': '00', 'LRCtok': '00', 'lcrsum': 256, 'rawline': '30 31 30 36 32 30 30 31 30 30 44 38 30 30'}
{'Okay': False, 'LRC': 'FF', 'LRCtok': '\x0fF', 'lcrsum': 257, 'rawline': '30 31 30 36 32 30 30 31 30 30 44 39 0F 46'}
{'Okay': False, 'LRC': 'FE', 'LRCtok': '\x0fE', 'lcrsum': 258, 'rawline': '30 31 30 36 32 30 30 31 30 30 44 41 0F 45'}
{'Okay': False, 'LRC': 'FD', 'LRCtok': '\x0fD', 'lcrsum': 259, 'rawline': '30 31 30 36 32 30 30 31 30 30 44 42 0F 44'}
{'Okay': False, 'LRC': 'A1', 'LRCtok': '\n1', 'lcrsum': 95, 'rawline': '30 31 30 36 32 30 30 31 30 31 33 36 0A 31'}
{'Okay': False, 'LRC': 'A0', 'LRCtok': '\n0', 'lcrsum': 96, 'rawline': '30 31 30 36 32 30 30 31 30 31 33 37 0A 30'}
{'Okay': True, 'LRC': '9F', 'LRCtok': '9F', 'lcrsum': 97, 'rawline': '30 31 30 36 32 30 30 31 30 31 33 38 39 46'}
{'Okay': True, 'LRC': '9F', 'LRCtok': '9F', 'lcrsum': 97, 'rawline': '30 31 30 36 32 30 30 31 30 31 33 38 39 46'}
{'Okay': True, 'LRC': '00', 'LRCtok': '00', 'lcrsum': 0, 'rawline': '30 30 30 30'}
{'Okay': True, 'LRC': 'FC', 'LRCtok': 'FC', 'lcrsum': 260, 'rawline': '30 31 30 36 32 30 30 31 30 30 44 43 46 43'}
{'Okay': True, 'LRC': 'FC', 'LRCtok': 'FC', 'lcrsum': 260, 'rawline': '30 31 30 36 32 30 30 31 30 30 44 43 46 43'}
{'Okay': True, 'LRC': 'F2', 'LRCtok': 'F2', 'lcrsum': 270, 'rawline': '30 31 30 36 32 30 30 31 30 30 45 36 46 32'}
{'Okay': True, 'LRC': 'F2', 'LRCtok': 'F2', 'lcrsum': 270, 'rawline': '30 31 30 36 32 30 30 31 30 30 45 36 46 32'}
{'Okay': True, 'LRC': 'E8', 'LRCtok': 'E8', 'lcrsum': 280, 'rawline': '30 31 30 36 32 30 30 31 30 30 46 30 45 38'}
{'Okay': True, 'LRC': 'E8', 'LRCtok': 'E8', 'lcrsum': 280, 'rawline': '30 31 30 36 32 30 30 31 30 30 46 30 45 38'}
{'Okay': True, 'LRC': 'DE', 'LRCtok': 'DE', 'lcrsum': 290, 'rawline': '30 31 30 36 32 30 30 31 30 30 46 41 44 45'}
{'Okay': True, 'LRC': 'DE', 'LRCtok': 'DE', 'lcrsum': 290, 'rawline': '30 31 30 36 32 30 30 31 30 30 46 41 44 45'}
{'Okay': True, 'LRC': 'D3', 'LRCtok': 'D3', 'lcrsum': 45, 'rawline': '30 31 30 36 32 30 30 31 30 31 30 34 44 33'}
{'Okay': True, 'LRC': 'D3', 'LRCtok': 'D3', 'lcrsum': 45, 'rawline': '30 31 30 36 32 30 30 31 30 31 30 34 44 33'}
{'Okay': True, 'LRC': 'C9', 'LRCtok': 'C9', 'lcrsum': 55, 'rawline': '30 31 30 36 32 30 30 31 30 31 30 45 43 39'}
{'Okay': True, 'LRC': 'C9', 'LRCtok': 'C9', 'lcrsum': 55, 'rawline': '30 31 30 36 32 30 30 31 30 31 30 45 43 39'}
{'Okay': True, 'LRC': 'BF', 'LRCtok': 'BF', 'lcrsum': 65, 'rawline': '30 31 30 36 32 30 30 31 30 31 31 38 42 46'}
{'Okay': True, 'LRC': 'BF', 'LRCtok': 'BF', 'lcrsum': 65, 'rawline': '30 31 30 36 32 30 30 31 30 31 31 38 42 46'}
{'Okay': True, 'LRC': 'B5', 'LRCtok': 'B5', 'lcrsum': 75, 'rawline': '30 31 30 36 32 30 30 31 30 31 32 32 42 35'}
{'Okay': True, 'LRC': 'B5', 'LRCtok': 'B5', 'lcrsum': 75, 'rawline': '30 31 30 36 32 30 30 31 30 31 32 32 42 35'}
{'Okay': True, 'LRC': 'AB', 'LRCtok': 'AB', 'lcrsum': 85, 'rawline': '30 31 30 36 32 30 30 31 30 31 32 43 41 42'}
{'Okay': True, 'LRC': 'AB', 'LRCtok': 'AB', 'lcrsum': 85, 'rawline': '30 31 30 36 32 30 30 31 30 31 32 43 41 42'}
{'Okay': True, 'LRC': 'A1', 'LRCtok': 'A1', 'lcrsum': 95, 'rawline': '30 31 30 36 32 30 30 31 30 31 33 36 41 31'}
{'Okay': True, 'LRC': 'A1', 'LRCtok': 'A1', 'lcrsum': 95, 'rawline': '30 31 30 36 32 30 30 31 30 31 33 36 41 31'}
{'Okay': True, 'LRC': '97', 'LRCtok': '97', 'lcrsum': 105, 'rawline': '30 31 30 36 32 30 30 31 30 31 34 30 39 37'}
{'Okay': True, 'LRC': '97', 'LRCtok': '97', 'lcrsum': 105, 'rawline': '30 31 30 36 32 30 30 31 30 31 34 30 39 37'}
{'Okay': True, 'LRC': '8D', 'LRCtok': '8D', 'lcrsum': 115, 'rawline': '30 31 30 36 32 30 30 31 30 31 34 41 38 44'}
{'Okay': True, 'LRC': '8D', 'LRCtok': '8D', 'lcrsum': 115, 'rawline': '30 31 30 36 32 30 30 31 30 31 34 41 38 44'}
{'Okay': True, 'LRC': '15', 'LRCtok': '15', 'lcrsum': 235, 'rawline': '30 31 30 36 32 30 30 31 30 31 43 32 31 35'}
{'Okay': True, 'LRC': '15', 'LRCtok': '15', 'lcrsum': 235, 'rawline': '30 31 30 36 32 30 30 31 30 31 43 32 31 35'}
{'Okay': True, 'LRC': '0B', 'LRCtok': '0B', 'lcrsum': 245, 'rawline': '30 31 30 36 32 30 30 31 30 31 43 43 30 42'}
{'Okay': True, 'LRC': '0B', 'LRCtok': '0B', 'lcrsum': 245, 'rawline': '30 31 30 36 32 30 30 31 30 31 43 43 30 42'}
{'Okay': True, 'LRC': '01', 'LRCtok': '01', 'lcrsum': 255, 'rawline': '30 31 30 36 32 30 30 31 30 31 44 36 30 31'}
{'Okay': True, 'LRC': '01', 'LRCtok': '01', 'lcrsum': 255, 'rawline': '30 31 30 36 32 30 30 31 30 31 44 36 30 31'}
{'Okay': True, 'LRC': 'F7', 'LRCtok': 'F7', 'lcrsum': 265, 'rawline': '30 31 30 36 32 30 30 31 30 31 45 30 46 37'}
{'Okay': True, 'LRC': 'F7', 'LRCtok': 'F7', 'lcrsum': 265, 'rawline': '30 31 30 36 32 30 30 31 30 31 45 30 46 37'}
{'Okay': True, 'LRC': 'ED', 'LRCtok': 'ED', 'lcrsum': 275, 'rawline': '30 31 30 36 32 30 30 31 30 31 45 41 45 44'}
{'Okay': True, 'LRC': 'ED', 'LRCtok': 'ED', 'lcrsum': 275, 'rawline': '30 31 30 36 32 30 30 31 30 31 45 41 45 44'}
{'Okay': True, 'LRC': 'E3', 'LRCtok': 'E3', 'lcrsum': 285, 'rawline': '30 31 30 36 32 30 30 31 30 31 46 34 45 33'}
{'Okay': True, 'LRC': 'E3', 'LRCtok': 'E3', 'lcrsum': 285, 'rawline': '30 31 30 36 32 30 30 31 30 31 46 34 45 33'}
{'Okay': True, 'LRC': 'D9', 'LRCtok': 'D9', 'lcrsum': 295, 'rawline': '30 31 30 36 32 30 30 31 30 31 46 45 44 39'}
{'Okay': True, 'LRC': 'D9', 'LRCtok': 'D9', 'lcrsum': 295, 'rawline': '30 31 30 36 32 30 30 31 30 31 46 45 44 39'}
{'Okay': True, 'LRC': 'CE', 'LRCtok': 'CE', 'lcrsum': 50, 'rawline': '30 31 30 36 32 30 30 31 30 32 30 38 43 45'}
{'Okay': True, 'LRC': 'CE', 'LRCtok': 'CE', 'lcrsum': 50, 'rawline': '30 31 30 36 32 30 30 31 30 32 30 38 43 45'}
{'Okay': True, 'LRC': 'C4', 'LRCtok': 'C4', 'lcrsum': 60, 'rawline': '30 31 30 36 32 30 30 31 30 32 31 32 43 34'}
{'Okay': True, 'LRC': 'C4', 'LRCtok': 'C4', 'lcrsum': 60, 'rawline': '30 31 30 36 32 30 30 31 30 32 31 32 43 34'}
{'Okay': True, 'LRC': 'BA', 'LRCtok': 'BA', 'lcrsum': 70, 'rawline': '30 31 30 36 32 30 30 31 30 32 31 43 42 41'}
{'Okay': True, 'LRC': 'BA', 'LRCtok': 'BA', 'lcrsum': 70, 'rawline': '30 31 30 36 32 30 30 31 30 32 31 43 42 41'}
{'Okay': True, 'LRC': 'B0', 'LRCtok': 'B0', 'lcrsum': 80, 'rawline': '30 31 30 36 32 30 30 31 30 32 32 36 42 30'}
{'Okay': True, 'LRC': 'B0', 'LRCtok': 'B0', 'lcrsum': 80, 'rawline': '30 31 30 36 32 30 30 31 30 32 32 36 42 30'}
{'Okay': True, 'LRC': 'A6', 'LRCtok': 'A6', 'lcrsum': 90, 'rawline': '30 31 30 36 32 30 30 31 30 32 33 30 41 36'}
{'Okay': True, 'LRC': 'A6', 'LRCtok': 'A6', 'lcrsum': 90, 'rawline': '30 31 30 36 32 30 30 31 30 32 33 30 41 36'}
{'Okay': True, 'LRC': '9C', 'LRCtok': '9C', 'lcrsum': 100, 'rawline': '30 31 30 36 32 30 30 31 30 32 33 41 39 43'}
{'Okay': True, 'LRC': '9C', 'LRCtok': '9C', 'lcrsum': 100, 'rawline': '30 31 30 36 32 30 30 31 30 32 33 41 39 43'}
{'Okay': True, 'LRC': '92', 'LRCtok': '92', 'lcrsum': 110, 'rawline': '30 31 30 36 32 30 30 31 30 32 34 34 39 32'}
{'Okay': True, 'LRC': '92', 'LRCtok': '92', 'lcrsum': 110, 'rawline': '30 31 30 36 32 30 30 31 30 32 34 34 39 32'}
{'Okay': True, 'LRC': '88', 'LRCtok': '88', 'lcrsum': 120, 'rawline': '30 31 30 36 32 30 30 31 30 32 34 45 38 38'}
{'Okay': True, 'LRC': '88', 'LRCtok': '88', 'lcrsum': 120, 'rawline': '30 31 30 36 32 30 30 31 30 32 34 45 38 38'}
{'Okay': True, 'LRC': '60', 'LRCtok': '60', 'lcrsum': 416, 'rawline': '46 37 30 33 31 33 38 39 30 30 30 41 36 30'}
 
Last edited:
By the way, this is being done in Ladder Logic on a DL05 using DirectSoft6.
My method has been to use the sum of the first 4 bytes (28h) and add it to the next two bytes of data being sent. Then I XOR the sum and add 1. I'm starting to think that I should process each byte separately every pass but not sure how to process every byte separately. What boolean logic function would gen up what I need for every byte separately and to be added together at the end?



  • Assume the six message bytes are in tag MESSAGE_STRING (excluding the leading STX/:, and the trailing LRC + (0D 0A)
  • Create with an integer tag SUM, set it to 0 (zero)
  • Create an integer tag POINTER, set it to 0 if indexing is zero-based in DirectSoft6, or set it to 1 if indexing is one-based
  • subtract the byte MESSAGE_STRING[POINTER] from SUM
    • I don't know how you do indexed addressing on the DL05; I assume you know how to do that,
  • increment pointer
  • repeat the previous two steps until the incremented pointer either is equal to the length (zero-based) or is 1 more than the length.
  • LRC = AND(SUM,FFh)
 
Last edited:
Yup. That calcs and now I see probably what the problem is. Thanks so much to all for the insight. :geek: The PLC native 16 bit format is BCD. So if I add using BCD and negate it I effectively am adding and negating in base 10 as you are then switch back to hex to extract the least significant nibble . I've probably been adding in hex/binary and Modbus and so the effective dead spots (skips) in the calc in decimal have been 10 hex or 16 dec. šŸ™ƒ I'll check that tomorrow. Tonight I'm too bleary-eyed :eek: to look at any more code but thanks. Looks like a light at the end of a tunnel!

I usually get to work at a little higher level on 99% of the PLCs I program. This takes me back to the old PLC2 and TI days in the 80s which am am so happy I don't have to deal with hardly anymore. As frustrating o_O as it's been (a PLC with no MSG function for Modbus / ASCII!) I suppose the silver lining is that its been a great refresher in binary. Makes me think of one of my favourite old Journeymen I worked for that would tell me often that he had forgotten more than I'll ever know šŸ‘ØšŸ»ā€šŸ«. 45 years in controls and always something new to exercise the brain cells. (y)
 
Last edited:

Similar Topics

need to find C bits in the logic. They are hidden someplace! Thank you! Bob
Replies
5
Views
183
I have a c-more micro with a three digit input box on one of the screens. This is being written to a memory location in a DL05. I don't have the...
Replies
3
Views
104
Does anyone have example code of how to read/write a discrete push button from a C-More Micro to a DL05. I just bought these two items and I am...
Replies
2
Views
980
Is it correct to say that the dl05 program when uploaded does not store the current value in a v memory location? I have a customer that has one...
Replies
8
Views
3,091
Hi, I am trying to learn how to use my encoder with my PLC. I recently got a high-speed counter module (H0-CTRIO2) for my DirectLogic05 PLC. I...
Replies
5
Views
2,200
Back
Top Bottom