problem using revpimodio2 in separate threads

Topics about the Software of Revolution Pi
Post Reply
sofiene
Posts: 23
Joined: 24 Dec 2019, 15:36

problem using revpimodio2 in separate threads

Post by sofiene »

i have a problem with using revpimodio2 library in multiple python codes in parallel
the output signal is not stable
i have made this simple test using the script bellow in two seperate files triggerring O_1 and O_2 in parallel
and reading the inputs wired to them I_1 and I_2 respectively and i attatched a led to O_1
and the result is that the led starts to blink when it's supposed to stay high (for 5 seconds ) and the Input that i'm reading is showing unexpected results

Code: Select all

import revpimodio2
import time
revpi = revpimodio2.RevPiModIO(autorefresh=True)


revpi.mainloop(blocking=False)

revpi.io.O_1.value=(False)
while True:

    revpi.io.O_1.value=(True)
    time.sleep(0.1)
    print (revpi.io.I_1.value)
    time.sleep(5)
    revpi.io.O_1.value=(False)
    time.sleep(0.1)
    print (revpi.io.I_1.value)
    time.sleep(5)
User avatar
nicolaiB
KUNBUS
Posts: 931
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: problem using revpimodio2 in separate threads

Post by nicolaiB »

If you want to share the process image among different programs you have to set the 'direct_output' flag to true. For more details have a look into the documentation: https://revpimodio.org/en/doc2/

A better way would be ihmo to run a master with an shared instance of your revpimodio object. So it would be possible for the threads to access the IOs.

Nicolai
Post Reply