Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Switching the ethercatmaster state does not work

Switching the ethercatmaster state does not work

Open
Occasional Contributor

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,

4 REPLIES 4

CodeShepherd
Community Moderator
Community Moderator

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?

Open
Occasional Contributor

Hi CodeShepherd,

i got it working now for the function block to work i need to give execute variable false then true.

Open
Occasional Contributor

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.

Open_1-1721698484876.png

Open_2-1721698634526.png

Anyone also had the same issue?

Warmest regards,

Open
Occasional Contributor

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

 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist