Implemented stuff to get ready for jet measurement
This commit is contained in:
@@ -28,10 +28,21 @@ VAR
|
||||
|
||||
// Rerun flag for faster state machine
|
||||
_xSMCycleDone : BOOL := TRUE;
|
||||
|
||||
_xMasterWasBusy : BOOL;
|
||||
|
||||
_xTest : BOOL;
|
||||
END_VAR
|
||||
]]></Declaration>
|
||||
<Implementation>
|
||||
<ST><![CDATA[// Main state machine
|
||||
<ST><![CDATA[//_fbMaster();
|
||||
|
||||
IF _xTest THEN
|
||||
_xTest := FALSE;
|
||||
_fbMaster.ReadInputRegs(Execute := FALSE);
|
||||
END_IF
|
||||
|
||||
// Main state machine
|
||||
REPEAT
|
||||
// Safety reset
|
||||
_xSMCycleDone := TRUE;
|
||||
@@ -51,13 +62,6 @@ REPEAT
|
||||
1:
|
||||
// Get next request from queue if there is one
|
||||
IF M_Dequeue() THEN
|
||||
// Set fb data
|
||||
_fbMaster.UnitID := _stCurrReq.bySlaveAddr;
|
||||
_fbMaster.MBAddr := _stCurrReq.wStartAddr;
|
||||
_fbMaster.Quantity := _stCurrReq.wQuantity;
|
||||
_fbMaster.cbLength := _stCurrReq.wDataSize;
|
||||
_fbMaster.pMemoryAddr := _stCurrReq.pvData;
|
||||
|
||||
// Rerun statemachine this cycle
|
||||
_xSMCycleDone := FALSE;
|
||||
_iState := 10;
|
||||
@@ -68,13 +72,34 @@ REPEAT
|
||||
// Call modbus master corresponding function
|
||||
CASE _stCurrReq.eCmd OF
|
||||
E_Modbus_Cmd.READ_HOLDING:
|
||||
_fbMaster.ReadRegs();
|
||||
_fbMaster.ReadRegs(
|
||||
UnitID := _stCurrReq.bySlaveAddr,
|
||||
Quantity := _stCurrReq.wQuantity,
|
||||
MBAddr := _stCurrReq.wStartAddr,
|
||||
cbLength := _stCurrReq.wDataSize,
|
||||
pMemoryAddr := _stCurrReq.pvData,
|
||||
Execute := TRUE,
|
||||
Timeout := T#1S);
|
||||
|
||||
E_Modbus_Cmd.READ_INPUTS:
|
||||
_fbMaster.ReadInputRegs();
|
||||
_fbMaster.ReadInputRegs(
|
||||
UnitID := _stCurrReq.bySlaveAddr,
|
||||
Quantity := _stCurrReq.wQuantity,
|
||||
MBAddr := _stCurrReq.wStartAddr,
|
||||
cbLength := _stCurrReq.wDataSize,
|
||||
pMemoryAddr := _stCurrReq.pvData,
|
||||
Execute := TRUE,
|
||||
Timeout := T#1S);
|
||||
|
||||
E_Modbus_Cmd.WRITE_HOLDING:
|
||||
_fbMaster.WriteRegs();
|
||||
_fbMaster.WriteRegs(
|
||||
UnitID := _stCurrReq.bySlaveAddr,
|
||||
Quantity := _stCurrReq.wQuantity,
|
||||
MBAddr := _stCurrReq.wStartAddr,
|
||||
cbLength := _stCurrReq.wDataSize,
|
||||
pMemoryAddr := _stCurrReq.pvData,
|
||||
Execute := TRUE,
|
||||
Timeout := T#1S);
|
||||
|
||||
// Reject unknown commands
|
||||
ELSE
|
||||
@@ -82,8 +107,15 @@ REPEAT
|
||||
_iState := 0;
|
||||
END_CASE
|
||||
|
||||
IF _fbMaster.BUSY THEN
|
||||
_xMasterWasBusy := TRUE;
|
||||
END_IF
|
||||
|
||||
// Wait for fb to be done
|
||||
IF (NOT _fbMaster.BUSY) THEN
|
||||
_fbMaster.ReadRegs(Execute := FALSE);
|
||||
_fbMaster.ReadInputRegs(Execute := FALSE);
|
||||
_fbMaster.WriteRegs(Execute := FALSE);
|
||||
_stCurrReq.pxDone^ := TRUE;
|
||||
// Rerun statemachine this cycle
|
||||
_xSMCycleDone := FALSE;
|
||||
@@ -91,6 +123,9 @@ REPEAT
|
||||
END_IF
|
||||
|
||||
IF _fbMaster.Error THEN
|
||||
_fbMaster.ReadRegs(Execute := FALSE);
|
||||
_fbMaster.ReadInputRegs(Execute := FALSE);
|
||||
_fbMaster.WriteRegs(Execute := FALSE);
|
||||
_stCurrReq.pxError^ := TRUE;
|
||||
// Rerun statemachine this cycle
|
||||
_xSMCycleDone := FALSE;
|
||||
@@ -137,7 +172,7 @@ _iNextTail := (_iTail + 1) MOD GVL_ModbusMaster.QUEUE_SIZE;
|
||||
IF _iNextTail = _iHead THEN
|
||||
M_Enqueue := FALSE;
|
||||
ELSE
|
||||
_astReqQueue[_iNextTail] := stReq;
|
||||
_astReqQueue[_iTail] := stReq;
|
||||
_iTail := _iNextTail;
|
||||
M_Enqueue := TRUE;
|
||||
END_IF
|
||||
|
||||
Reference in New Issue
Block a user