Hits: 20544

As I think a lot of people involved into the automation world  know , Siemens always shown a kind of "adversity" to equip its products with not-native Siemens protocols. One of these, born on far 1979 but still common, is the Modbus protocol for networks TCP/IP. Anyway, available from few years, Siemens release its on licensed-library in order to use Modbus TCP communication into the PN type CPU (300, 400, 400H), into the CP (343, 443) or into the CPU-PN equipped ET200S. Recently I had the possibility to test this library developing an application (S7-317 2PN/DP)  who needs to run as Modbus Master (Client) reading / writings data to some relay controller (Areva) in order to control an hydroelectric power plant. Then I though to wrote this tutorial as a memo for some future similar jobs. Wish it'll be useful you too.

Into this article I'll explain hot to implement to modbus TCP Client (Master) functionality into a CPU S7-315 2PN/DP firmware 3.2. Here follow hardware and software needed coponents:






Parameter    In/Out     Type      Description    Value range 
ID IN WORD    Connection-ID, must be identical to the associated parameter in the local connection description    1 to 4095    yes  
DB_PARAM IN BLOCK_DB    Number of the parameter DB     
RECV_TIME IN TIME    Monitoring Time: Wait for data from communication partner
Shortest adjustable time is 20 ms
CONN_TIME IN TIME    Monitoring Time: Wait for establishing or termination of the connection
Shortest adjustable time is 100 ms
KEEP_ALIVE IN TIME     Not used  
ENQ_REQ IN BOOL CP is Client: Initiate request at positive edge
CP is Server: Ready to receive at TRUE signal
 DISCONNECT IN  BOOL S7 is Client: TRUE: the connection will be terminated after reception of the response
S7 is Server: TRUE: the connection will be terminated when ENQ_ENR = FALSE
 REG_KEY  IN  STRING[17]    Registration key  to activate the license     
 LICENSED  IN  BOOL License state of the function block
Block is licensed
Block is not licensed



 BUSY     OUT BOOL  Operating state of the T-functions (TCON, TDISCON, TSEND or TRCV)
Job processing
No job processing active




Connection established

Connection end


 DONE_NDR      OUT  BOOL CP is Client: TRUE: Active request finished without errors
CP is Server: TRUE: Request from the client was executed and answered

An error has occurred (TRUE)
No error has occurred (FALSE)



 STATUS_MODBUS   OUT  WORD  Error number for protocol errors when evaluating a Modbus telegram (if >0)  
 STATUS_CONN  OUT  STRING[8] Error number for connection errors during execution of the T-blocks (TCON, TSEND,TRCV, DISON),.. (if >0)  
UNIT    IN/OUT BYTE Unit identification (INPUT if in CLIENT mode, OUTPUT if in SERVER mode)  0 to 255
DATA_TYPE    IN/OUT BYTE Data type to be accessed (INPUT if inCLIENT mode, OUTPUT if in SERVER mode)


2=Input Status

3=Holding register

4=Input register

 START_ ADDRESs  IN/OUT  WORD MODBUS start address (INPUT if in CLIENT mode, OUTPUT if in SERVER mode)  0 to 65535
 LENGTH  IN/OUT  WORD Number of registers to be processed (INPUT if in CLIENT mode, OUTPUT if in SERVER mode)

1..2000 Coil Read

1..1968 Write Coil

1..2000 Read Input Status

1..125 Read Holding Register

1..123 Write Holding Register

1..125 Read Input Register

  TI  IN/OUT  WORD  Transaction Identifier (INPUT if in CLIENT mode, OUTPUT if in SERVER mode) . This value MUST be increase for each new ENS_REQ  

 TRUE= write

FALSE= only read