tty

How can I implement timeout for read() when reading from a serial port (C/C++)

人盡茶涼 提交于 2019-12-17 18:41:05
问题 I am reading bytes from a serial port in C++ using a file descriptor and the posix/unix read() function. In this example, I am reading 1 byte from the serial port (baud rate settings and similiar are omitted for clarity): #include <termios.h> #include <fcntl.h> #include <unistd.h> int main(void) { int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY); char buf[1]; int bytesRead = read(fd, buf, 1); close(fd); return 0; } If the device connected to /dev/ttyS0 does not send any information, the program

AT^SYSINFO and a C++ terminal program

余生长醉 提交于 2019-12-17 06:56:27
问题 I have written a program that comminucates serially with a USB 3g Modem. When I open the port and write the AT command AT To the modem, I get the normal "OK" response and can read it using a serial read function. In a terminal, when I write the command AT^SYSINFO I get the following response: ^SYSINFO:#,#,#,#,#,# With the #'s being numbers. However, when I attempt to write the same command serially using my program, I read only this reponse: AT^SYSINFO I try to then read another line of

Reading and writing to serial port in C on Linux

▼魔方 西西 提交于 2019-12-17 03:46:26
问题 I'm trying to send/receive data over an USB Port using FTDI , so I need to handle serial communication using C/C++. I'm working on Linux (Ubuntu). Basically, I am connected to a device which is listening for incoming commands. I need to send those commands and read device's response. Both commands and response are ASCII characters . Everything works fine using GtkTerm but, when I switch to C programming, I encounter problems. Here's my code: #include <stdio.h> // standard input / output

How to kill respawned process by init in linux

落花浮王杯 提交于 2019-12-14 03:43:38
问题 am respawning the /bin/bash on ttyS1 port.ttyS0 is my console. inittab entry is given below. ::respawn:/bin/bash < /dev/ttyS1 > /dev/ttyS1 2> /dev/ttyS1 My question is how to disable/kill respwning so that i can use serial port for other application. 回答1: You can kill that bash process like other processes. However, init respawns it immediately - nothing gained. To disable the process you have to edit /etc/inittab and comment out that line. To inform init about this change you have to send a

How does ssh receive password from tty?

社会主义新天地 提交于 2019-12-14 03:34:18
问题 I was wondering how openssh gets the password when login, cause I got stuck in automating entering passwords to the similar tools in linux which requires getting password from tty like ssh. Tried to understand sshpass and found that sshpass forks a child process with the same pid then enters the password under the child process. Don't know if my guess was right that ssh needs to check the right pid since I cannot stdin to the current tty using another process to enter the ssh password. 回答1:

Write non-ASCII characters to stdin of a progam on a tty (over ssh)

坚强是说给别人听的谎言 提交于 2019-12-13 18:24:26
问题 I'm SSHd into a remote server with some binary challenges. At one point it asks for me to input text. I know it's using fgets() to read stdin , and that I can overflow where it is being copied to and overwrite a nearby variable. The problem is I don't know how to type the address values I need, \x84 and \x04 etc. If I were able to use bash I would echo -ne "\x84" or use a C hex array but I can't do that kind of thing here. I've tried using a hex to ASCII converter and copying the binary

Mac OS analog to /dev/ttyUSBxx

 ̄綄美尐妖づ 提交于 2019-12-13 11:39:41
问题 I used to linux USB port naming, aka /dev/ttyUSBxx and currently trying to write some test software to read/wrtie raw data to USB ports on iMac, but i find it hard to detect to which port my usb hardware is connected. I have tried up to a using /dev/ttys"x" but no luck. In the system information i see the hardware attached at Location ID: 0xfa120000 / 6 maybe this can help somehow? 回答1: OS X doesn't create a /dev entry for raw access to USB devices, and there's no way to access them as TTY

How to get HPUX to adopt a TTY as controlling

*爱你&永不变心* 提交于 2019-12-13 03:07:46
问题 A question that came through on the sshpass mailing list (and also on stack overflow). Sshpass does not work on HP-UX. Looking at the truss output, I see the following: -u [/tmp/sshpass][14066]{3783827} fork() ................... (returning as child ...) ......... = 14064 {3783821} The child process is 14066. -u [/tmp/sshpass][14066]{3783827} setpgrp3(2)................................................. [entry] -u [/tmp/sshpass][14066]{3783827} setpgrp3(2)......................................

Leaving canonical mode (entering raw/cbreak mode) in WSL

断了今生、忘了曾经 提交于 2019-12-13 02:42:22
问题 How do I enter raw or cbreak mode under WSL? I want keyboard input available to stdin immediately, instead of waiting for enter key. I've tried using termios to put the TTY in raw or canonical mode, either by using cfmakeraw or by fiddling with various flags, following the example from the termios manual page and several variations (only disabling ICANON , code similar to ncurses internals, and so on): termios_p->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);

Capture output as a tty in python

耗尽温柔 提交于 2019-12-12 16:03:07
问题 I have a executable which requires a tty (as stdin and stderr), and want to be able to test it. I want to input stdin, and capture the output of stdout and stderr, here's an example script: # test.py import sys print("stdin: {}".format(sys.stdin.isatty())) print("stdout: {}".format(sys.stdout.isatty())) print("stderr: {}".format(sys.stderr.isatty())) sys.stdout.flush() line = sys.stdin.readline() sys.stderr.write("read from stdin: {}".format(line)) sys.stderr.flush() I can run this without