Samples 8 Samples 8.1 Sample: Digital IO Access This sample explains the access to a TwinCAT system via Modbus. The default mapping [ } 14] of the TwinCAT Modbus TCP mapps the digital output (coils) to the physical outputs of the PLC. PROGRAM MAIN VAR Q00 AT%QX0.0 : BOOL; Q01 AT%QX0.1 : BOOL; Q02 AT%QX0.2 : BOOL; Q03 AT%QX0.3 : BOOL; Q04 AT%QX0.4 : BOOL; Q05 AT%QX0.5 : BOOL; Q06 AT%QX0.6 : BOOL; Q07 AT%QX0.7 : BOOL; fbWriteCoils : FB_MBWriteCoils; bWrite : BOOL; nValue :
INT; END_VAR IF NOT bWrite THEN nValue := nValue + 1; bWrite := TRUE; fbWriteCoils.nQuantity := 8; fbWriteCoils.cbLength := SIZEOF(nValue); fbWriteCoils.pSrcAddr := ADR(nValue); fbWriteCoils.tTimeout := T#5s; fbWriteCoils(bExecute:=TRUE); ELSE IF NOT fbWriteCoils.bBUSY THEN bWrite :=FALSE; END_IF fbWriteCoils(bExecute:=FALSE); END_IF The counter nValue will be written to physical outputs of the plc (Q00-Q07) by a rising edge of bWrite. The bit ordering is explained in this table: MSB = Most significant bit LSB = Least significant bit https://infosys.beckhoff.com/content/1033/tcmodbussrv/Resources/11379454731/.zip 8.2 Sample:
Multiple register access This sample explains the access to the register of aTwinCAT system via Modbus. The Modbusaddress 0x3000 is mapped by the default-configuration to the memory area of the plc (ADS- Indexgroup 0x4020) PROGRAM MAIN VAR ipAddr : STRING(15) := ''; TS6250 51 Version: 1.2 Bit 8 MSB 7 6 5 4 3 2 1 LSB Output 7 6 5 4 3 2 1 0