Commissioning
EL600x, EL602x
142
Version: 4.6
i: BYTE; // Counter variable
wResult:WORD; // Resulting output value
END_VAR
Execution part:
wResult := BYTE_TO_WORD(pData^[0]);
FOR i := 1 TO (nLen-1) DO
wResult := w BYTE_TO_WORD(pData^[i]);
IF wResult > 255 THEN
wResult := wResult - 255;
END_IF
END_FOR
F_CALC_LIN_CHKSUM := WORD_TO_BYTE(NOT(wResult));
This master program part should be called from a corresponding separate task. Here, a node in the LIN bus
with the ID 0x07 is queried every 200 ms.
Declaration part:
PROGRAM EL6001_MASTER
VAR
Timer: TON; // Timer for periodical requests by the master
Send: SendData; // Functionblock of TC2_SerialCom
SendBusy: BOOL; // Flag copy of SendData.Busy
SendErrorID: ComError_t; // Flag-Copy of Error-ID
aDataTX:tDataFrame; // Data frame being send
Receive: ReceiveData; // Functionblock of TC2_SerialCom
LastReceivedDataBytes: tDataFrame; // Copy (Latch) of received data
DataReceived: BOOL; // Flag copy of receive confirmation
ReceiveBusy: BOOL; // Flag copy of reception not ready
ReceiveError: BOOL; // Flag copy of receive error
ReceiveErrorID: ComError_t;// Error-ID copy
ReceiveTimeout: BOOL; // Flag copy of receive-timeout
ReceiveCounter: UDINT := 0; // Number of received frames
aDataRX:tDataFrame; // Receiving data frame buffer
nDataLen:BYTE := 4; // Fixed data length
nState:BYTE := 0; // Initial state (start)
bNodeId_SL1: BYTE := 16#07; // ID of slave node
bReqLen_SL1: BYTE := 0; // Optional entry for 4 Data bytes Value 2
nRxChecksum: BYTE; // Storage of received checksum
nCalcChecksum:BYTE; // Storage of calculated checksum
T_ReceiveDelay:TIME; // Storage of calculated delay time
END_VAR
Execution part:
(*==================================================================
Receive data
*)
CASE nState OF
0:
Timer(IN:=TRUE, PT:=T#0.5S); // Call timer for periodical master requests
IF Timer.Q THEN
// Put ID into Tranceive data:
aDataTX[0] := F_ADD_LIN_NODE_PARITY(bNodeId_SL1, bReqLen_SL1);
LastReceivedDataBytes[0] := aDataTX[0];
// Send request to Slave 1 (get Data)
Send(pSendData:= ADR(aDataTX), Length:= 1,
TXbuffer:= TxBuffer_MASTER,
Busy => SendBusy, Error => SendErrorID);
Timer(IN:=FALSE); (* reset timer *)
IF NOT SendBusy THEN // Wait until sending ends
nState := 1;
END_IF
END_IF
1:
// Delaytime by 1/Tbaud * Number of Bytes * (8 Da 2 Bit:start-Stop) * 1000ms
T_ReceiveDelay := REAL_TO_TIME((1/DINT_TO_REAL(nSetBaudrate)) * 33 * 1000); // .. for 1 Byte
Timer(IN:=TRUE, PT:=T_ReceiveDelay);
IF Timer.Q THEN
// Wait until ID is send
nState := 1;
Timer(IN:=FALSE); (* reset timer *)
END_IF
2:
Receive(
pReceiveData:= ADR(aDataRX),
SizeReceiveData:= (nD 1),
RXbuffer:= RxBuffer_MASTER,