An unexpected result

Moderator: RevPiModIO

Post Reply
yushengzhou
Posts: 7
Joined: 17 Oct 2018, 09:29
Answers: 0

An unexpected result

Post by yushengzhou »

Image Image


As shown in the figure above, I has written "code A" and "code B" ,I turned on two terminals and ran them separately.
as you see, I Change the potential of O_2 every five seconds in code A, and then read the potential of O_2 in code B,
Why do I always read False? Can you explain the reason to me?
User avatar
dirk
KUNBUS
Posts: 1926
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: An unexpected result

Post by dirk »

Hi, I have moved your post to the place where the specialists from RevPiModIO may help you.
User avatar
RevPiModIO
KUNBUS
Posts: 322
Joined: 20 Jan 2017, 08:44
Answers: 0
Contact:

Re: An unexpected result

Post by RevPiModIO »

I can not see the pictures unfortunately :( Maybe you can update them?

If you run two programs on the same process image (same device) with the same instantiation it will not work!

Why?

RevPiModIO runs, with normal instantiation, in the exclusive mode on the process image. Only at the start of the program, the current values of the outputs are synchronized. During runtime, RevPiModIO ensures that the values of the outputs set in the program are written to the process image! If a value of an output in the process image is change by another program, this change is overwritten immediately. This is the only way your control remains consistent!

If two programs are now started with RevPiModIO, both of them write their values for the outputs in the process image! If the value of O_2 is set to True in program A, it will be written to the process image, but will be overwritten by program B immediately, because in that program the value of O_2 IS false and that value MUST be written to the process image!

BUT!

If program A is to control the outputs and program B only monitors them, the monitoring parameter can be set to true.
https://revpimodio.org/en/doc2/

If RevPiModIO is instantiated in program B with monitoring=True (and optionally autorefresh=True), then the outputs in program B will also show the values that program A has set. But remember: you can not write to outputs in monitoring mode.

Code: Select all

rpi = revpimodio2.RevPiModIO(autorefresh=True, monitoring=True)
Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
yushengzhou
Posts: 7
Joined: 17 Oct 2018, 09:29
Answers: 0

Re: An unexpected result

Post by yushengzhou »

miprotek wrote: 23 Nov 2018, 11:57 I can not see the pictures unfortunately :( Maybe you can update them?

If you run two programs on the same process image (same device) with the same instantiation it will not work!

Why?

RevPiModIO runs, with normal instantiation, in the exclusive mode on the process image. Only at the start of the program, the current values of the outputs are synchronized. During runtime, RevPiModIO ensures that the values of the outputs set in the program are written to the process image! If a value of an output in the process image is change by another program, this change is overwritten immediately. This is the only way your control remains consistent!

If two programs are now started with RevPiModIO, both of them write their values for the outputs in the process image! If the value of O_2 is set to True in program A, it will be written to the process image, but will be overwritten by program B immediately, because in that program the value of O_2 IS false and that value MUST be written to the process image!

BUT!

If program A is to control the outputs and program B only monitors them, the monitoring parameter can be set to true.
https://revpimodio.org/en/doc2/

If RevPiModIO is instantiated in program B with monitoring=True (and optionally autorefresh=True), then the outputs in program B will also show the values that program A has set. But remember: you can not write to outputs in monitoring mode.

Code: Select all

rpi = revpimodio2.RevPiModIO(autorefresh=True, monitoring=True)
Sven
Thanks for you help miprotek! You may not be able to access the picture.My code looks like this:
code A:

Code: Select all

from time import sleep
import revpimodio2
revpi = revpimodio2.RevPiModIO(autorefresh=True)
while True:
	revpi.io.O_1.value = 1
	sleep(5)
	revpi.io.O_1.value = 0
	sleep(5)
	
code B:

Code: Select all

from time import sleep
import revpimodio2
revpi = revpimodio2.RevPiModIO(autorefresh=True)
while True:
	print(revpi.io.O_1.value)
	sleep(1)
Why is the execution of code B always False?
Post Reply