I am trying to create a simple Hello World
Modbus TCP/IP program using Twincat3 and virtual PLC (PLC running locally on my computer).
What I have tried:
ipAddr
parameter to: 'localhost', '192.168.88.1', '192.168.88.126'
nUnitID
set to: 0, 1, 16#FF
(16#FF
as specified by Beckhoff docs)This is my Beckhoff code:
PROGRAM MAIN
VAR
ipAddr : STRING(15) := '192.168.88.1'; //Tried also 192.168.88.126 and 192.168.88.1 'localhost'
M0 AT %MB0 : ARRAY [0..3] OF WORD;
nValue : ARRAY [0..3] OF WORD;
fbWriteRegs : FB_MBWriteRegs;
bWriteRegs : BOOL;
END_VAR
IF NOT bWriteRegs THEN
nValue[0] := nValue[0]+1;
nValue[1] := nValue[1]+1;
nValue[2] := nValue[2]+1;
nValue[3] := nValue[3]+1;
bWriteRegs := TRUE;
fbWriteRegs.sIPAddr := ipAddr;
fbWriteRegs.nTCPPort := 502;
fbWriteRegs.nUnitID := 16#FF; //Tried setting this to 0,1 and it also and didnt work ...
fbWriteRegs.nQuantity := 4;
fbWriteRegs.nMBAddr := 16#3000; //Tried: 16#3000, 0, 1
fbWriteRegs.cbLength := SIZEOF(nValue);
fbWriteRegs.pSrcAddr := ADR(nValue);
fbWriteRegs.tTimeout := T#5S;
fbWriteRegs (bExecute:=TRUE);
ELSE
IF NOT fbWriteRegs.bBUSY THEN
bWriteRegs :=FALSE;
fbWriteRegs (bExecute:=FALSE);
END_IF
fbWriteRegs (bExecute:=FALSE);
END_IF
Info about LabVIEW programs:
'localhost'
and the port to 502
(which should match the IP address in my Beckhoff code)Picture of my LabVIEW programs:
By virtual PLC
I mean this target PLC:
You didn't mention that you have installed TF6250, which is necessary. You need to install TF6250 on the PLC: