Hiii!
I would like to say first of all, that I am a beginner in this topic, so it is probably easy to solve this problem, but I am not succeeding on my own.
I'm building a control system using some sensors and actuators combined with some of your modules: CORE Connect 4, AIO and DO.
I can read most of the sensors or actuators using this command in Python (and using the names assigned in PicTory):
rpi.io["LHEpump"].value [1]
To be able to do this I'm using this library and this initialization and also the cleanup line:
import revpimodio2
def main():
rpi=revpimodio2.RevPiModIO(autorefresh=True, monitoring=False, syncoutputs=True, debug=True, replace_io_file=None, shared_procimg=False)
output_1 = rpi.io["TWV_1"].value
# Print the values before changing
print(f"The value of input TWV_1 bc is: {output_1}")
# Change the value
rpi.io["TWV_1"].value=0
output_2 = rpi.io["TWV_1"].value
rpi.cleanup()
# Print the new value
print(f"The value of output TWV_1 ac is: {output_2}")
if __name__ == "__main__":
main()
But it doesn't work if the variable is one of the RTU Master, in this case it allows me to store and print the value but not to write output.
I attach a picture of how they have been declared and the code that I'm trying to run and the output that I get.
The output variable change the value, but it doesn't take effect and when I read again, the value is the initial one.
The photos of the configuration and the rest will be in this link: https://photos.app.goo.gl/umd8Zj3XXQ1sEfKE7
The code that doesn't work is this one:
import revpimodio2
def main():
# Initialize the RevPiModIO object
rpi = revpimodio2.RevPiModIO(
autorefresh=True,
monitoring=False,
syncoutputs=True,
debug=True,
replace_io_file=None,
shared_procimg=False
)
# Get the initial value of the input
input_value = rpi.io["min_SPEED_cond_HP_i"].value
output_value = rpi.io["min_SPEED_cond_HP_o"].value
print(f"The initial value of min_SPEED_cond_HP_i is: {input_value}")
print(f"The initial value of min_SPEED_cond_HP_o is: {output_value}")
# Set the value of the output register
rpi.io.min_SPEED_cond_HP_o.value = 7000
print(f"Set min_SPEED_cond_HP_o to: {7000}")
# Write the process image to ensure the new value is set
rpi.writeprocimg()
# Refresh the process image again to get the updated value
rpi.readprocimg()
# Get the updated value of the input
updated_input_value = rpi.io["min_SPEED_cond_HP_i"].value
updated_output_value = rpi.io["min_SPEED_cond_HP_o"].value
# Clean up
rpi.cleanup()
print(f"The updated value of min_SPEED_cond_HP_i is: {updated_input_value}")
print(f"The updated value of min_SPEED_cond_HP_o is: {updated_output_value}")
if __name__ == "__main__":
main()
And the output:
pi@RevPi114725:~/Documents $ /bin/python /home/pi/Documents/test_read_variable_modbus.py
The initial value of min_SPEED_cond_HP_i is: 8000
The initial value of min_SPEED_cond_HP_o is: 7000
Set min_SPEED_cond_HP_o to: 7000
The updated value of min_SPEED_cond_HP_i is: 8000
The updated value of min_SPEED_cond_HP_o is: 7000
Could someone help me to understand what is wrong?
Thank you very much in advance, I really appreciate the help.
Write outputs Modbus Master RTU
Re: Write outputs Modbus Master RTU
Hello, zairalm thank you very much for your detailed report and the details. Can you send me an SOS report?
https://kunbus-gmbh.atlassian.net/servi ... 2036400208
https://kunbus-gmbh.atlassian.net/servi ... 2036400208