I am trying to receive a J1939 CAN message using the mpJ1939Recieve FB. Here is the code and configuration I am using:
PROGRAM _INIT
mp_j1939_receive.Enable := TRUE;
received := FALSE;
END_PROGRAM
PROGRAM _CYCLIC
mp_j1939_receive.Data := ADR(data);
mp_j1939_receive.DataLength := 1;
mp_j1939_receive.MpLink := ADR(gJ1939Receive_Master);
mp_j1939_receive.PGN := 65305;
mp_j1939_receive.Priority := 3;
mp_j1939_receive();
IF NOT mp_j1939_receive.CommandDone AND
NOT mp_j1939_receive.CommandBusy AND
mp_j1939_receive.Active AND
NOT mp_j1939_receive.Error THEN
mp_j1939_receive.Receive := TRUE;
ELSE
mp_j1939_receive.Receive := FALSE;
END_IF;
IF mp_j1939_receive.CommandDone AND
mp_j1939_receive.Info.ReceivedBytes = 1 THEN
received := TRUE;
END_IF;
END_PROGRAM
PROGRAM _EXIT
mp_j1939_receive.Enable := FALSE;
mp_j1939_receive();
received := FALSE;
END_PROGRAM
There are two more devices on the same can line that can exchange can messages without a problem, therefore I don’t think that the wiring is wrong. I also measured the resistance and got 60 Ohms between high and low when the system was without power.
I am by no means a CAN expert, but I had some thoughts reading your post so I thought I’d make a reply in case this helps you.
From your description, it’s not clear whether the problem is related to the J1939 library or CAN communication in general. If you’ve triple checked all of the J1939 programming and configuration (which looks okay to me on first glance), then I’d recommend troubleshooting the CAN communication itself.
One way to do this is using a CAN → USB dongle and related software (e.g. PCAN). A device like this allows you to see all of the messages on the CAN network and pick them apart. This way you can verify that the messages contain the data you expect.
Another option is to write a simple program on the PLC using the ArCAN library (which has a sample program in the Library Samples folder of the Toolbox!). You can use this to verify that your PLC is receiving the correct message data. Once you know the CAN messages are making it, you can focus on J1939 library specifically.
I know you said that other devices on the network are receiving data, but in my experience this doesn’t always mean that your PLC is receiving the data. If the communication settings between the sender and the receiver differ too much, the PLC may just not be seeing anything on the network. You also said:
I also measured the resistance and got 60 Ohms between high and low when the system was without power
I find this odd because the network should be terminated with a 120 Ohm resistor. What is the value of the resistor you have connected to the end of the network, after the PLC?
thank you for the suggestions, I will try them out.
A CAN line needs one resistor on each end to prevent signal reflections. This means you have two 120 Ohm resistors in parallel that result into 60 Ohms in total.