1. Introduction¶
EIA-485, also known as TIA/EIA-485 or RS-485, is a standard defining theelectrical characteristics of drivers and receivers for use in balanceddigital multipoint systems.This standard is widely used for communications in industrial automationbecause it can be used effectively over long distances and in electricallynoisy environments.
I have two objects of the class Foo in my main class MainWindow, which use a serial connection between two FTDI breakout boards to read and write serial data.I've checked this setup via a terminal and it works. In my main class, I'm trying to send a QByteArray from FooA to FooB, but received is empty when executing testConnection.I've checked the serial connection with an additional FTDI.
2. Hardware-related Considerations¶
Some CPUs/UARTs (e.g., Atmel AT91 or 16C950 UART) contain a built-inhalf-duplex mode capable of automatically controlling line direction bytoggling RTS or DTR signals. That can be used to control externalhalf-duplex hardware like an RS485 transceiver or any RS232-connectedhalf-duplex devices like some modems.
For these microcontrollers, the Linux driver should be made capable ofworking in both modes, and proper ioctls (see later) should be madeavailable at user-level to allow switching from one mode to the other, andvice versa.
3. Data Structures Already Available in the Kernel¶
The Linux kernel provides the serial_rs485 structure (see [1]) to handleRS485 communications. This data structure is used to set and configure RS485parameters in the platform data and in ioctls.
The Qt Serial Port module provides the following examples for reference to help understand the API usage. Running the Examples. To run the examples from Qt Creator, open the Welcome mode and select the example from Examples.For more information, visit Building and Running an Example. The IFTOOLS MSB-RS485 module and the AWESOME multi-function software (!) are by far the best tool I’ve ever found for RS485 bus analysis in our serial networks. It is like going from dark night to sunshine; your RS485 analysis suite paid for itself many times over in the very first test session.
The device tree can also provide RS485 boot time parameters (see [2]for bindings). The driver is in charge of filling this data structure fromthe values given by the device tree.
Any driver for devices capable of working both as RS232 and RS485 shouldimplement the rs485_config callback in the uart_port structure. Theserial_core calls rs485_config to do the device specific part in responseto TIOCSRS485 and TIOCGRS485 ioctls (see below). The rs485_config callbackreceives a pointer to struct serial_rs485.
4. Usage from user-level¶
From user-level, RS485 configuration can be get/set using the previousioctls. For instance, to set RS485 you can use the following code:
5. References¶
Rs485 Connector
[1] include/uapi/linux/serial.h
Rs485 Serial Pinout
[2] Documentation/devicetree/bindings/serial/rs485.txt