linux - C serial program using keyboard and monitor instead of serial port /dev/ttyUSBX -
i trying write programme accepts keyboard input , puts output on screen acting if serial port. not sure doable. current code serial port works is:
int fd; char *portname; char buf[255]; struct termios tty; portname = "/dev/ttyusb0"; // opening serial port fd = open(portname, o_rdwr | o_noctyy | o_sync ); //writing serial port write (fd, "hello!\n", 7); //reading serial port read (fd, buf, 255)
so, possible instead of setting portname /dev/ttyusb0 set else (e.g. /dev/stdin?) , exact same uart functionality keyboard set input , screen output?
thank help.
unix/linux sets stdin (fd 0), stdout (fd 1) , stderr (fd 2) open terminal (whether serial line real hardware terminal, virtual console or graphics terminal) keyboard , screen connected to. it's available termio command , special device filename /dev/tty
termios routines termios(3) man page operate on open fild descriptor, allows getting of terminal driver attributes, turning off canonical mode , later resetting values @ end of program.
you read/write normal, in posix everything's file, whether it's serial line, disk, terminal emulator abstracted away, process doing i/o os kernel.
c linux serial-port tty
No comments:
Post a Comment