3

I'm trying to have a modbus RTU client on my Raspberry Pi 4 talking to the modbus synchronous server available in the pymodbus examples (https://pymodbus.readthedocs.io/en/latest/source/example/synchronous_client.html). I set up the server like this:

# RTU:
    StartSerialServer(context, framer=ModbusRtuFramer, identity=identity,
                      port='/dev/ttyAMA0', timeout=.5, baudrate=9600)

What my client does:

from pymodbus.pdu import ModbusRequest
from pymodbus.client.sync import ModbusSerialClient
from pymodbus.transaction import ModbusRtuFramer
import time
import logging

### Logs
FORMAT = ('%(asctime)-15s %(threadName)-15s '
      '%(levelname)-8s %(module)-15s:%(lineno)-8s % 
(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)

### Modbus RTU stuff
client = ModbusSerialClient(method='rtu', port='/dev/ttyAMA0', baudrate=9600, timeout=.5, parity='N')
client.connect()
client.write_registers(1, 1, unit=1)
client.close()

What I see in server console:

    2020-03-24 00:08:14,189 MainThread      DEBUG    sync           :46       Client Connected [/dev/ttyAMA0:/dev/ttyAMA0]
    2020-03-24 00:08:14,190 MainThread      DEBUG    sync           :580      Started thread to serve client

Client logs:

   2020-03-24 00:09:53,937 MainThread      DEBUG    transaction    :115      Current transaction state - IDLE
   2020-03-24 00:09:53,938 MainThread      DEBUG    transaction    :120      Running transaction 1
   2020-03-24 00:09:53,939 MainThread      DEBUG    transaction    :219      SEND: 0x1 0x10 0x0 0x1 0x0 0x1 0x2 0x0 0x1 0x66 0x41
   2020-03-24 00:09:53,939 MainThread      DEBUG    sync           :75       New Transaction state 'SENDING'
   2020-03-24 00:09:53,940 MainThread      DEBUG    transaction    :238      Transaction failed. ([Errno 25] Inappropriate ioctl for device) 
   2020-03-24 00:09:53,941 MainThread      DEBUG    rtu_framer     :235      Frame - [b''] not ready
   2020-03-24 00:09:53,941 MainThread      DEBUG    transaction    :394      Getting transaction 1
   2020-03-24 00:09:53,942 MainThread      DEBUG    transaction    :193      Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'

I'm really confused by the error message:

[Errno 25] Inappropriate ioctl for device

Up to that point the logs show what I expected (It looks like I can connect and the SEND stuff is correct), but I can't understand what's going on with that error message. On the server side nothing happens in the terminal window. I made sure that with

sudo raspi-config

to disable shell and kernel from the serial connection.

Any idea about what the issue could be? Ty

Federico
  • 43
  • 7

0 Answers0