I’m having an issue with the GenerateForwardCrc16OnString method.
I’m using a USB to FTDI serial device to send modbus strings to a J1939 converter. But unfortunately I haven’t got to that point yet.
The J1939 converter has an example modbus messages I’m testing my RS232 output with.
when I duplicate that message in PAC Control and use GenerateForwardCrc16OnString on it, the CRC that’s generated is FE95.
I’ve double checked the example CRC with a CRC generator I wrote in C# and it checks out. So I’m thinking I’m missing something small and silly in PAC Control.
I’ve used Forward and Reverse, etc. to no avail.
My code:
if (HasDownTimerExpired(CANout_Timer) == 1 or CANout_SendImmediately == 1) then
SetDownTimerPreset(CANout_Delay, CANout_Timer);
StartTimer(CANout_Timer);
CANout_SendImmediately = 0;
CANout_Message = Chr(0x01) + Chr(0x10) + Chr(0x00) + Chr(0x00) + Chr(0x00) + Chr(0x01) + Chr(0x02) + Chr(0x12) + Chr(0x34);
//CANout_Checksum = 0xAB27; // known checksum in hex
//CANout_Checksum = 43815; // known checksum in dec
// generate our own
CANout_Checksum = GenerateForwardCrc16OnString(0, CANout_Message);
//--------------------
NumberToHexString(CANout_Checksum, CANout_CRC); // convert to hex
CANout_Message = CANout_Message + CANout_CRC; // append
endif
Can anyone see any issue with what I’m doing? I’m wondering if I should just switch to codesys and output the J1939 natively.
Paging @greichert for the Codesys question (Im thinking yes, the less middleware the better usually).
Paging @philip and @torchard for Modbus and code experience.