[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Ncurses and reading from seriall port
From: |
Philipp H. Mohr |
Subject: |
Ncurses and reading from seriall port |
Date: |
Thu, 21 Nov 2002 20:49:54 +0000 (GMT) |
Hello,
I am trying to read from the serial port and to print out the string
I read. I know I could just print it out on the command line, but
I want to do other fancy thing with the string in the next stage.
My problem is that in:
for (;;)
{
addch('b');
refresh();
res = read(fd,buf,255);
buf[res]=0;
}
b gets printed, but It dosn't read the seriall port - or doesn't print it.
Thank you very much.
Phil
code:
#include <curses.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#define BAUDRATE B38400
#define MODEMDEVICE "/dev/ttyS1"
#define _POSIX_SOURCE 1
#define FALSE 0
#define TRUE 1
static void finish(int sig);
int
main(int argc, char *argv[])
{
int num = 0;
int fd,c, res, result;
struct termios oldtio,newtio;
char buf[5];
(void) signal(SIGINT, finish); /* arrange interrupts to terminate
*/
(void) initscr(); /* initialize the curses library */
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd <0) {perror(MODEMDEVICE); exit(-1); }
tcgetattr(fd,&oldtio);
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | ICRNL;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
addch('a');
refresh();
for (;;)
{
addch('b');
refresh();
res = read(fd,buf,255);
buf[res]=0;
}
tcsetattr(fd,TCSANOW,&oldtio);
finish(0); /* we're done */
}
static void finish(int sig)
{
endwin();
exit(0);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Ncurses and reading from seriall port,
Philipp H. Mohr <=