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

Re: termios ifnterface, raw?



On Fri, Jan 27, 2006 at 02:44:34PM -0500, Robbie wrote:
> 
> 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);

You have junk in almost all control character locations of
newtio, possibly not even reproducible from run to run since 
it is allocated on the stack. You could for example copy
oldtio to newtio to start from an existing and hopefully
working (even if it's not what you want) state.

Besides that setting ICANON and cc[VMIN] or cc[VTIME] is
inconsistent since man termios claims:

These symbolic subscript values are all different, except that
VTIME, VMIN may have the same value as VEOL, VEOF, respectively.  
(In non-canonical mode the special character meaning is replaced 
by the timeout meaning. 
...)

As already mentioned, cfmakeraw may help you. I don't know
what you mean by BAUDRATE, since I've not found this constant
on my system.

	Regards,
	Gabriel



Reply to: