Linux c使用485通讯,ioctl的配置
2017-08-14 19:00
155 查看
//原文链接:https://www.kernel.org/doc/Documentation/serial/serial-rs485.txt #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 whilst 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. */ }
相关文章推荐
- Tomcat的异步通讯配置----使用NIO
- 工行通讯前置配置工具使用的陷阱
- Tomcat的异步通讯配置----使用NIO
- Android及时通讯——配置环信及时通讯注意地方,EvevtBus使用详解,网络请求过程中退出出错处理办法
- linux c 使用libxml2读取配置文件
- Tomcat的异步通讯配置----使用NIO
- iis 配置ssl通讯 和证书的使用
- Tomcat的异步通讯配置----使用NIO
- Tomcat的异步通讯配置----使用NIO
- 如何在BCB中配置和使用GDI+技术?(附动画实例)
- 怎样配置 WSS 以使用 Kerberos 身份验证(下)
- 使用web.config配置应用程序参数
- 使用C#进行点对点通讯和文件传输(通讯基类部分)
- GRUB安装,配置及使用汇总
- 配置Tomcat 4使用SSL
- ASP.NET中使用web.config配置web应用程序中的数据库连接
- 使用Resin在NT环境下配置JSP环境!
- 使用C#进行点对点通讯和文件传输(发送接收部分)
- 使用PVCS系列软件构建配置管理环境(四)
- 使用PVCS系列软件构建配置管理环境(一)