0

I have raspberry pi 3 B+ running latest raspbian-strech lite. i have a max485 ic connected to uart on the gpio.

import serial,fcntl, struct

ser = serial.Serial(
    port='/dev/serial0', 
    baudrate=9600, 
    timeout=1,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS
)  

fd=ser.fileno()
serial_rs485 = struct.pack('hhhhhhhh', 1, 0, 0, 0, 0, 0, 0, 0)
fcntl.ioctl(fd,0x542F,serial_rs485)


ser.write("A")      # Send a "A" char to the serial port
s = ser.read(1)         # Wait for a char
print s
ser.close()

i get the following error.

File "t1.py", line 15, in <module>
   fcntl.ioctl(fd,0x542F,serial_rs485)
IOError: [Errno 25] Inappropiate ioctl for device

I have tried searching the error but none seem to match what im doing.

  • It is unclear what you actually have but /dev/ttyS2 won't exist, so you can't set ioctl – Milliways Sep 16 '18 at 2:21
  • sorry its meant /dev/serial0 changed above – Trent Bliss Sep 16 '18 at 3:37
  • What is 0x542F supposed to mean? It's better to use symbolic names for ioctl. – RalfFriedl Sep 16 '18 at 9:07
0

It looks like you're using the standard serial driver which doesn't understand the RS485-specific RTS control which you're trying to request.

AFAIK the easiest way is to buy a USB to RS485 adapter, which should support the correct handling in hardware. Otherwise, you'll have to make the serial driver do that for you. Your options include rebuilding the kernel with SER_RS485_ENABLED set to y, or build an out-of-tree driver which provides the RS485-specific RTS control (example).

There were also attempts to drive the RTS pin from userspace, but they don't seem to be successful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.