Function Block to MODBUS CRC Calculation.

2008-10-16
2008-10-23
  • Mauricio-Lopes - 2008-10-16

    Hi all.

    I am working in a project that has some MODBUS RTU Slaves but the custumer is using a plataform that doesn't have support for this protocol but this plataform has two RS-485 ports. So I am creating the protocol manually and I had difficulties to create the CRC function Block. I will post the code of this FB and I hope that can be helpful for anyone that having the same difficult that I've had. It's the first version and I am testing it yet. Maybe it has some bugs. If anyone want to test or modify the code please don't forget to post your feedback here .

    Best Regards

    FBCRC16MODBUS.zip [1.15 KiB]

     
  • hugo - 2008-10-17

    Hi mauricio

    in the open source library from oscat you can find function blocks for crc encode and crc decode

    both in open source and ready to use

    w www.oscat.de w

     
  • Mauricio-Lopes - 2008-10-18

    Hi Hugo.

    Thanks for infomation. I get the library from OSCAT, but the values that the blocks returns seems incoherent and I can't find good explanation about these blocks.

    Thanks a lot.

    Mauricio.

     
  • hugo - 2008-10-19

    do you have a clear description what crc you need? detailes of polynom, and other parameters?

     
  • hugo - 2008-10-19

    i did look through your code, and cannot find any initial polynom or other setup parameters.

    CRC is a general form of cyclic redundancy check.

    there is literally hundreds of different CRTC's

    you need to find out your specific CRC paramaters like:

    polynom,

    reverses byte order or not

    reversed bits in bytes?

    inverse bytes?

    starting bits FF or 00

    ending bits ff or 00

    only with the exact paramaters a crc generator or checker can deliver the correct results

     
  • Mauricio-Lopes - 2008-10-21

    Hi hugo,

    This CRC check is for MODBUS RTU and I get that tables from MODICON page. I don't have any Idea which polynom is that... I've tried to use the OSCAT library before write this fb, that is powerful library, but I got the same problem that you told...

    Thanks a lot.

     
  • Uwe - 2008-10-21

    Hello Mauricio,

    i checked your fb and it works fine.

    Your fb calculated exact the same crc like Modscan.

    (see the attached hardcopy)

    I think your problem is the use of your fb.

    Are you shure you call it with the correct length ?

    Best Regards

    Uwe

    IMG: Hardcopy.JPG

     
  • hugo - 2008-10-23

    Dear Mauricio,

    of oscat crc block is a general purpose crc which can only deliver the correct output if its configured with the right parameters. in the oscat manual we mention about 40 different types of CRC's. in praktical terms there is probably around hundreds of different flavours.

    without the knowledge of what needs to be done its hard to do the job

     

Log in to post a comment.