[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

termios ifnterface, raw?



Hi,
I'm using the program below to grab data from the serial port. The data is in a predefined language and does not follow the typical character set, but sending commands.

The hex values I've received is in no way close to that being send and I've tried just about every configuration I can think of. The raw data 0x02 for instance signifies the start of a message and that's no where to be found. I'm using a non return to zero format: 1 start bit, 8 data bits, no parity, and one stop.
Can any one offer any insight into this? What am I missing?
Thanks a lot.

listing:
main()
      {
        struct termios oldtio,newtio;
        struct sigaction saio;           /* definition of signal action */
        int inx = 0;
        /* open the device to be non-blocking (read will return immediatly) */
        fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
        if (fd <0) {perror("/dev/ttyS0"); exit(-1); }

        /* install the signal handler before making the device asynchronous */
        saio.sa_handler = signal_handler_IO;
       // saio.sa_mask = 0;
        saio.sa_flags = 0;
        saio.sa_restorer = NULL;
        sigaction(SIGIO,&saio,NULL);

        /* allow the process to receive SIGIO */
        fcntl(fd, F_SETOWN, getpid());
        /* Make the file descriptor asynchronous */
        fcntl(fd, F_SETFL, FASYNC);

        tcgetattr(fd,&oldtio);
        newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
        newtio.c_iflag = IGNPAR | ICRNL;
        newtio.c_oflag = 0;
        newtio.c_lflag = ICANON;
        newtio.c_cc[VMIN]=0;
        newtio.c_cc[VTIME]=0;
        tcflush(fd, TCIFLUSH);
        tcsetattr(fd,TCSANOW,&newtio);

        /* loop while waiting for input. normally we would do something
           useful here */
        for(inx =0; i<10000; i++) {
         inx++;
          usleep(100000);
          }
        }
        /* restore old port settings */
        tcsetattr(fd,TCSANOW,&oldtio);
      }


      void signal_handler_IO (int status)
      {
        printf("received SIGIO signal.\n");
        res = read(fd,buf,255);
        for(i = 0; i< res; i++) {
                printf("%X ", buf[i]);
                }
      }


_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!




Reply to: