CppLinuxSerial icon indicating copy to clipboard operation
CppLinuxSerial copied to clipboard

I want use this lib for 485,but I don't konw how to control the state

Open VarianSikovsky opened this issue 1 year ago • 2 comments

First thank for you make this Very good library Now I need a lib for serial,but I’m using a custom-made linux pc,and this pc has different serial for 485 ,I need change gpio state that is used to switch between read and write,fortunately the gpio is also RTS pin,so that I just need change RTS state, and I can switch between read and write The issue is I don't how to use the CppLinuxSerial to change RTS state,the examples don't have this dome I really hope to get your reply

VarianSikovsky avatar Aug 29 '24 09:08 VarianSikovsky

Hi.

I used this nice lib with RS485 for some tests. All I needed to do was to add a short code fragment to set the port into the RS485 mode:

Inside ConfigureTermios()

        struct serial_rs485 ctrl485;
        /* Set the port in 485 mode */
        ctrl485.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND;
        ctrl485.delay_rts_before_send = 0;
        ctrl485.delay_rts_after_send = 0;
        int status = ioctl(this->fileDesc_, TIOCSRS485, &ctrl485);
        if (status) {
            THROW_EXCEPT("Unable to configure port \"" + device_ + "\" in 485 mode.");
        }          

add #include <linux/serial.h> as well.

The RTS pin should be handled by the kernel uart driver and needs to be specified inside the device tree.

Vinzenz82 avatar Mar 13 '25 08:03 Vinzenz82

@Vinzenz82 interesting! I didn't know there was a serial_rs485 struct available that you can use to configure it specifically for RS-485. I'll have to look further into this and consider adding support into this code base.

gbmhunter avatar Mar 14 '25 23:03 gbmhunter