Files
TIA_VCI/fVarMcxVd.scl
smaugain 629c0bd291 RAZ pin
2026-01-06 09:57:02 +01:00

123 lines
3.3 KiB
Plaintext

FUNCTION_BLOCK "fVarMcxVd"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
iADDR : HW_IO;
iSecu : Bool;
iEnable : Bool;
iRelBrake : Bool;
iJogP : Bool;
iJogN : Bool;
iNewPos : Bool;
iStart : Bool;
iReset : Bool;
iSelDrive2 : Bool;
iDisLimitSw : Bool;
iInhibit : Bool;
iStby : Bool;
iConsVit : UInt;
iAccel : UInt;
iDecel : UInt;
iwDo : Word;
iTpsSecu : Time := T#500MS;
END_VAR
VAR_OUTPUT
oRdy : Bool; // Ready
oSto : Bool; // / Safe stop
oPow : Bool; // Powered
oNoBrake : Bool; // Brake released
oRot : Bool; // Motor turning
oRefOk : Bool; // Referenced
oNPosAcc : Bool; // New position accepted
oInPos : Bool; // Setpoint reached/ In position
oError : Bool;
oWarn : Bool;
oDrive2Active : Bool;
oComparCons : Bool;
oLimitSwDis : Bool;
oStbyOn : Bool;
oDefCom : Bool;
oRetVit : Int;
oCodeEtat : Word;
oCodeDef : Word;
oRetCouple : Int;
oDi : Word;
END_VAR
VAR
PD { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Struct
R { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Array[1..5] of Word;
W { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Array[1..5] of Word;
END_STRUCT;
TofSecu {InstructionName := 'TOF_TIME'; LibVersion := '1.0'; S7_SetPoint := 'False'} : TOF_TIME;
DefBitVie : "fDefBitVie";
RReturn : Int;
WReturn : Int;
END_VAR
BEGIN
// Movitrac C Profinet en Velocity Drive
//Lecture du bus
IF #iADDR > 0 THEN
#RReturn := DPRD_DAT(LADDR := #iADDR, RECORD => #PD.#R);
END_IF;
// Lectures
#oRdy := #PD.R[1].%X0;
#oSto := #PD.R[1].%X1;
#oPow := #PD.R[1].%X2;
#oNoBrake := #PD.R[1].%X3;
#oRot := #PD.R[1].%X4;
#oRefOk := #PD.R[1].%X5;
#oNPosAcc := #PD.R[1].%X6;
#oInPos := #PD.R[1].%X7;
#oError := #PD.R[1].%X8;
#oWarn := #PD.R[1].%X9;
#oDrive2Active := #PD.R[1].%X10;
#oComparCons := #PD.R[1].%X11;
#oLimitSwDis := #PD.R[1].%X12;
#oStbyOn := #PD.R[1].%X14;
// Le bit 15 est recopié en interne dans le var
#DefBitVie(iIn := #PD.R[1].%X15, iDelai := T#2s, oDef => #oDefCom);
#oRetVit := WORD_TO_INT(#PD.R[2]);
IF #oError THEN
#oCodeEtat := 0;
#oCodeDef := #PD.R[3];
ELSE
#oCodeEtat := #PD.R[3];
#oCodeDef := 0;
END_IF;
#oRetCouple := WORD_TO_INT(#PD.R[4]);
#oDi := #PD.R[5];
// Ecritures
#PD.R[1] := 0; // Raz bit reserve
#TofSecu(IN := #iSecu, PT := #iTpsSecu);
#PD.W[1].%X0 := #TofSecu.Q;
#PD.W[1].%X1 := #iEnable;
#PD.W[1].%X3 := #iRelBrake;
#PD.W[1].%X4 := #iJogP;
#PD.W[1].%X5 := #iJogN;
#PD.W[1].%X6 := #iNewPos;
#PD.W[1].%X7 := #iStart;
#PD.W[1].%X8 := #iReset AND #oError;
#PD.W[1].%X10 := #iSelDrive2;
#PD.W[1].%X12 := #iDisLimitSw;
#PD.W[1].%X13 := #iInhibit;
#PD.W[1].%X14 := #iStby;
#PD.W[1].%X15 := "Clock_2Hz";
#PD.W[2] := UINT_TO_WORD(#iConsVit);
#PD.W[3] := UINT_TO_WORD(#iAccel);
#PD.W[4] := UINT_TO_WORD(#iDecel);
#PD.W[5] := #iwDo;
//Ecriture sur bus
IF #iADDR > 0 THEN
#WReturn := DPWR_DAT(LADDR := #iADDR, RECORD := #PD.#W);
END_IF;
END_FUNCTION_BLOCK