Reputation: 3
Codesys v3.5 sp20+(32bit)
I hope to power up the specified axis through the following code,It worked.
The following code is called cyclically,It's called by a task every 4 milliseconds.
PROGRAM PowerupTest
VAR
MC_Power_0: MC_Power;
Axises:ARRAY[0..5] OF SM3_Drive_ETC_DS402_CyclicSync.AXIS_REF_ETC_DS402_CS;
END_VAR
MC_Power_0(
Axis:=Axis0,
Enable:=1 ,
bRegulatorOn:=1 ,
bDriveStart:=1 ,
Status=> ,
bRegulatorRealState=> ,
bDriveStartRealState=> ,
Busy=> ,
Error=> ,
ErrorID=>
);
Now, to change it a little bit, I save Axis0 into an array first, and then pass the elements of the array into the MC_Power function block.
It doesn't work properly anymore.
Axises[0]:=Axis0;
MC_Power_0(
Axis:=Axises[0], //Changed here
Enable:=1 ,
bRegulatorOn:=1 ,
bDriveStart:=1 ,
Status=> ,
bRegulatorRealState=> ,
bDriveStartRealState=> ,
Busy=> ,
Error=> ,
ErrorID=>
);
Could you tell me the possible reason? I hope I can access all axes as an array.
Thank you.
=========================
I made the following changes, but it still doesn't work.
PROGRAM PowerupTest
VAR
MC_Power_0: MC_Power;
Axises:ARRAY[0..5] OF SM3_Drive_ETC_DS402_CyclicSync.AXIS_REF_ETC_DS402_CS;
IsInitialized:BOOL:=false;
END_VAR
IF NOT IsInitialized THEN
Axises[0]:=Axis0;
IsInitialized:=TRUE;
RETURN;
END_IF
MC_Power_0(
Axis:=Axises[0],
Enable:=1 ,
bRegulatorOn:=1 ,
bDriveStart:=1 ,
Status=> ,
bRegulatorRealState=> ,
bDriveStartRealState=> ,
Busy=> ,
Error=> GVL.LastError,
ErrorID=> GVL.LastErrorId
);
Upvotes: 0
Views: 82
Reputation: 3
Problem solved, I should use a pointer to save the reference to the axis object
PROGRAM PowerupTest
VAR
MC_Power_0: MC_Power;
Axises:ARRAY[0..5] OF POINTER TO SM3_Drive_ETC_DS402_CyclicSync.AXIS_REF_ETC_DS402_CS;
IsInitialized:BOOL:=false;
END_VAR
Axises[0]:=ADR(Axis0);
MC_Power_0(
Axis:=Axises[0]^,
Enable:=1 ,
bRegulatorOn:=1 ,
bDriveStart:=1 ,
Status=> ,
bRegulatorRealState=> ,
bDriveStartRealState=> ,
Busy=> ,
Error=> ,
ErrorID=>
);
Upvotes: 0
Reputation: 6995
I assume the code shown is called cyclically.
Then, it seems likely to me that the problem is that you overwrite Axis[0]
with the content of Axis0
every cycle. Since Axis0
is not used, its internal state never changes, so anything that was done to Axis[0]
as part of the call to MC_Power_0
is wiped out.
Why to you have Axises[0]:=Axis0;
? If there is some initialization done to Axis0
that you want to transfer to Axis[0]
, you can do the same directly with Axis[0]
instead. If you really want to keep this line, make sure it is called only once at the beginning of your program rather than at every cycle.
Upvotes: 1