J1939 Timing

If I use the code below to receive a J1939 can message, is the data available in the same cycle where the Receive is set to true or in the following cycle?

fb_receive_patrol_f_shm(MpLink := ADR(gJ1939Receive_patrol_shm),
Enable := TRUE,
PGN := 3584,
Priority := 3,
Data  := ADR(pgn_data_raw_shm),
DataLength := 8);

IF NOT fb_receive_patrol_f_shm.CommandDone AND 
	NOT fb_receive_patrol_f_shm.CommandBusy AND
	fb_receive_patrol_f_shm.Active AND
	NOT fb_receive_patrol_f_shm.Error THEN
	fb_receive_patrol_f_shm.Receive := TRUE;
ELSE
	fb_receive_patrol_f_shm.Receive := FALSE;	
END_IF;

This code calls the function block once at the beginning. The inputs and outputs are processed when the function block is called, so there is no way for the data to update in the same cycle that Receive is set.

However, from the MpJ1939Receive documentation:

The requested information is indicated via the positive edge input parameter “Receive” = TRUE on parameter “Data”. Output “CommandDone” set to TRUE indicates that the command was successful. This means that every positive edge at “Receive” requests the information at the specified PGN

The function block works asynchronously and so you must wait for CommandDone to be true to know that the data has been processed.

1 Like