ts-7000
[Top] [All Lists]

Re: [ts-7000] Re: tcgetattr problem

To:
Subject: Re: [ts-7000] Re: tcgetattr problem
From: "Don W. Carr" <>
Date: Sun, 15 Apr 2007 09:50:08 -0500
One quick comment. perror, takes a valid null terminated string, then uses that as part of the error message. It puts that string first, then appends a ':' and space, then the actual error message. So, the code you wrote could potentially crash the program on error.

Use something like this for perror:

perror("Call to tcgetattr");

Now that I think about it, the structure will have the constants that are defined in a header file, which match to a baud rate, but are not the actual baud rate.

Here is my code for setting, and this should solve the problem for you. You likely need a case statement if you want to print the baud rates, which would be the opposite of what I do below.

  switch (baud_rate)
  {
    case 0:
      rt_tio.c_cflag = B0;
      break;
    case 50:
      rt_tio.c_cflag = B50;
      break;
    case 75:
      rt_tio.c_cflag = B75;
      break;
    case 110:
      rt_tio.c_cflag = B110;
      break;
    case 134:
      rt_tio.c_cflag = B134;
      break;
    case 150:
      rt_tio.c_cflag = B150;
      break;
    case 200:
      rt_tio.c_cflag = B200;
      break;
    case 300:
      rt_tio.c_cflag = B300;
      break;
    case 600:
      rt_tio.c_cflag = B600;
      break;
    case 1200:
      rt_tio.c_cflag = B1200;
      break;
    case 1800:
      rt_tio.c_cflag = B1800;
      break;
    case 2400:
      rt_tio.c_cflag = B2400;
      break;
    case 4800:
      rt_tio.c_cflag = B4800;
    case 9600:
      rt_tio.c_cflag = B9600;
      break;
    case 19200:
      rt_tio.c_cflag = B19200;
      break;
    case 38400:
      rt_tio.c_cflag = B38400;
      break;
    case 57600:
      rt_tio.c_cflag = B57600;
      break;
    case 115200:
      rt_tio.c_cflag = B115200;
      break;
    case 230400:
      rt_tio.c_cflag = B230400;
      break;
    default:
      rt_tio.c_cflag = B9600;
  }
 
I am packing to head for San Francisco, as we speak, so will not be able to reply again, but, I think this will do if for you!!

Don.

On 15 Apr 2007 07:11:44 -0700, Rob <> wrote:

Thanks for the info. It is a serial port because other routines in the program read data off
the GPS if I manually set the baud rate with "stty -F /dev/ttyAM1 speed 19200" (yes this
GPS is not running 4800). The only two routines that fail are configuration and
read_configuration. On your suggestion to check for errors I added

char err_str[256];

result = tcgetattr (file_id, &options);
if(result != 0)
{
printf("Error of %d calling tcgetattr\n", result);
perror(err_str);
}

I get no reported error but the same bad values.

Thanks for the suggestions so far.
Rob

--- In ts-7000%40yahoogroups.com, "Don W. Carr" <> wrote:
>
> First, always check for errors. Capture the return value, and if it is not 0
> (success), then call perror(), to print the error. You must check errors on
> these types of functions and handle them, otherwise, the bigger the program,
> the more likely that you will have mysterious unknown errors at times that
> you can not figure out. For this particular call, you can not call on any
> old fd, it much be a serial port. You might get the error, not a tty or
> something like that as I recall. As I recall, I typically call isatty() to
> check to see if the fd is valid for setting baud rate, before continuing.
>
> Hope that helps!
>
> Don.
>
>
>
>
> --
> Dr. Don W. Carr
> J. G. Montenegro 2258
> Guadalajara, Mexico
> +52-333-630-0704
> +52-333-836-4500 ext 2930
>




--
Dr. Don W. Carr
J. G. Montenegro 2258
Guadalajara, Mexico
+52-333-630-0704
+52-333-836-4500 ext 2930 __._,_.___


SPONSORED LINKS
Single board computer Hardware Computer running slow
Linux os Single board

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: =Email Delivery: Digest | m("yahoogroups.com?subject","ts-7000-fullfeatured");=Change Delivery Format: Fully Featured">Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | =Unsubscribe

__,_._,___
<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU