RT-Thread / rt-thread

RT-Thread is an open source IoT Real-Time Operating System (RTOS).
https://www.rt-thread.io
Apache License 2.0
10.56k stars 5.03k forks source link

RTT serial supports RS485 #9127

Open hhb2017 opened 4 months ago

hhb2017 commented 4 months ago

Describe problem solved by the proposed feature

RTT serial supports RS485 like linux RS485

Describe your preferred solution

No response

Describe possible alternatives

No response

ComerLater commented 4 months ago

RS485只是硬件电平,跟软件没有关系吧

hhb2017 commented 4 months ago

类似这种linux用户态的配置

  1. Usage from user-level

    From user-level, RS485 configuration can be get/set using the previous ioctls. For instance, to set RS485 you can use the following code::

    include <linux/serial.h>

    / Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 /

    include <sys/ioctl.h>

    / Open your specific device (e.g., /dev/mydevice): / int fd = open ("/dev/mydevice", O_RDWR); if (fd < 0) { / Error handling. See errno. / }

    struct serial_rs485 rs485conf;

    / Enable RS485 mode: / rs485conf.flags |= SER_RS485_ENABLED;

    / Set logical level for RTS pin equal to 1 when sending: / rs485conf.flags |= SER_RS485_RTS_ON_SEND; / or, set logical level for RTS pin equal to 0 when sending: / rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND);

    / Set logical level for RTS pin equal to 1 after sending: / rs485conf.flags |= SER_RS485_RTS_AFTER_SEND; / or, set logical level for RTS pin equal to 0 after sending: / rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND);

    / Set rts delay before send, if needed: / rs485conf.delay_rts_before_send = ...;

    / Set rts delay after send, if needed: / rs485conf.delay_rts_after_send = ...;

    / Set this flag if you want to receive data even while sending data / rs485conf.flags |= SER_RS485_RX_DURING_TX;

    if (ioctl (fd, TIOCSRS485, &rs485conf) < 0) { / Error handling. See errno. / }

    / Use read() and write() syscalls here... /

    / Close the device when finished: / if (close (fd) < 0) { / Error handling. See errno. / }