- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试在我的程序中设置半双工通信。我的 RS485 收发器使用 RTS 标志 (TIOCM_RTS) 在发送和接收之间来回切换。为了发送/接收数据,我需要手动更改 RTS 标志:
将 RTS 设置为高。
发送数据。
将 RTS 设置为低。
int setRTS(int level) {
int status;
ioctl(ser_port, TIOCMGET, &status);
if(level) {
status |= TIOCM_RTS;
} else {
status &= ~TIOCM_RTS;
}
ioctl(ser_port, TIOCMSET, &status);
return 1;
}
我的问题是:linux内核不应该能够自动切换RTS吗?以及如何确保在调用 setRTS(0) 之前发送数据?
最佳答案
shouldn't the linux kernel be able to switch RTS automatically?
是的,从 Linux 3.0 开始就有内核框架。
include/uapi/asm-generic/ioctls.h中有两个ioctl:
#define TIOCGRS485 0x542E
#define TIOCSRS485 0x542F
在 RS-485 模式下检索和配置 tty 串行端口驱动程序。
这些 ioctl 使用 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 .. */
};
我已经在 Atmel 和 Etrax SoC 上使用了这种 RS-485 功能,但在其他方面,这些 ioctl 在 Linux UART/USART 驱动程序中的实现非常稀少。
如果您的驱动程序没有,请考虑自己实现。您可以使用 drivers/tty/serial/atmel_serial.c 中的实现作为指南。另请阅读 Linux kernel document for RS485 .
关于c - 自动更改 RTS 以进行 RS-485 通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25250731/
我正在对使用 GHC 编译的 haskell 程序的内存消耗进行基准测试。为此,我使用以下命令行参数运行程序:+RTS -t -RTS .这是一个示例输出:> . 根据 ghc 手册,输出显示: 程序
在《魔兽争霸 3》或《帝国时代》等游戏中,AI 对手在 map 上移动的方式几乎是无限的。 map 很大,其他玩家的位置也在不断变化。 这类游戏中的 AI 寻路是如何工作的?在这样的设置中,标准的图搜
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我正在用 Java 编写 RTS 游戏,遇到了一些多态性问题。为了描述我的问题,我将列出游戏中的一些对象/类:(我将在括号内说明它们中的每一个应该能够做什么) 坦克(可以移动,可以攻击) 塔(可以攻击
我正在为 Epic Flash 游戏设计大赛 http://www.youtube.com/watch?v=bpFBraUbHyo&list=UUfkxvxrvpNxXvdKusYS0NfQ&inde
当我运行 ./MyProgram +RTS -N4 时,我希望我的程序自动检测到它正在 4 个核心上运行,并创建 4 个 Spark 来处理数据集。现在,每次我想更改此选项时,我都要重新编译,这很烦人
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我正在尝试为我的 RTS 游戏实现多人游戏。它不是回合制的,所以我认为我应该使用 UDP,对吧? 对于应该从客户端发送到服务器的内容,我也有点困惑。游戏中显示的每个对象(建筑物、树木、单位等)都在 G
关于如何将脚本集成到游戏中,我已经访问了几个教程和链接——但其中大部分对我来说并没有在流程中及早开始。我正在努力思考有效脚本游戏的基本结构。以下是基础知识: 我正在使用 C++ 开发一款基本的 2d
对于 rts 中的单元集合来说,什么是好的数据类型?我正在为 an api that lets you write bots for the strategy game Starcraft2 in P
我很好奇什么样的算法可以根据它的城市、建筑物,当然还有附近城市和建筑物的半径来计算国家的边界线? 游戏《万国崛起》图片: 如何用线条或三角形带渲染这个形状(例如宽度为 5 米)?如何有序地从边界线
寻找一种算法,用于确定在像星际争霸这样的实时战略游戏中作为一个小队一起移动的单位组。我目前关注的方向是一种聚类算法,但很难找到哪个算法最有效,因为单元作为一个整体在移动,而不仅仅是静止不动。任何帮助都
我有一段代码可以读取串行端口 CTS 线的当前状态,然后应用程序根据那里的值进入适当的模式。 使用此处描述的零调制解调器电缆: http://www.lammertbies.nl/comm/info/
我正在用 C# 编写 2D 太空 RTS 游戏。单人游戏作品。现在我想添加一些多人游戏功能。我在谷歌上搜索了一下,似乎只有一种方法可以让数千个单位在没有强大网络连接的情况下连续移动:只通过网络发送命令
我正在制作一个实时太空战略游戏克隆,当时它没有任何多人游戏选项。我想为它添加多人游戏。 游戏本身相对较长:完成一个游戏需要大约 10-15 个小时的游戏时间。这很长,我不想强迫玩家不间断地玩它或由
我想开始修补 RTS AI,但我很难找到一个好的工作环境,即一个已经创建的游戏。我看过 Spring RTS 和 Bos Wars,但它们似乎不利于创建简单的示例。 我并不完全反对自己编写游戏环境,只
我必须回答以下关于 6502 汇编语言的问题: “在堆栈上,有以下值(顶部元素在前):0x01, 0x02, 0x03, 0x04, 0x05, 0x06地址 0xc000 是指令 jsr 0xABC
我一直在考虑一款多人 RTS 游戏。我似乎无法解决的部分是保持单位运动同步。如果我将单元 A 移动到 XY 点,我必须将其传回中继到其他客户端的服务器。 我很好奇通信会是什么样子。你能告诉服务器我要将
对于 ghci ,我可以限制 ghci 可以使用的内存 $ ghci +RTS -M10m -RTS 当我编译整个程序时,我可以 $ ghc -rtsopts a.hs 然后 $ ./a +RTS -
我有一个 Haskell 程序,它处理一个文本文件并构建一个 Map (包含数百万个元素)。整个过程可以持续2-3分钟。我发现调整 -H 和 -A 选项会对运行时间产生很大影响。 有documenta
我是一名优秀的程序员,十分优秀!