#include /*POSIX terminal control definitions*/ #include /*standard input/output definitions*/ #include #include /*UNIX standard functions definitions*/ #include /*File control definitions*/ #include /*error numbre definitions*/ #include /*string functions definitions*/ #include /*available signals definitions*/ #include #define BAUDRATE B4800 #define MODEMDEVICE "/dev/termios1" #define ENDMINITERM 2 /* ctrl-b to quit miniterm */ #define _POSIX_SOURCE 1 /* POSIX compliant source */ #define FALSE 0 #define TRUE 1 void *hilo_1(void *arg); void main (void) { struct termios oldtio,newtio,oldstdtio,newstdtio; pthread_t th1; pthread_attr_t attr; int fd, c; /* Open modem device for reading and writing and not as controlling tty because we don't want to get killed if linenoise sends CTRL-C. */ fd = open (MODEMDEVICE, O_RDWR | O_NOCTTY); if (fd <0) perror(MODEMDEVICE); exit(-1); tcgetattr(fd,&oldtio); /* save current modem settings */ /* Set bps rate and hardware flow control and 8n1 (8bit,no parity,1 stopbit). Also don't hangup automatically and ignore modem status. Finally enable receiving characters. */ newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD; /* Ignore bytes with parity errors and make terminal raw and dumb. */ newtio.c_iflag = IGNPAR; /* Raw output. */ newtio.c_oflag = 0; /* Don't echo characters because if you connect to a host it or your modem will echo characters for you. Don't generate signals. */ newtio.c_lflag = 0; /* blocking read until 1 char arrives */ newtio.c_cc[VMIN]=1; newtio.c_cc[VTIME]=0; /* now clean the modem line and activate the settings for modem */ tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); tcsetattr(1,TCSANOW,&newtio); /* stdout settings like modem settings */ /* next stop echo and buffering for stdin */ tcgetattr(0,&oldstdtio); tcgetattr(0,&newstdtio); /* get working stdtio */ newstdtio.c_lflag &= ~(ICANON | ECHO); tcsetattr(0,TCSANOW,&newstdtio); /* terminal settings done, now handle in ouput */ if(pthread_attr_init (&attr) == -1) perror(""); if (pthread_create(&th1, &attr, hilo_1, NULL) == -1) perror (""); while(TRUE) { read(fd,&c,1); printf("%d", c); } } void *hilo_1 (void *arg) { int dato,fd1; fd1 = open (MODEMDEVICE, O_RDWR | O_NOCTTY); if (fd1 <0) perror(MODEMDEVICE); exit(-1); while(TRUE) { printf(" Enter byte:" ); dato=getchar(); write(fd1,&dato,1); } }