FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We will start the migration process in one hour.
The community will be then in READ ONLY mode.
Read more: Important
information on the platform change.
03-21-2024 07:08 AM - last edited on 03-21-2024 08:16 AM by CodeShepherd
Hi,
I am new to CXA_EtherCATMaster library and i have the similiar issue, the CytroPac when it power on it is in Safe-OP mode and need to switch to INIT -> OP mode for it to be operational.
I tried following your code:
Declaration:
PROGRAM PLC_PRG
VAR
//CytroPac EtherCAT Switch State OP -> INIT -> OP
fbECATMasterGetBusState: IL_ECATMasterGetBusState;
eActBusState: IL_ECAT_STATE;
fbECATMasterSetBusState: IL_ECATMasterSetBusState;
fbIL_ECATRemoteSlaveGetDevState1: IL_ECATRemoteSlaveGetDevState;
eActDevState1: IL_ECAT_STATE;
fbIL_ECATRemoteSlaveGetDevState2: IL_ECATRemoteSlaveGetDevState;
eActDevState2: IL_ECAT_STATE;
fbIL_ECATRemoteSlaveGetDevState3: IL_ECATRemoteSlaveGetDevState;
eActDevState3: IL_ECAT_STATE;
fbIL_ECATRemoteSlaveSetDevState1: IL_ECATRemoteSlaveSetDevState;
fbIL_ECATRemoteSlaveSetDevState2: IL_ECATRemoteSlaveSetDevState;
fbIL_ECATRemoteSlaveSetDevState3: IL_ECATRemoteSlaveSetDevState;
strMasterName: STRING := 'ethercatmaster';
iSetMaster: INT;
bExecute: BOOL;
END_VAR
Implementation:
//CytroPac EtherCAT Switch State OP -> INIT -> OP
fbECATMasterSetBusState.Execute := bExecute;
fbECATMasterSetBusState.MasterName := ADR(strMasterName);
CASE iSetMaster OF
0: //Automatically Start every slave in OP mode
IF NOT (eActDevState1 = ECAT_STATE_OP AND eActDevState2 = ECAT_STATE_OP) AND eActDevState3 = ECAT_STATE_OP THEN
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_INIT;
ELSIF eActBusState = ECAT_STATE_INIT THEN
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_OP;
END_IF
1:
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_INIT;
2:
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_PREOP;
3:
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_SAFEOP;
4:
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_OP;
END_CASE
fbECATMasterSetBusState();
IF fbECATMasterSetBusState.Done THEN
; // Master reached operational state
END_IF
IF TRUE = fbECATMasterSetBusState.Error THEN
; // Error handling
END_IF
When i write iSetMaster = 1 (Switch EtherCAT Master State INIT), my ctrlX EtherCAT Master state remain OP.
does anyone have a code example for switching between EtherCAT state? i have seen this example but i do not understand how the switching works.
Warmest regards,
Solved! Go to Solution.
03-21-2024 08:31 AM
Moved to own topic from "Switching the ethercatmaster between states".
Did you check the sample in the library CXA_EtherCatMaster itself? As your code looks quite similar I guess yes. Could you try switching to one state at a time?
Do you also write "bExecute := true" after choosing "iSetMaster := 1", so that function block execution gets started?
03-28-2024 03:26 AM
Hi CodeShepherd,
i got it working now for the function block to work i need to give execute variable false then true.
07-23-2024 03:38 AM
Hello @CodeShepherd ,
I am facing issue with reading the EtherCAT State in PLC.
I followed the code above. The value i received is ECAT_STATE_UNKNOWN.
Anyone also had the same issue?
Warmest regards,
07-23-2024 08:59 AM
I have solved it.
I used fbIL_ECATRemoteSlaveGetDevState1.ActDevState = ECAT_STATE_OP instead of eActBusState1.
Declaration:
PROGRAM EtherCAT_Auto_Switching_OP_INIT
VAR
fbIL_ECATRemoteSlaveGetDevState1: IL_ECATRemoteSlaveGetDevState;
strMasterName : STRING := 'ethercatmaster';
eActBusState1 : IL_ECAT_STATE;
eActDevState1: CXA_EthercatMaster.IL_ECAT_STATE;
fbIL_ECATRemoteSlaveGetDevState2: IL_ECATRemoteSlaveGetDevState;
eActBusState2 : IL_ECAT_STATE;
eActDevState2: CXA_EthercatMaster.IL_ECAT_STATE;
fbIL_ECATRemoteSlaveGetDevState3: IL_ECATRemoteSlaveGetDevState;
eActBusState3 : IL_ECAT_STATE;
eActDevState3: CXA_EthercatMaster.IL_ECAT_STATE;
fbIL_ECATRemoteSlaveGetDevState4: IL_ECATRemoteSlaveGetDevState;
eActBusState4 : IL_ECAT_STATE;
eActDevState4: CXA_EthercatMaster.IL_ECAT_STATE;
fbBLINK: BLINK;
bBlinkOut: BOOL;
//AUTO Switching Condition
fbIL_ECATRemoteSlaveSetDevState1: IL_ECATRemoteSlaveSetDevState;
fbIL_ECATRemoteSlaveSetDevState2: IL_ECATRemoteSlaveSetDevState;
fbIL_ECATRemoteSlaveSetDevState3: IL_ECATRemoteSlaveSetDevState;
fbIL_ECATRemoteSlaveSetDevState4: IL_ECATRemoteSlaveSetDevState;
iSetMaster: INT;
bExecute: BOOL;
fbECATMasterSetBusState: IL_ECATMasterSetBusState;
eActBusState: IL_ECAT_STATE;
fbECATMasterGetBusState: IL_ECATMasterGetBusState;
END_VAR
Implementation:
//Read EtherCAT State
//1001
fbBLINK(ENABLE:= TRUE, TIMELOW:= T#1S, TIMEHIGH:= T#1S, OUT=> bBlinkOut);
fbIL_ECATRemoteSlaveGetDevState1.Execute := bBlinkOut;
fbIL_ECATRemoteSlaveGetDevState1.MasterName := ADR(strMasterName);
fbIL_ECATRemoteSlaveGetDevState1.SlaveAddress := 1001;
fbIL_ECATRemoteSlaveGetDevState1();
IF TRUE = fbIL_ECATRemoteSlaveGetDevState1.Done THEN
eActDevState1 := fbIL_ECATRemoteSlaveGetDevState1.ActDevState;
END_IF
IF TRUE = fbIL_ECATRemoteSlaveGetDevState1.Error THEN
; // error handling
END_IF
//1002
fbIL_ECATRemoteSlaveGetDevState2.Execute := bBlinkOut;
fbIL_ECATRemoteSlaveGetDevState2.MasterName := ADR(strMasterName);
fbIL_ECATRemoteSlaveGetDevState2.SlaveAddress := 1002;
fbIL_ECATRemoteSlaveGetDevState2();
IF TRUE = fbIL_ECATRemoteSlaveGetDevState2.Done THEN
eActDevState2 := fbIL_ECATRemoteSlaveGetDevState2.ActDevState;
END_IF
IF TRUE = fbIL_ECATRemoteSlaveGetDevState2.Error THEN
; // error handling
END_IF
//1003
fbIL_ECATRemoteSlaveGetDevState3.Execute := bBlinkOut;
fbIL_ECATRemoteSlaveGetDevState3.MasterName := ADR(strMasterName);
fbIL_ECATRemoteSlaveGetDevState3.SlaveAddress := 1003;
fbIL_ECATRemoteSlaveGetDevState3();
IF TRUE = fbIL_ECATRemoteSlaveGetDevState3.Done THEN
eActDevState3 := fbIL_ECATRemoteSlaveGetDevState3.ActDevState;
END_IF
IF TRUE = fbIL_ECATRemoteSlaveGetDevState3.Error THEN
; // error handling
END_IF
//1004
fbIL_ECATRemoteSlaveGetDevState4.Execute := bBlinkOut;
fbIL_ECATRemoteSlaveGetDevState4.MasterName := ADR(strMasterName);
fbIL_ECATRemoteSlaveGetDevState4.SlaveAddress := 1004;
fbIL_ECATRemoteSlaveGetDevState4();
IF TRUE = fbIL_ECATRemoteSlaveGetDevState4.Done THEN
eActDevState4 := fbIL_ECATRemoteSlaveGetDevState4.ActDevState;
END_IF
IF TRUE = fbIL_ECATRemoteSlaveGetDevState4.Error THEN
; // error handling
END_IF
//AUTO Switching Condition
fbECATMasterGetBusState.Execute := bBlinkOut;
fbECATMasterGetBusState.MasterName := ADR(strMasterName);
fbECATMasterGetBusState();
fbECATMasterSetBusState.Execute := bExecute;
fbECATMasterSetBusState.MasterName := ADR(strMasterName);
CASE iSetMaster OF
0: //Automatically Start every slave in OP mode
IF NOT (fbIL_ECATRemoteSlaveGetDevState1.ActDevState = ECAT_STATE_OP) AND (fbIL_ECATRemoteSlaveGetDevState2.ActDevState = ECAT_STATE_OP) AND (fbIL_ECATRemoteSlaveGetDevState3.ActDevState = ECAT_STATE_OP) AND (fbIL_ECATRemoteSlaveGetDevState4.ActDevState = ECAT_STATE_OP) THEN
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_INIT;
ELSIF fbECATMasterGetBusState.ActBusState = ECAT_STATE_INIT THEN
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_OP;
END_IF
1:
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_INIT;
2:
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_PREOP;
3:
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_SAFEOP;
4:
fbECATMasterSetBusState.NewBusState := IL_ECAT_STATE.ECAT_STATE_OP;
END_CASE
fbECATMasterSetBusState();
IF fbECATMasterSetBusState.Done THEN
; // Master reached operational state
END_IF
IF TRUE = fbECATMasterSetBusState.Error THEN
; // Error handling
END_IF