Pyscada on Raspberry PI for Modbus RTU

Following on from my Pyscada 1-Wire posts this article covers the configuration of Pyscada for the purpose of reading, displaying and writing Modbus RTU data using a raspberry pi and a usb to RS485 interface. This article assumes the installation has been completed along the lines of PyScada on Raspberry PI for temperature monitoring with DS18B20 on 1-Wire – Part 1 – Software Installation. This article will describe the configuration and reading of the first data bit and word to demonstrate the starting point of a larger project. Once these first variables have been setup, my previous post on HMI components may be useful PyScada on Raspberry PI for temperature monitoring with DS18B20 on 1-Wire – Part 4 – PyScada HMI Configuration.

 

Hardware Arrangement

A Usb to Serial RS485 adapter has been connected between a Raspberry PI and a Schneider Electric Twido PLC. After connecting the USB to Serial adapter the linux address device can be located using the terminal commands.

cd /dev/
ls

The result of these commands is to list the devices, my USB to Serial adapter identifies as /dev/ttyUSB0. We will need this address later for the Pyscada Configuration.

We now need look at the permissions of the /dev/ttyUSB0 device in detail, a serial device when connected is only setup for access by the dialout group.

cd /dev/
ls -l

This will give results that look something like this.

crw-rw—- 1 root dialout 188, 0 Jan 21 11:48 ttyUSB0

To add our pyscada user to this group run

sudo adduser pyscada dialout

 

Pyscada Modbus RTU Device Configuration

From the admin menu in the pyscada core section click add device and configure it as shown below.

2-Add Device

Back on the main menu under Pyscada Modbus Master/Client click add device.

2a-modbus menu

Configure the new device as shown below.

3-Set Modbus Device.PNG

The screenshot above shows my configuration, the content in the red box defines the serial device location, in this case we are using the local host ip address (i am unsure if this is actually used by the modbus RTU device but the form will not accept a blank ip address) and the port is defined as the path to the serial device as identified in the section above.

The unit number in the orange box is the modbus slave address of the remote device and the section in the green box defines our modbus network settings. In my case these have been setup to match the PLC configuration shown below.

3a-Modbus Twido

Pyscada Modbus RTU Variables

As with the 1-wire interface in the previous posts we first need to create generic pyscada core variables and connect them to modbus variables.

We will create two variables in this example, a word and a bit, both of which will be configured to be writable.

From the administration menu add two new variables configured as follows.

4-Var-MW

and

4-Var-M

Back on the main menu under Pyscada Modbus Master/Client click add variable and setup the two modbus variables.

2a-modbus menu

The memory table from the PLC is shown below. The day of the week MW is at register 0 of the word table and the sequencemode bit is at coil 2.

5-Modbus Variable MW5-Modbus Variable M

The two modbus reads are configured as shown below.

5-Set Modbus Variable MW

5-Set Modbus Variable M

The device reads are now complete, in the event that the HMI performs a write function pyscada handles internally the change of read holding registers to a write holding registers etc.

From here my previous post on configuring HMI elements and creating displays can be used to create pages that will work with the modbus data source. PyScada on Raspberry PI for temperature monitoring with DS18B20 on 1-Wire – Part 4 – PyScada HMI Configuration.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s