Modbus RTU & RevPi DIO manage in Python script

Show the world your Revolution Pi project!
Post Reply
Theo
Posts: 8
Joined: 19 Feb 2020, 17:27
Answers: 0

Modbus RTU & RevPi DIO manage in Python script

Post by Theo »

I'm a new user on the RevPI Forum.

I bought a RevPi connect+ and a RevPi DIO module. I would like to control my devices with a Python script.

Would it be possible to receive some examples of python programs: to control an actuator in modbus RTU ( write and read coil & write and read registers with some values) and to control I/O with the DIO module?

Thanks in advance
Theo
Online
User avatar
dirk
KUNBUS
Posts: 1924
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: Modbus RTU & RevPi DIO manage in Python script

Post by dirk »

Hi Theo, have a look at the RevPiModIO Python library. It makes it easy to access to the process image of the RevPi
Bit Mirror example
https://revolution.kunbus.de/forum/view ... rror#p6250
Documentation of the library
https://revolution.kunbus.de/forum/view ... 1026#p4198
Theo
Posts: 8
Joined: 19 Feb 2020, 17:27
Answers: 0

Re: Modbus RTU & RevPi DIO manage in Python script

Post by Theo »

Hi Dirk, thanks for the reply and sorry for the delay.

I would like to retrieve information from a sensor with my RevPi connect and DIO module. I try to use the library RevPiModio2 but it doesn't work..
My DIO module is correctly configured, I check with the piTest -d

When I tried to swich on the LED on the Connect device, it doesn't work also. So; I am not sure how to use this library.. can you help me please?

My code :
import revpimodio2
import time

rpi = revpimodio2.RevPiModIO(autorefresh=True)

rpi.Connect.A3 = revpimodio2.GREEN

Error :
Traceback (most recent call last):
File "DIO.py", line 6, in <module>
rpi.Connect.A3 = revpimodio2.GREEN
AttributeError: 'RevPiModIO' object has no attribute 'Connect'


Image[/img][/img][/img]
Attachments
Capture.PNG
Capture.PNG (239.76 KiB) Viewed 7207 times
User avatar
nicolaiB
KUNBUS
Posts: 869
Joined: 21 Jun 2018, 10:33
Answers: 7
Location: Berlin
Contact:

Re: Modbus RTU & RevPi DIO manage in Python script

Post by nicolaiB »

Hi Theo,

the correct io would be

Code: Select all

rpi.core.a3
For more details have a look into the documentation of revpimodio2: https://revpimodio.org/en/doc2/core/

Nicolai
Theo
Posts: 8
Joined: 19 Feb 2020, 17:27
Answers: 0

Re: Modbus RTU & RevPi DIO manage in Python script

Post by Theo »

Hi Nicolai! Thanks for your answer.
I will try that.
For you, what is the best to control my DIO module and to monitor the status of my inputs and outputs instantly? The RevPiLoad?
User avatar
nicolaiB
KUNBUS
Posts: 869
Joined: 21 Jun 2018, 10:33
Answers: 7
Location: Berlin
Contact:

Re: Modbus RTU & RevPi DIO manage in Python script

Post by nicolaiB »

Yes, RevPiLoad might be a good starting point. With the GUI it's possible to control the outputs and also upload a custom program which is written with revpimodio2. There are some cool examples on the website.

Nicolai
Theo
Posts: 8
Joined: 19 Feb 2020, 17:27
Answers: 0

Re: Modbus RTU & RevPi DIO manage in Python script

Post by Theo »

Thank you! I try your recommandation but the LED doesn't light up

Code: Select all

import revpimodio2
import time

rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.core.A3 = revpimodio2.GREEN
Then, I would like to read the status of my Input 1 without activate the Output 1. I read the examples on the website revpimodio with the mirror but I don't need that. Can you show me a little example to read the values of my input please ?
Post Reply