Navigation:  Equipments (Devices) > PLC200 > Program > Communication Network > Modbus TCP >

MBTCP_WriteBinary

Escrita de BinĂ¡rios em rede Modbus TCP

Previous pageReturn to chapter overviewNext page

Block that performs a writing of up to 128 binary data (via Write Single Coil or Write Multiple Coils) in a server on the Modbus TCP network.

 

Ladder Representation

 

MBTCP_WRITEBINARY_block

 

Block Structure

 

Variable Type

Name

Data Type

Description

VAR_INPUT

Execute

BOOL

Block enabling

ServerAddress

DWORD

Server IP address

(Ex: 192.168.0.1)

ServerPort

WORD

Modbus TCP Port of the server

(Standard: 502)

UnitID

BYTE

UnitID do servidor

(Standard: 255)

Function#

BYTE

Writing function code

InitialDataAddress

WORD

Initial bit address where the data will be written

NumberOfData

BYTE

Number of bits to be written (1 to 128)

Timeout#

WORD

Maximum waiting time for the server response [ms]

Offset#

BOOL

Offset Indication in InitialDataAddress, i.e., need to subtract 1 from this number

Value

BOOL

Variable that stores the data to be written

VAR_OUTPUT

Done

BOOL

Output enabling

Active

BOOL

Awaiting response flag

Busy

BOOL

Flag indicating the connection is busy with another request

Error

BOOL

Error in the execution flag

ErrorID

BYTE

Identifier of the occurred error

VAR

MBTCP_WRITEBINARY

_INST_0

MBTCP_WRITEBINARY

Instance of access to block structure

 

Operation

 

When this block detects a leading edge on Execute, it checks whether the Modbus TCP server in specified address in ServerAddress is free to send data (Busy variable at FALSE level). If so, it sends the writing request of the Value values in a number of bits indicated by NumberOfData in InitialDataAddress address using chosen function in Function# and sets the Active output, resetting it when receiving the response from the server. If the server is not free, the block waits Busy go to FALSE level to resubmit the request.

 

wpshelp_common_fig_note

NOTE!

If Execute goes to FALSE level and Busy is still at TRUE level, the request is canceled.

 

wpshelp_common_fig_note

NOTE!

Value is an array of size equal to NumberOfData. It is important to check this compatibility not to generate errors in the block.

 

When Execute has FALSE value, Done remains FALSE. The Done output is only activated when the block finishes executing successfully, remaining at TRUE level until Execute receives FALSE.

 

If there is any error in the execution, the Error output is enabled and ErrorID displays an error code according to the table below.

 

Code

Description

0

Executed successfully

1

Invalid input data

2

Client not enabled

4

Timeout in server response

5

Server returned error

6

Failed to connect to server

7

TCP/IP connection terminated prematurely

 

Compatibility

 

Device

Version

PLC300

1.30 or higher

 

Block Flowchart

 

MBTCP_WRITEBINARY_flowchart

 

Example in Ladder

 

MBTCP_WRITEBINARY_example01

 

The example above requests written data contained in VALUE, with size described by DATA_COUNT, at addresses positioned from INIT on Modbus TCP server at SERVER:PORT address using the function Write Single Coil. The block ends successfully, Done output is activated.

 

Example in ST

 

 The example below displays the instructions for applying the example above in the ST language.

 

 

VAR

  SERVER : DWORD := 16#C0A8000A; // 192.168.0.10 = 3232235530

  PORT : WORD := 502;

  UNITID : BYTE := 255;

   INIT : WORD;

   DATA_COUNT : BYTE;

  VALUE : ARRAY [0..4] OF BOOL;  

   MBTCP_WRITEBINARY_INST_0 : FB_MBTCP_WriteBinary;

END_VAR

 

MBTCP_WRITEBINARY_INST_0.Execute := DI1;

MBTCP_WRITEBINARY_INST_0(

   ServerAddress:=SERVER,

   ServerPort:=PORT,

   UnitID:=UNITID,

   Function:=5,

   InitialDataAddress:=INIT,

   NumberOfData:=DATA_COUNT,

   Timeout:=50,

   Offset:=0,

   Value := VALUE);

DO1 := MBTCP_WRITEBINARY_INST_0.Done;