tech-userlevel archive

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

Re: C tty/tcsetattrs question

On Fri, May 27, 2016 at 03:37:03AM +0000, David Holland wrote:
> On Thu, May 26, 2016 at 07:30:05PM +0200, Manuel Bouyer wrote:
>  > I have a GPS device connected to a serial port. It defaults to 9600bps
>  > NMEA messages, but I need to switch it to 4800bps. There are NMEA
>  > commands for this, and I can properly do this using cu(1).
>  > 
>  > Now I'm trying to write a program to do this at boot time.
>  > First I need to determine if the GPS is outputting at 4800 or 9600bps
>  > (the CPU may be rebooted, or even powered off wihout resetting the GPS
>  > module).
>  > I wrote the attached C program, but the cfsetspeed() doesn't seem
>  > to have any effect: with the GPS running at 9600bps,
>  > if I start with the tty set to 9600 (for example from a previous
>  > cu(1) run) I get proper NMEA sentences on both check_term() calls,
>  > and if I start with the tty set to 4800 (e.g. from a previous
>  > cu(1) run) I get either nothing or garbage (not getting anything
>  > from the tty is a valid case, as the tty is in canon mode select()
>  > will return a read event only if the serial port got something that
>  > looks like a line).
>  > 
>  > Does anyone see an obvious error or something I missed ?
> No, but some things to check:
> (1) When you have this program change the speed, does the speed change
> register? If you call tcgetattr right after, what's the speed
> returned? And what do you see if if you use stty?

stty returns the expected speed, so I guess the kernel has the right speed.
But this may be cached somewhere; I'll add some debug printf in the
com driver to make sure.

> (2) Is the behavior different if you specify TCSANOW instead of TCSAFLUSH?
> (It shouldn't be, but...)

will try.

> (3) why are you turning on ICANON?

Because NMEA is a line-oriented protocol, so having select() wake up when
a whole line is ready to be read is easier to deal with.
But for test I could run with ICANON off.

Manuel Bouyer <>
     NetBSD: 26 ans d'experience feront toujours la difference

Home | Main Index | Thread Index | Old Index