import revpimodio2 error
Moderator: RevPiModIO
-
- Posts: 12
- Joined: 24 Jul 2019, 13:16
Hi everyone,
I'm having a strange issue installing the revpimodio2 module. It seems to not be able to "find" it when running any code. I get the "import error: no module named revpimodio2" error. I have a Stretch image RevPi Connect, not a RevPi Core. is the library not compatible with this?
Thanks,
Ibrahim
I'm having a strange issue installing the revpimodio2 module. It seems to not be able to "find" it when running any code. I get the "import error: no module named revpimodio2" error. I have a Stretch image RevPi Connect, not a RevPi Core. is the library not compatible with this?
Thanks,
Ibrahim
- RevPiModIO
- KUNBUS
- Posts: 335
- Joined: 20 Jan 2017, 08:44
- Contact:
Hi Ibrahim!
The library will run on every Revolution Pi, RaspberryPi, Linux machine, Windows machine and so on
How did you install it? Kunbus has got it in the repositories, so you should do it by:
And after that use python3 NOT just python !!!
Regards, Sven
The library will run on every Revolution Pi, RaspberryPi, Linux machine, Windows machine and so on
How did you install it? Kunbus has got it in the repositories, so you should do it by:
Code: Select all
# Update catalog
sudo apt-get update
# Install module:
sudo apt-get install python3-revpimodio2
And after that use python3 NOT just python !!!
Regards, Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
-
- Posts: 12
- Joined: 24 Jul 2019, 13:16
Hi Sven,
Thank you for your help! I had neglected to change the Execute build command in Geany from Python to Python 3. It is now working! I have one more issue though. I seem to be getting a runtime error that looks like this:
I'm not entirely sure where I've made the mistake in my code.
Thanks!
Ibrahim
Thank you for your help! I had neglected to change the Execute build command in Geany from Python to Python 3. It is now working! I have one more issue though. I seem to be getting a runtime error that looks like this:
Code: Select all
ru/usr/lib/python3/dist-packages/revpimodio2/helper.py:539: RuntimeWarning: cycle time of 20 ms exceeded several times - can not hold cycle time!
RuntimeWarning
Thanks!
Ibrahim
-
- Posts: 12
- Joined: 24 Jul 2019, 13:16
Hi Sven,
I managed to get it to work by disabling the Autorefresh, although I know this is bad practice. I have another question regarding EtherCAT but I'll open that as a separate post. Thanks again for the help and all the work you've done with the RevPiModIO!
Ibrahim
I managed to get it to work by disabling the Autorefresh, although I know this is bad practice. I have another question regarding EtherCAT but I'll open that as a separate post. Thanks again for the help and all the work you've done with the RevPiModIO!
Ibrahim
Any Updates on the above mentioned RuntimeWarning warning message?
I get a similar notification on my RevPiCore from 2019 and i get a similar error:
Any suggestions on how to safely do this?
I get a similar notification on my RevPiCore from 2019 and i get a similar error:
Code: Select all
RuntimeWarning: can not execute all event functions in one cycle - optimize your event functions or rise .cycletime
Any suggestions on how to safely do this?
- RevPiModIO
- KUNBUS
- Posts: 335
- Joined: 20 Jan 2017, 08:44
- Contact:
Well, this is not a Bug. The update of RevPiModIO, which is implemented in 2.4.2, prevents the system from spam the messages. They will appear just one time.
The warning will appear, if a event function takes very long time and another event rises. Long run time of a function could happen with sleep calls or long loops.
This program will run without a warning. If you change state of I_1 to high, the function "test" will be executed and has a run time of about 1 second.
- after 1 second - no warning - Output: "I_1 True"
If you set I_1 to low AFTER 1 second, the function "test" will be executed again.
If you change the state of I_1 after 500 milliseconds to high again, the function "test" should be executed, but it is still running because of the sleep(1) call.
- warning will rise!
- after 500 milliseconds the output "I_1 False" appear
- after 1 second the output "I_1 True" will apper
You see, ALL event functions will be executed exact in the order of rising, but the mainloop will not execute them in parallel. The warning tells you, that there could come problems:
Imagine: If you switch state of I_1 10 times in a second, the mainloop will execute the "test" function 10 times, but this will take 10 seconds. So if you stop trigger the I_1, the program will output "I_1 True / False" 10 seconds after that...
Why should that be good???
Fist, you CAN execute event functions in parallel! You just have to add the "as_thread=True" to the .reg_event(...) function. Than all functions will be executed at the same time, doesn't matter of the run times.
This could be dangerous on controlling a plant! For example: Your function takes long time and set an output in the end. In the same time another event rises and like to switch off the same output. If this functions are running parallel, the output will be set on the end! So RevPiModIO just wants to warn you to write your code as fast as possible. And if you want long running functions you can use the "as_thread" argument.
I hope my explanation is okay and understandable
Sven
The warning will appear, if a event function takes very long time and another event rises. Long run time of a function could happen with sleep calls or long loops.
Code: Select all
import revpimodio2
import time
def test(name, value):
sleep(1)
print(name, value)
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.handlesignalend()
rpi.io.I_1.reg_event(test)
rpi.mainloop()
This program will run without a warning. If you change state of I_1 to high, the function "test" will be executed and has a run time of about 1 second.
- after 1 second - no warning - Output: "I_1 True"
If you set I_1 to low AFTER 1 second, the function "test" will be executed again.
If you change the state of I_1 after 500 milliseconds to high again, the function "test" should be executed, but it is still running because of the sleep(1) call.
- warning will rise!
- after 500 milliseconds the output "I_1 False" appear
- after 1 second the output "I_1 True" will apper
You see, ALL event functions will be executed exact in the order of rising, but the mainloop will not execute them in parallel. The warning tells you, that there could come problems:
Imagine: If you switch state of I_1 10 times in a second, the mainloop will execute the "test" function 10 times, but this will take 10 seconds. So if you stop trigger the I_1, the program will output "I_1 True / False" 10 seconds after that...
Why should that be good???
Fist, you CAN execute event functions in parallel! You just have to add the "as_thread=True" to the .reg_event(...) function. Than all functions will be executed at the same time, doesn't matter of the run times.
This could be dangerous on controlling a plant! For example: Your function takes long time and set an output in the end. In the same time another event rises and like to switch off the same output. If this functions are running parallel, the output will be set on the end! So RevPiModIO just wants to warn you to write your code as fast as possible. And if you want long running functions you can use the "as_thread" argument.
I hope my explanation is okay and understandable
Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
RevPiModIO wrote: ↑10 Jan 2020, 14:25 Well, this is not a Bug. The update of RevPiModIO, which is implemented in 2.4.2, prevents the system from spam the messages. They will appear just one time.
The warning will appear, if a event function takes very long time and another event rises. Long run time of a function could happen with sleep calls or long loops.
Code: Select all
import revpimodio2 import time def test(name, value): sleep(1) print(name, value) rpi = revpimodio2.RevPiModIO(autorefresh=True) rpi.handlesignalend() rpi.io.I_1.reg_event(test) rpi.mainloop()
This program will run without a warning. If you change state of I_1 to high, the function "test" will be executed and has a run time of about 1 second.
- after 1 second - no warning - Output: "I_1 True"
If you set I_1 to low AFTER 1 second, the function "test" will be executed again.
If you change the state of I_1 after 500 milliseconds to high again, the function "test" should be executed, but it is still running because of the sleep(1) call.
- warning will rise!
- after 500 milliseconds the output "I_1 False" appear
- after 1 second the output "I_1 True" will apper
You see, ALL event functions will be executed exact in the order of rising, but the mainloop will not execute them in parallel. The warning tells you, that there could come problems:
Imagine: If you switch state of I_1 10 times in a second, the mainloop will execute the "test" function 10 times, but this will take 10 seconds. So if you stop trigger the I_1, the program will output "I_1 True / False" 10 seconds after that...
Why should that be good???
Fist, you CAN execute event functions in parallel! You just have to add the "as_thread=True" to the .reg_event(...) function. Than all functions will be executed at the same time, doesn't matter of the run times.
This could be dangerous on controlling a plant! For example: Your function takes long time and set an output in the end. In the same time another event rises and like to switch off the same output. If this functions are running parallel, the output will be set on the end! So RevPiModIO just wants to warn you to write your code as fast as possible. And if you want long running functions you can use the "as_thread" argument.
I hope my explanation is okay and understandable
Sven
what impact does the cycletime have on the input and output manipulation
i tried setting the cycletime to different values,
the default value of 20 ms made the program spam the warning mentioned above
the value of 100 ms did not show any warning
however i can't change the value without knowing if it will impact the functionality of my code
i would like for you to explain in more details the usage of the cycletime
PS : i tried bypassing this warning by commenting it in the helper.py file would that have a negative effect the normal function of RevPi ?
- RevPiModIO
- KUNBUS
- Posts: 335
- Joined: 20 Jan 2017, 08:44
- Contact:
Generally speaking, the cycle time is the time at which the inputs and outputs are updated. IO changes are detected between these time intervals. If an IO change is within the cycle time (e.g. from true to false and back to true), this cannot be recognized.
As you can see, the cycle time should be set as short as possible. But the piBridge also has a cycle time and less than that (starting at 10 milliseconds) of course makes no sense.
The cycle time of 20 milliseconds is no problem for a Revoluton Pi Core-3 or Connect! The system monitors the cycle time to ensure that it can hold that.
----- cylce based -----
If you use the .cycleloop(...), your cycle function must also have been completed within this cycle time. Of course you can't work with .sleep etc.
----- event based -----
Even with .mainloop(), the event functions has to be as short as possible in runtime (for example send data through a slow Network is bad!). The system can only execute one event function at time and will put the others in a queue to execute them one by one. This ensures consistency in your program, because there can not be more functions, which manipulate IOs at the same time!
BUT: Sometimes you WANT to do slow things in this functions and want so let the event functions run in parallel (thread). Than you have to add the parameter as_thread to the .reg_event(..., as_thread=True) call. But be careful: Now the function is started by every event, regardless of whether it is already running. So if you don't implement some code to recognize whether the function is still running, an infinite number of these functions can be started. You are now really running in parallel.
As you can see, the cycle time should be set as short as possible. But the piBridge also has a cycle time and less than that (starting at 10 milliseconds) of course makes no sense.
The cycle time of 20 milliseconds is no problem for a Revoluton Pi Core-3 or Connect! The system monitors the cycle time to ensure that it can hold that.
----- cylce based -----
If you use the .cycleloop(...), your cycle function must also have been completed within this cycle time. Of course you can't work with .sleep etc.
----- event based -----
Even with .mainloop(), the event functions has to be as short as possible in runtime (for example send data through a slow Network is bad!). The system can only execute one event function at time and will put the others in a queue to execute them one by one. This ensures consistency in your program, because there can not be more functions, which manipulate IOs at the same time!
BUT: Sometimes you WANT to do slow things in this functions and want so let the event functions run in parallel (thread). Than you have to add the parameter as_thread to the .reg_event(..., as_thread=True) call. But be careful: Now the function is started by every event, regardless of whether it is already running. So if you don't implement some code to recognize whether the function is still running, an infinite number of these functions can be started. You are now really running in parallel.
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!