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
New 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,

2 REPLIES 2

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?

Hi CodeShepherd,

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

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