Hi Guys, I started last week playing with the AXC F 2152 controller and an AXL F BK ETH buscoupler (with 1 DI and 1 DO connected). At the moment I’ve got the communication up and running between the two and I can read the DI’s. Now I thought I was ready to control the DO’s but that was a bit of a failure. I used the example code which is included in the Modbus_TCP_6 library to get the DI’s up and running with FC4_3. For the DO’s I think I must use FC16_3 I programmed it and tried some things but I cant get it to work. I got an error with wDioCode = ‘16#C060’ and xAddDiagCode = ‘16#0004’ (“Slave device busy”). My code:
The code in block ‘Aansturen_MB_NDB2’: TON1(IN := xDelayStart, PT := tDelayTime, Q => xDelayReady, ET => tDelayE);
CASE iState OF
0: (* Wait for command *)
IF xStart = TRUE THEN
iState := 10;
END_IF;10: (* Init )
xWrite_NBD_Ready := FALSE;
xWrite_NBD_Busy := TRUE;
( Client *)
udtClient.xActivate := FALSE;
udtClient.xAutoAck := FALSE;
udtClient.strServer_IP := ‘192.168.0.12’;
udtClient.iPort := 502;
udtClient.xUDP_Mode := FALSE;
udtClient.tTimeout := TIME#10s;(* FC16 function block *)
udtMB_TCP_FC16.xActivate := FALSE;
udtMB_TCP_FC16.iMT_ID := 1;iState := 100;
100: (* Start *)
udtClient.xActivate := TRUE;
IF (udtClient.xActive = TRUE) THEN
iState := 1000;
END_IF;1000:
udtMB_TCP_FC16.xActivate := TRUE;
udtMB_TCP_FC16.uiQuantityOfRegisters := UINT#1;
udtMB_TCP_FC16.wStartRegister := WORD#9001;
IF (udtMB_TCP_FC16.xActive = TRUE) THEN
iState := 2000;
END_IF;2000:
IF udtMB_TCP_FC16.xError = FALSE THEN
udtMB_TCP_FC16.arrRegisterValue[1] := wNBD_DO2;
xDelayStart := TRUE;
IF xDelayReady = TRUE THEN // AND
xDelayStart := FALSE;
iState := 3000;
END_IF
END_IF3000:
udtClient.xActivate := FALSE;
udtMB_TCP_FC16.xActivate := FALSE;
IF (
udtMB_TCP_FC16.xActive = FALSE
AND udtClient.xActive = FALSE
) THEN
IF xStart = FALSE THEN
iState := 0;
xWrite_NBD_Ready := TRUE;
xWrite_NBD_Busy := FALSE;
END_IF;
END_IF;
END_CASE; // Is there perhaps a code viewer in this forum? I couldn’t find it.// The variable ‘wNBD_DO2’ is a 16 bit word which contains the values to control the outputs. Thanks for your help! If you need more information, please ask.