Hello,
I was following this video on YouTube on how to read the temperature using DS18B20 on Raspberry Pi.
I followed all the steps. However, when I run the code I get an error with pymodbus.
Here is the log when I start the PLC
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
PSM: Starting PSM...
Traceback (most recent call last):
File "/home/pi/Desktop/OpenPLC_v3/webserver/./core/psm/main.py", line 27, in <module>
import psm
File "/home/pi/Desktop/OpenPLC_v3/webserver/core/psm/psm.py", line 3, in <module>
from pymodbus.server.sync import ModbusTcpServer
ModuleNotFoundError: No module named 'pymodbus'
PSM: Error while starting Python interpreter
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
PSM: Connection to psm failed
PSM: Error connecting to psm!
PSM: PSM is disabled
Skipping configuration of Slave Devices (mbconfig.cfg file not found)
Warning: Persistent Storage file not found
I installed pymodbus by doing pip3 install pymodbus and I'm still having the same error.
Here is the PSM Code
import psm
import time
from w1thermsensor import W1ThermSensor
#global variables
sensor = None
def hardware_init():
#Insert your hardware initialization code in here
global sensor
psm.start()
sensor = W1ThermSensor()
def update_inputs():
#place here your code to update inputs
global sensor
temperature = sensor.get_temperature()
temp_int = int(temperature)
psm.set_var("IW0", temp_int)
def update_outputs():
#place here your code to work on outputs
pass
if __name__ == "__main__":
hardware_init()
while (not psm.should_quit()):
update_inputs()
update_outputs()
time.sleep(0.1) #You can adjust the psm cycle time here
psm.stop()
I would really appreciate it if someone could help me with this.
thank you.