Skip to contentSkip to conversation

serial port programming question (newbie)

DISCUSSION Donna Rigas 2 participants 3 messages Jan 18, 2011

lore
Share & tools
lore
#0 lore raw

I see lots of serial port programming examples where the port settings are saved before being changed to the desired settings, then restored to the original before exiting the program via tcgetattr and tgsetattr.

I see one example where someone comments that this is not necessary.

Can someone tell me whether or not it is necessary to save and restore the old settings and if so, why?

#1 lore raw

serial port programming second question (newbie)

Also, if your call to tcsetattr fails, or if the ioctl call to set the baud rate fails, does it matter if you restore the serial port settings or not?

Quoted 1 line
#2 lore raw

Re: serial port programming second question (newbie)

Quoted 3 lines · On Mon, 17 Jan 2011 16:41:38 -0800 Donna Rigas <[email protected]> wrote:

Also, if your call to tcsetattr fails, or if the ioctl call to set the baud rate fails, does it matter if you restore the serial port settings or not?

If they fail the returned struct contains the settings you ended up with, eg the baud rate you actually got. Older kernels didn't get that detail right but current ones do. Generally they will try and pick a nearest suitable rate.

Alan