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.
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.
Back on the main menu under Pyscada Modbus Master/Client click add device.
Configure the new device as shown below.
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.
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.
Back on the main menu under Pyscada Modbus Master/Client click add variable and setup the two modbus variables.
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.
The two modbus reads are configured as shown below.
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.