Results 1 to 3 of 3

Thread: Trying to write minimal test program for CR0401 + J1939 device

  1. #1

    Default Trying to write minimal test program for CR0401 + J1939 device

    I'm working on a bare bones codesys program for validating message transmission from a J1939 device (SureGrip joystick in this case) to a CR0401 controller. I've got a program running and receiving data from the joystick, but before I turn it into a "How To" document to keep on hand I'd like to see if I can get some feedback on if there was a better way to do it.

    The basic steps I used were:
    1. Gather device hardware info first. Case in point J1939 device, spec sheet address of 0x30 (replace 0x with 16# when using codesys), baud rate is 250 kb/s, spec sheet shows PGN's of 64982 & 64984 being sent. Ensure that 120 ohm terminating resistor is installed on J1939 device.
    2. Use the maintenance tool to flash the correct bootloader
    3. Create new Codesys (currently 2.3.9) .pro from template. Use CR0401 Layer 2 (use same template version as bootloader).
    4. Test comm between CodeSys and CR0401 by building and uploading an empty template .pro. If canFox usb is on CAN1, use 127. If canFox usb is on CAN2, use 126.
    5. Add library "ifm_J1939_NT" (check for same version as hardware / bootloader) to CodeSys program.
    6. Add POU's for "J1939_ENABLE" and "J1939_RX" using the same CAN channel, baud, & PGN that the J1939 device will be communicating on.
    7. DO NOT make changes to "PLC Configuration", not necessary for testing J1939 device.
    8. Create a global catch-all variable that the DATA output of J1939_RX can be streamed to.
    9. Create a POU and variable that only stores values from the DATA output of J1939_RX when the RESULT == 1 (message sent without error).
    10. Rebuild program, upload, and run with CodeSys monitoring.
    11. While running confirm the following: J1939_ENABLE is TRUE; RESULT from J1939_RX is = 1 at least some of the time (0 when not transmitting); catch-all data stream is seeing traffic; and that data saved when J1939_RX.RESULT =1 is not being overwritten with 0's each time J1939_RX.RESULT=0.
    12. If all above pass, proceed with adding J1939 device to desired project.

    While these steps are working for me right now, this is my first J1939 device I'm using and I have a feeling I made a mountain out of a mole hill. If you can see somewhere that I can simplify my device testing work flow I'd love to know. Thanks for the help.

  2. #2
    Join Date
    May 2009
    Minneapolis, MN


    Everything looks good. I would add some more to 11.

    SourceAddress : BYTE := 80; (*source address of device we wish to get PGN data from*)
    tmrResultBad : TON;
    J1939RxFB : J1939_RX;
    abPGNData : ARRAY [1..8] OF BYTE;
    abZeros : ARRAY [1..8] OF BYTE; (*empty array*)


    tmrResultBad (IN:=J1939RxFB.RESULT <> 1, PT:=T#2s); (*higher that repeat rate of PGN being transmitted x2*)

    IF tmrResultBad.Q THEN
    abPGNData := abZeros;
    ELSIF J1939RxFB.RESULT = 1 and J1939RxFB.SA = SourceAddress THEN
    abPGNData := J1939RxFB.Data;
    abPGNData := abPGNData;

  3. #3


    Thanks Erik,

    I'll add that and check it out.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts