2

我有一个没有流量控制的串行设备,但通过将RTS 保持在高电平DTR保持在低电平从RS232端口供电

我希望使用简单的 bash 脚本从该设备读取数据,但找不到任何方法来设置握手线,使用 stty 或其他方式,以允许上述配置。

如果可能的话,有什么想法吗?

4

3 回答 3

1

I don't have an answer about setting RTS without touching DTR, because I don't have any DTR pin on my dongle; but, trying to set RTS was already very tricky un pure shell.

You may need to play with stty crtscts and clocal flags.

I have published a detailed answer here: https://forums.gentoo.org/viewtopic-p-8132756.html#8132756

Here is the short version:

#!/bin/bash
MySerialPort="/dev/ttyUSB0"
MyLatency="2"
echo "#include <fcntl.h>
#include <sys/ioctl.h>
main()
{ int fd; fd = open(\"${MySerialPort}\",O_RDWR | O_NOCTTY );
int RTS_flag; RTS_flag = TIOCM_RTS;
ioctl(fd,TIOCMBIS,&RTS_flag);
sleep (${MyLatency});
ioctl(fd,TIOCMBIC,&RTS_flag);
close(fd); } " | tcc -run -

Note that sending data on TX will probably mess RTS; see the Gentoo forum for details.

于 2017-10-21T13:55:07.393 回答
0

我一直在这里尝试类似的东西。我使用了ioctl。然后用万用表测量。这就是我发现的:

  dsrv=TIOCM_DTR;//this sets RTS to -11.7?
  dsrv=TIOCM_RTS;//sets DTR -11.7
  ioctl(fd, TIOCMBIS, &dsrv);

  dsrv=TIOCM_DTR;//this sets RTS to 11.7?
  dsrv=TIOCM_RTS;//sets DTR 11.7
  ioctl(fd, TIOCMBIC, &dsrv);

这有点奇怪……

于 2019-05-20T10:59:30.957 回答
-1

socat 在 hucpcl=1 时控制 DTR

(Atmel EDBG USB Serial 需要 DTR 高)

sleep 1; while true; do echo -en "\x01\x02"; sleep 0.1; done | socat -T1 -t1 - /dev/ttyUSB0,hupcl=1,raw,b1000000,cs8,echo=0

man socat - 可能会为您的串行问题找到更多解决方案。

于 2019-05-04T19:05:38.237 回答