Makers Blog

Read and Write PLC Process Data with Python

Nils Hettig 05 October 2021 min. read
1,362 views 0 comments


This article describes how to access and write process data with Python utilizing the PyPlcnextRsc library. You can find the library’s documentation here. This page also provides examples for creating and handling complex data structures. If the described techniques do not meet your requirements, you are good to go to the man-page.


  1. The PLC must have internet access.
  2. Install the Python package manager pip if it is not on the PLCnext device yet. You can check it by logging into the PLC and type pip3, and hit enter. If pip is installed, some version information is displayed. Otherwise install pip:curl -o python3 alias pip='/opt/plcnext/.local/bin/pip'
  3. Install the required package: pip3 install -U PyPlcnextRsc

Read & Write Process Data

With the following example, we read process data:

# required imports
from PyPlcnextRsc import Device, RscVariant, RscType
from PyPlcnextRsc.Arp.Plc.Gds.Services import IDataAccessService, WriteItem

# we have to login using the standard credentials
# it is not recomended to store the login data in code
# the following example should only show how to interact with the process data
secureInfoSupplier = lambda:("admin","password")

# login to the device
device = Device('', secureInfoSupplier=secureInfoSupplier)

# service to access the process data
data_access_service = IDataAccessService(device)

# read one variable
read_item = data_access_service.ReadSingle("Arp.Plc.Eclr/test_in2")

# read multiple variables
read_items = data_access_service.Read(("Arp.Plc.Eclr/test_in1", "Arp.Plc.Eclr/test_in2", ))
read_item1 = read_items[0]
read_item2 = read_items[1]

# get the value of the read_item
value = read_item.Value.GetValue()
# get the data type of the read_item
value = read_item.Value.GetType()

Differences exist concerning the type of process data we want to access:

# Extern variable:
# Arp.Plc.Eclr/
read_item = data_access_service.ReadSingle("Arp.Plc.Eclr/test_in2")

# Local variable:
# Arp.Plc.Eclr/.
read_item = data_access_service.ReadSingle("Arp.Plc.Eclr/MainInstance.test_in2")

# Function block variable:
# Arp.Plc.Eclr/..
read_item = data_access_service.ReadSingle("Arp.Plc.Eclr/MainInstance.myFB.test_in2")

And last here is the code to write data:

# first create the variable containing the value and the data type
rscv = RscVariant(16,RscType.Int16)
# create a WriteItem with the destination process variable
wi = WriteItem("Arp.Plc.Eclr/MainInstance.test_in3", rscv)

# write single process variable

# write several process variables
data_access_service.Write((wi1, wi2,))

For the different data types, please visit the library’s documentation.


The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact.


Please login/register to comment
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users