本文介绍了自动改变为RS-485通信RTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立半双工通信在我的计划。我已经使用RTS标志(TIOCM_RTS)来传输之间来回切换,并接受我的RS485收发器。和发送/接收数据,我需要手动更改RTS标志:


  1. 设置RTS为高。


  2. 发送数据。


  3. 设置RTS为低。

      INT setRTS(INT级){
        INT状态;
        的ioctl(ser_port,TIOCMGET,&安培;状态);
        如果(水平){
            状态| = TIOCM_RTS;
        }其他{
            状态和放大器; =〜TIOCM_RTS;
        }
        的ioctl(ser_port,TIOCMSET,&安培;状态);
        返回1;
    }


我的问题是:不应该在Linux内核能够自动切换RTS?
而如何保证数据调用之前被送到setRTS(0)?


解决方案

Yes, there is kernel framework for this starting in Linux 3.0.
There are two ioctls in include/uapi/asm-generic/ioctls.h:

#define TIOCGRS485      0x542E
#define TIOCSRS485      0x542F

to retrieve and configure a tty serial port driver in RS-485 mode.
These ioctls use the struct serial_rs485:

 /*
  * Serial interface for controlling RS485 settings on chips with suitable
  * support. Set with TIOCSRS485 and get with TIOCGRS485 if supported by your
  * platform. The set function returns the new state, with any unsupported bits
  * reverted appropriately.
  */

 struct serial_rs485 {
         __u32   flags;                  /* RS485 feature flags */
 #define SER_RS485_ENABLED               (1 << 0)        /* If enabled */
 #define SER_RS485_RTS_ON_SEND           (1 << 1)        /* Logical level for
                                                            RTS pin when
                                                            sending */
 #define SER_RS485_RTS_AFTER_SEND        (1 << 2)        /* Logical level for
                                                            RTS pin after sent*/
 #define SER_RS485_RX_DURING_TX          (1 << 4)
         __u32   delay_rts_before_send;  /* Delay before send (milliseconds) */
         __u32   delay_rts_after_send;   /* Delay after send (milliseconds) */
         __u32   padding[5];             /* Memory is cheap, new structs
                                            are a royal PITA .. */
 };

I've used this RS-485 capabilty on Atmel and Etrax SoCs, but otherwise implementation of these ioctls in Linux UART/USART drivers is very sparse.
If your driver doesn't have it, then consider implementing it yourself. You could use the implementation in drivers/tty/serial/atmel_serial.c as a guide. Also read the Linux kernel document for RS485.

这篇关于自动改变为RS-485通信RTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 01:23