Home:ALL Converter>Setting DTR high, RTS low using Linux bash?

Setting DTR high, RTS low using Linux bash?

Ask Time:2014-07-22T19:30:15         Author:user1447903

Json Formatter

I have a serial device that has no flow control, but is powered from the RS232 port by holding the RTS high and DTR low

I was hoping to read from this device using a simple bash script, but can't find any way to set the handshaking lines, using stty or otherwise, to allow for the above configuration.

Any ideas if this is possible?

Author:user1447903,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/24886207/setting-dtr-high-rts-low-using-linux-bash
Johann Klammer :

I've been trying something similar here.\nI used the ioctls. Then measured with a multimeter.\nthis is what I found:\n\n dsrv=TIOCM_DTR;//this sets RTS to -11.7?\n dsrv=TIOCM_RTS;//sets DTR -11.7\n ioctl(fd, TIOCMBIS, &dsrv);\n\n dsrv=TIOCM_DTR;//this sets RTS to 11.7?\n dsrv=TIOCM_RTS;//sets DTR 11.7\n ioctl(fd, TIOCMBIC, &dsrv);\n\n\nIt is somewhat weird...",
2019-05-20T10:59:30
Benoit-Pierre DEMAINE :

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.\n\nYou may need to play with stty crtscts and clocal flags.\n\nI have published a detailed answer here:\nhttps://forums.gentoo.org/viewtopic-p-8132756.html#8132756\n\nHere is the short version:\n\n#!/bin/bash\nMySerialPort=\"/dev/ttyUSB0\"\nMyLatency=\"2\"\necho \"#include <fcntl.h>\n#include <sys/ioctl.h>\nmain()\n{ int fd; fd = open(\\\"${MySerialPort}\\\",O_RDWR | O_NOCTTY );\nint RTS_flag; RTS_flag = TIOCM_RTS;\nioctl(fd,TIOCMBIS,&RTS_flag);\nsleep (${MyLatency});\nioctl(fd,TIOCMBIC,&RTS_flag);\nclose(fd); } \" | tcc -run -\n\n\nNote that sending data on TX will probably mess RTS; see the Gentoo forum for details.",
2017-10-21T13:55:07
yy