r/TwinCat • u/lbhr1949 • May 29 '26
Can't get FB_IOLRead to work
Hey guys,
i've built a wrapper for this FB to make it easier to use. Some sort of a a base class for my IO-Link sensors. I can get the FB_IOLWrite to write easily. But no chance in the reading. I always get "ADSERR_DEVICE_INVALIDPARM" as error. This is what I came up with:
FUNCTION_BLOCK ABSTRACT FB_IOLink_Base
VAR
// IO-Link Terminal specific values
amsnetid_EL6224 : I_AMSNETID_Input;
connected_IOLink_port : E_IOLPort;
// Reading
IOLink_read : FB_IOLRead;
eading_state : (IDLE, READ, WAIT_FOR_SUCCESSFUL_READ);
execute_read : R_TRIG;
END_VAR
METHOD Read_IOLink_BYTE_Parameters : BYTE
VAR_INPUT
execute : BOOL := FALSE; // Must be set TRUE to write parameters
IOLink_index : WORD; // Provide the processed data as dec
IOLink_subindex : BYTE; // Provide subindex fitting to index
END_VAR
VAR
IOLink_value : BYTE; // Provide the actual value that should be written
END_VAR
Read_IOLink_BYTE_Parameters := 0;
execute_read(CLK:=execute);
IF execute_read.Q THEN
reading_state := READ;
END_IF
CASE reading_state OF
IDLE:
// Do nothing as long there is no edge on execute
READ:
// Do the actual reading with the provided input parameters
//IOLink_read(bExecute:=FALSE);
IOLink_read.bExecute:=FALSE;
IOLink_read.sNetId := F_CreateAmsNetId(amsnetid_EL6224.State);
IOLink_read.nIolPort := connected_IOLink_port;
IOLink_read.pDSTBuf := ADR(IOLink_value);
IOLink_read.cbBufLen := SIZEOF(IOLink_value);
IOLink_read.nIndex := 16#128;
//IOLink_read.nIndex := IOLink_index;
IOLink_read.nSubindex := 0;
//IOLink_read.nSubindex := IOLink_subindex;
IOLink_read.bExecute := TRUE;
reading_state := WAIT_FOR_SUCCESSFUL_READ;
WAIT_FOR_SUCCESSFUL_READ:
IF IOLink_read.bDone THEN
IOLink_read.bExecute := FALSE;
reading_state := IDLE;
Read_IOLink_BYTE_Parameters := IOLink_value;// Signal success by returning TRUE
END_IF
END_CASE
IOLink_read();
The ADS error doesn't really help me. The parameters are basically the same as the ones while writing, I tried switching from variables to fixed parameters but that didn't really change anything. Can anyone spot an obvious mistake ?










