Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

stty baud rate setting not working

Hi,


I am fiddling with an FTDI chip based USB-serial converter. I need to run the device in 19K2 mode and am using the php-serial class to communicate with the device.

PHP-serial uses stty to change communication settings. Changing the default 9600 baud into 19200 does not seem to work. This is reported numerous times reagrding the OSX version of stty. Is it me (us) or is there really a bug in stty?


stty -f /dev/cu.usbserial-000012FD gfmt1:cflag=4b00:iflag=0:lflag=0:oflag=0:discard=f:dsusp=19:eof=4:eol=ff:eol2=f f:erase=7f:intr=3:kill=15:lnext=16:min=1:

quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=19 200:ospeed=19200


returns:

9600


so does:

stty -f /dev/cu.usbserial-000012FD speed 19200

9600


btw screen works fine, and so does librxtxSerial.jnilib



Ronald

Mac OS X (10.7.3)

Posted on Mar 11, 2012 6:45 AM

Reply
Question marked as Best reply

Posted on Mar 11, 2012 7:48 AM

This is one of those situations where Linux has the non-standard behaviour, but because it is so popular, people think there is some bug in the Mac. In OS X and other versions of UNIX, closing the serial port restores it to its default settings. Linux does not do that. Here is a suggestion for getting it to work in FreeBSD that should work on the Mac too: http://www.clearchain.com/blog/posts/using-serial-devices-in-freebsd-how-to-set- a-terminal-baud-rate

3 replies
Question marked as Best reply

Mar 11, 2012 7:48 AM in response to ronaldleenes

This is one of those situations where Linux has the non-standard behaviour, but because it is so popular, people think there is some bug in the Mac. In OS X and other versions of UNIX, closing the serial port restores it to its default settings. Linux does not do that. Here is a suggestion for getting it to work in FreeBSD that should work on the Mac too: http://www.clearchain.com/blog/posts/using-serial-devices-in-freebsd-how-to-set- a-terminal-baud-rate

Mar 11, 2012 10:14 AM in response to ronaldleenes

I think the standard way to do this is to include the stty command in a redirect. Then, when you feed data to it, it will be send using the parameters you specify. You would do something like:


/usr/local/bin/myprogram > stty -f /dev/cu.usbserial-000012FD speed 19200


Another alternative is to just do it in C. Back when all of this was designed, shells weren't as powerful as they are today.

stty baud rate setting not working

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.