I'm trying to establish basic comms between Raspberry Pi 4 Model B and PID-controller using RS485 Serial HAT hardware.
The PID-controller "Serial communication standard is RS485 (isolated) with Modbus RTU Master/Slave protocol."
Pi 4 now has virtual environment containing minimalmodbus install and I'm using Thonny.
DIP switches on the hat are set to 'automatic send/receive control, multipoint master,' terminating resistor on. (I haven't experimented with setting switches to 'send/receive control via GPIO18 yet).
PID-controller = ATR144
Raspberry Pi 4 Model B
Debian GNU/Linux 12 (bookworm)
ZIHATEC RS422 / RS485 Serial HAT
As you'll see from the code and shell below, I've incorrectly specified the port name and slave address. Unfortunately, I don't know what this should be when connecting via 485 using hat. Would appreciate any pointers.
shell reports following:
____________________________________________
default comms settings for the ATR144 are:
modbus slave: enabled
slave address: 247
baud: 19,200 bit/s
serial port format: 8 bit, no parity, 1 stop bit
serial delay: 5mS
The PID-controller "Serial communication standard is RS485 (isolated) with Modbus RTU Master/Slave protocol."
Pi 4 now has virtual environment containing minimalmodbus install and I'm using Thonny.
DIP switches on the hat are set to 'automatic send/receive control, multipoint master,' terminating resistor on. (I haven't experimented with setting switches to 'send/receive control via GPIO18 yet).
PID-controller = ATR144
Raspberry Pi 4 Model B
Debian GNU/Linux 12 (bookworm)
ZIHATEC RS422 / RS485 Serial HAT
As you'll see from the code and shell below, I've incorrectly specified the port name and slave address. Unfortunately, I don't know what this should be when connecting via 485 using hat. Would appreciate any pointers.
Code:
import minimalmodbusinstrument = minimalmodbus.Instrument('/dev/ttyUSB1', 1) # port name, slave address (in decimal)## Read temperature (PV = ProcessValue) ##temperature = instrument.read_register(0, 1) # Registernumber, number of decimalsprint(temperature)## Change temperature setpoint (SP) ##NEW_TEMPERATURE = 95instrument.write_register(24, NEW_TEMPERATURE, 1) # Registernumber, value, number of decimals for storage
Code:
>>> %Run minmodbus01.pyTraceback (most recent call last): File "/home/aga/thonny_venv/lib/python3.11/site-packages/serial/serialposix.py", line 322, in open self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)FileNotFoundError: [Errno 2] No such file or directory: '/dev/ttyUSB1'During handling of the above exception, another exception occurred:Traceback (most recent call last): File "/home/aga/Desktop/minmodbus01.py", line 3, in <module> instrument = minimalmodbus.Instrument('/dev/ttyUSB1', 1) # port name, slave address (in decimal) File "/home/aga/thonny_venv/lib/python3.11/site-packages/minimalmodbus.py", line 225, in __init__ self.serial = _serialports[port] = serial.Serial( File "/home/aga/thonny_venv/lib/python3.11/site-packages/serial/serialutil.py", line 244, in __init__ self.open() File "/home/aga/thonny_venv/lib/python3.11/site-packages/serial/serialposix.py", line 325, in open raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyUSB1: [Errno 2] No such file or directory: '/dev/ttyUSB1'>>>
default comms settings for the ATR144 are:
modbus slave: enabled
slave address: 247
baud: 19,200 bit/s
serial port format: 8 bit, no parity, 1 stop bit
serial delay: 5mS
Statistics: Posted by agalout — Sat Apr 06, 2024 1:03 pm