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

Writing value in element 0 of P-0-0397

alink
Long-established Member

Writing value in element 0 of P-0-0397

Hello,

I'd like to write a value into the parameter P-0-0397. This parameter contains of 2 elements. How to write on element '0' with FB IL_CATSoeWrite? Currently, the result is a timeout error....

ecaterror.JPG

To write this parameter of an IndraDrive

drive_para.JPG

 

5 REPLIES 5
CodeShepherd
Community Moderator

Re: Writing value in element 0 of P-0-0397

Did you already check this post?

alink
Long-established Member

Re: Writing value in element 0 of P-0-0397

Yes, but if I'm not wrong then the solved issue belongs to

READ ListParameter and then Write to S-0-0052 which isn't a list.

I tried with an ARRAY[0..1] OF UINT to Write to P-0-0397

[0] := input of VISU , the value what should be set to P-0-0397 element 0

[1] := 0 , not used

Still timeout error.

CodeShepherd
Community Moderator

Re: Writing value in element 0 of P-0-0397

See my example for the ctrlX DRIVE. Beware that the values in my case is 4 Byte and the digits after decimal point are 3. In IndraDrive it is 2 Byte and 1 digit. I created an own structure corresponding to the drive parameter that then is written via IL_ECATSoeWrite:

Struct:

TYPE MyTableStruct :
STRUCT
	ActLength : UINT;
	MaxLength : UINT;
	ArrayOfElements : ARRAY[0..3] OF UDINT;
END_STRUCT
END_TYPE

Declaration:

PROGRAM Read_Write_StringParameter
VAR
	fbECATSoeWrite: IL_ECATSoeWrite;
	WriteList: MyTableStruct := (
                ActLength:= 16(*number of bytes*), 
                MaxLength := 16(*number of bytes*), 
                ArrayOfElements := [1000,2000,3000,4000](*number multiplied with digits after decimal point*));
	bExecute: BOOL;
	strMasterName: STRING := 'ethercatmaster';
	fbECATSoeRead2: IL_ECATSoeRead;
	bExecuteRead: BOOL;
	rDiagnosis: IL_ST_SOE_STRING;
END_VAR

Implementation:

fbECATSoeWrite.Execute      := bExecute;
fbECATSoeWrite.MasterName   := ADR(strMasterName);
fbECATSoeWrite.SlaveAddress := 1001;
fbECATSoeWrite.Idn          := IL_ECATSOEIdnCoding(SOE_P_PARAM,0,397);
fbECATSoeWrite.ValueAdr     := ADR(WriteList);
fbECATSoeWrite.SizeOfValue  := WriteList.ActLength(*number of bytes that should be written*) + SIZEOF(WriteList.MaxLength) + SIZEOF(WriteList.ActLength);
fbECATSoeWrite();
IF TRUE = fbECATSoeWrite.Done THEN
  ; // FB finished .
END_IF
IF TRUE = fbECATSoeWrite.Error THEN
	fbECATSoeWrite.ErrorID;
	fbECATSoeWrite.ErrorIdent.Table;
	fbECATSoeWrite.ErrorIdent.Additional1;
	fbECATSoeWrite.ErrorIdent.Additional2;
  ; // Error handling
END_IF

 

alink
Long-established Member

Re: Writing value in element 0 of P-0-0397

Thanks a lot @CodeShepherd 👍

I don't know what's different between your writing style like

fbIL_ECATSoeWrite.Execute := bExecute;
fbIL_ECATSoeWrite.MasterName := ADR('ethercatmaster');
fbIL_ECATSoeWrite.SlaveAddress := 1004;

......

and using the function block from libary

fbIL_ECATSoeWrite(
 Execute:= TRUE,
 MasterName:= ADR('ethercatmaster'),
 SlaveAddress:= 1004,

......

but using your style works fine, using function block style don't. Maybe I am doing something wrong but it's strange.

For using with IndraDrive MPB17 it can look like that (writing P-0-0397 filter of signal time constant):

Structure:

TYPE TableStruct :
 STRUCT
  ActLength : UINT;
  MaxLength : UINT;
  ArrayOfElements : ARRAY[0..1] OF UDINT;
 END_STRUCT
END_TYPE

Declaration:

WriteList : TableStruct := (
ArrayOfElements := [40,30],
ActLength := 4,
MaxLength := 4);

Code: If HMI-input is changed by a user it will trigger writing on P-0-0397 element 0 (time constant for filter 1 / signal 1 (in my case signal 1 is S-0-0084 torque value)):

IF GVL_AXIS.iGlaettung[1] <> iGlaettungOld[1] THEN
 WriteList.ArrayOfElements[0] := (GVL_AXIS.iGlaettung[1]*10);

 fbIL_ECATSoeWrite.Execute := TRUE;
 fbIL_ECATSoeWrite.MasterName := ADR('ethercatmaster');
 fbIL_ECATSoeWrite.SlaveAddress := 1004;
 fbIL_ECATSoeWrite.Idn := IL_ECATSOEIdnCoding(SOE_P_PARAM,0,397);
 fbIL_ECATSoeWrite.ValueAdr := ADR(WriteList);
 fbIL_ECATSoeWrite.SizeOfValue := WriteList.ActLength + SIZEOF(WriteList.MaxLength) + SIZEOF(WriteList.ActLength);
 fbIL_ECATSoeWrite();
 IF fbIL_ECATSoeWrite.Done THEN
  bExecute := FALSE;
  fbIL_ECATSoeWrite.Execute := FALSE;
  fbIL_ECATSoeWrite();
  iGlaettungOld[1] := GVL_AXIS.iGlaettung[1];
 END_IF
 IF TRUE = fbIL_ECATSoeWrite.Error THEN
  bExecute := FALSE;
  fbIL_ECATSoeWrite.Execute := FALSE;
  fbIL_ECATSoeWrite();
  iGlaettungOld[1] := GVL_AXIS.iGlaettung[1];
 END_IF
END_IF

 

By the way, is this a special kind of coding?

IF TRUE = fbIL_ECATSoeWrite.Error THEN...

I don't know that style, I use always: IF fbIL_ECATSoeWrite.Error Then... or IF NOT fbIL_ECATSoeWrite.Error Then....

CodeShepherd
Community Moderator

Re: Writing value in element 0 of P-0-0397

There is no functional difference between directly adding variables to the input of the function block in the brackets of the or outside, like in my examples. It simply does the same.

Also the if loop does the same. It just looks different.

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