RS485 & RS232 - Send single byte
In this example, the serial ports are initialized and used in a Linux environment in protocol mode 0, which is distinguished from mode 1 (also called protocol mode system) by the sending of single bytes or packets without preamble or checksum and without the system library functions.
In start.c two tasks are executed
-
rs485_task
-
rs232_task The two functions that execute when these tasks are launched are present in the project's common.h file. The first lines of code initialize and open the port, followed by an infinite loop listening for any incoming bytes.
When receiving a packet, you'll notice how the function idles until nothing arrives, while it shuffles bytes with com_rx() until something is present in the buffer, thus incrementing a counter. For the 485, everything is similar, except for the com, which is obviously different.
To send a single byte, use the com_tx function.
Note: com_tx and com_rx are functions of the Proteus development environment, described in the manual on page 34, under the Serial Ports section.
The example's interface is very simple: it allows the user to select a character and send it via RS-232 or RS-485, incrementing the corresponding counters. The same applies to received characters.
L'esempio è stato testato su due dispositivi syel p10 collegati tra loro in RS232 e RS485 ed liberamente scaricabile dal seguente link: scarica
2025-02-07 Creatore dell'articolo Simone De Santis. Per ulteriori richieste simone.desantis@syel.it


