tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: C tty/tcsetattrs question
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?
(2) Is the behavior different if you specify TCSANOW instead of TCSAFLUSH?
(It shouldn't be, but...)
(3) why are you turning on ICANON?
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index