Using the Siemens LCom Library for TCP Communication on S7 PLCs

Using the Siemens LCom Library for TCP Communication on S7 PLCs

In a recent project, we needed to set up communication between a PC running LabView and a Siemens S7-1500 PLC. Thankfully, Siemens provides the LCom communications library, shown below, for setting up TCP communications on SIMATIC S7-300/400, SIMATIC S7-1200/1500, and SIMOTION SCOUT devices.

TCP is a handy method of establishing non-critical communications between two Ethernet capable devices. The LCom library provides a convenient interface to implement TCP communications in your project.

In this post, we will look at the implementation of the LCom library on a Siemens S7-1516 PLC.

Figure 1: LCom Block in TIA Portal V15
Figure 1: LCom Block in TIA Portal V15

Set Up

Siemens provides a guide on using global libraries, but here is a shortened tutorial:

  1. Download the Communication Library LCom for Ethernet Communication from Siemens' website and unzip the ZAL file using 7-Zip.
  2. Open the global library by choosing the circled option shown in Figure 2 and navigating to your local copy of the LCom library.

    Figure 2: Open LCom library
    Figure 2: Open LCom library
  3. Drag a copy of LCom_Communication, LCom_Constants, typeLCom_Config, and typeLCom_Diagnostics to the project tree (Figure 3) to add them to your local project.

    Figure 3: Copy library objects to local project
    Figure 3: Copy library objects to the local project


Set configuration parameters in the dbComms data block (Figure 4), which is used to store information for the LCom block.

Figure 4: dbCommsFigure 4: dbComms

The most important configuration parameters for a quick setup are as follows:

iSendDataLength: Specify the length (in bytes) of the data to be sent.

iReadDataLength: Specify the length (in bytes) of the data to be received.

cycleTime: Specify the cyclic transmission time, if applicable

partnerIP: Specify the IP address of the recipient device.

IsServer: Specify whether or not the device is the server.

ConnectionID: If you're application is communicating with multiple devices at different IP addresses, make sure each instance of the LCOM block has a unique connection ID.


Shown in Figure 5, we created another data block to contain the send and receive data from the LCom block.

Figure 5: Send/receive dataFigure 5: Send/receive data

Enable the LCom block in our application by setting dbComms.bEnable to 1, and start sending data by setting dbComms.bSend to 1. 

This is useful if you only want to send data at specific times. Otherwise, set both bits to 1 to send data cyclically.


We have used this technology to communicate between two Siemens PLCs and an S7-1500 and a LabView PLC. However, this block can be used to transmit data between a Siemens PLC and any device which accepts the TCP protocol by setting the correct IP address and cycle time.

Learn more about DMC's Siemens S7 PLC Programming services. Or, contact us to get started on a project today.


There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

Enter the code shown above:

Related Blog Posts