6/11/2019 11:11 AM | |
Joined: 4/11/2012 Last visit: 12/4/2023 Posts: 176 Rating: (34) |
I won't go to the actual CRC calculation, that is already covered elsewhere (link at the end): But a troubling situation has come up when I'm receiving data from a Hardware component that provides me 4 DINT of data and a CRC that the component calculated from that data. I created a program to calculate the CRC from the data I receive and compare it to the received CRC, and it indicated that the received CRC did not match my calculated CRC. Then I fed the data I received to the online calculator and confirmed that the CRC given by the online calculator matched the CRC I calculated.https://www.lammertbies.nl/comm/info/crc-calculation.html But when I did some more digging, I found out that if I converted the received data to Little Endian format and then performed the CRC calculation, I got the same results as the received CRC. And if I fed the data to the online calculator in Little Endian format, the online calculator also gave the same CRC that was provided by the device. So this is the situation:I receive the data as normal profinet data, in Big Endian format (LSB in the rightmost byte) but the CRC calculated from that data is calculated from Little Endian data (LSB in the leftmost byte). The Modbus 16 CRC specification defines the following: How should this be seen? Is this specification only relevant when Modbus is used in serial line communication, and not as a general rule for Modbus 16 CRC calculation? Or does this mean that even though Siemens has data in Big Endian format, the CRC should always be calculated from the data in Little Endian format? So before the CRC calculation, the data should be converted to Little Endian and only then the calculation should be made? (When DINT is moved to bytearray for the CRC calculation, the LSB byte should be moved to Array[0] and MSB should be moved to Array[3]? When by default the data would to the opposite way, the MSB would go to Array[0] and LST to Array[3].) Or should we require that the Hardware provider changes their system (new firmware to device and new GSD file for us) so that the CRC they provide is calculated from Big Endian Data? I don't actually know the details of Profinet, does the Profinet care about Little / Big Endian? Or can a Big Endian device send n bytes of data to Little Endian device and the data will appear in the order the Little Endian device expects? (Is it possible that the Hardware device is Little Endian and that is why it calculates the data in Little Endian format, and the device itself sends data in Little Endian format, but the Profinet protocol defines the byteorder so that it arrives safely to the Big Endian device?) The attached excel contains some raw data and received CRC from the data and the different byte order configurations the data can be seen in. Related topics: AttachmentCRC assistant_Cleared.xlsx (176 Downloads) |
Last edited by: Elonen at: 06/11/2019 11:12:40Unfinished sentence clarified. Last edited by: Elonen at: 06/11/2019 11:29:12Added question about when the Modbus CRC specs should be used |
|
Follow us on