this is my very first post in this beautiful forum. I found lots of information here already. Thanks to all.
At the moment I am trying to get RS485 up and running. This seems nothing special as there are lots of RS485 boards around. I already have this one: https://www.conrad.biz/de/raspberry-pi- ... 67832.html and it works in one of my environments. With other devices I can't get RS485 running perhaps beause of the behaviour of this device:
For RS485 communication the sender / receiver has to by switched in either send or receive mode. This is done normally by an additional output pin. The board I have doesn't do this and switches between send and receive depending on the state of TX. I think this is somewhat strange but seems to work and the advantage is that this additional output pin is not needed. Only TX and RX are necessary.
What I want to do is to create a standard RS485 bus. The transceiver switches to send mode then sends all the bits and then switches back to receive mode. What I found is that on the raspi the pin used to switch the transceiver is RTS (GPIO 17) and pyserial has a RS485 mode. So I set up the following code:
Code: Select all
#!/usr/bin/env python3
import serial
import serial.rs485
ser = serial.Serial(
port="/dev/ttyAMA0",
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0,
rtscts = True
)
ser.rs485_mode = serial.rs485.RS485Settings()
if (ser.isOpen() == True):
ser.close()
ser.open()
ser.reset_input_buffer
outstr = "5"
ser.write(outstr.encode(encoding = 'ascii'))
The pyserial package is python3-serial and the OS is rasobian stretch lite 2018-11-13. I am totally stuck here so any help is very much appreciated.Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 156, in _set_rs485_mode
fcntl.ioctl(self.fd, TIOCSRS485, buf)
OSError: [Errno 25] Inappropriate ioctl for device
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./test485.py", line 14, in <module>
ser.rs485_mode = serial.rs485.RS485Settings()
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 480, in rs485_mode
self._reconfigure_port()
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 434, in _reconfigure_port
self._set_rs485_mode(self._rs485_mode)
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 158, in _set_rs485_mode
raise ValueError('Failed to set RS485 mode: {}'.format(e))
ValueError: Failed to set RS485 mode: [Errno 25] Inappropriate ioctl for device
Elektrix