I have a program in structured text using twincat 3 that should read from and write to a modbus tcp server. However whenever i run the read or write functions i get the error 6. From what I have researched it is a ADS error Target Port not found but i could not find a way to fix it. Whenever i login I also get a warning message saying: Application 'Port_851' does not exist on device 'device name'. It gives an option to download and continue which i choose. I am currently not connected to a plc and just running the program on my laptop.
VAR
// Modbus TCP Read Coils
MBReadCoils : FB_MBReadCoils;
nReadValue : BYTE;
END_VAR
MBReadCoils(
sIPAddr:= 'localhost',
nTCPPort:= 502,
nUnitID:= 16#FF,
nQuantity:= 1,
nMBAddr:= 1,
cbLength:= SIZEOF(nReadValue),
pDestAddr:= ADR(nReadValue),
bExecute:= TRUE,
tTimeout:= ,
bBusy=> ,
bError=> ,
nErrId=> ,
cbRead=> );
MBReadCoils(bExecute := FALSE);
I have double checked the addresses and they are all correct. I have tried looking into the ADS server but cannot find anything concrete on anything pertaining to my error.
A couple things:
bExecute
bit on and off constantly, which is problematic because a Modbus read or write cycle will take considerably longer than one PLC scan. The recommended method is to trigger bExecute
, then wait for the bBusy
bit to deactivate before triggering bExecute
again. See Beckhoff's example code:
https://infosys.beckhoff.com/english.php?content=../content/1033/tf6250_tc3_modbus_tcp/192789899.html&id=