How to set the baud rate for Macs in a terminal

28,151

Solution 1

On Mac OS, stty seemingly can only change terminal settings for an ongoing access.

It works to either:

  • Access the serial interface, e.g. cat /dev/cu.usbserial, the default settings will be used at first. On a different terminal use stty, e.g. stty -f /dev/cu.usbserial 230400 to set the baud rate, the settings of the terminal accessed before will change.

  • There is a small time window after executing stty, in which the access can be performed with the desired parameters, e.g. stty -f /dev/cu.usbserial 230400 & cat /dev/cu.usbserial executes stty, detaches it and then immediately performs the access to the serial device.

  • For one line command logging serial port /dev/tty.usbserial-X's output to cat.out and terminating the logging by pressing Ctrl+C, here is the solution: trap 'kill $(jobs -p)' SIGINT ; cat /dev/tty.usbserial-X | tee cat.out & stty -f /dev/tty.usbserial-X 115200. You can type Ctrl+C to terminate logging to cat.out. (edited)

This only seems to work for the /dev/cu.* device files. I don't know the difference from /dev/tty.* files.

Solution 2

Minicom is an excellent tool that does exactly what you're asking for. You can get it using apt on ubuntu but should check this Tutorial out for Mac.

Keep the serial reset issue in mind if you plan on sending data to the Arduino. see http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

Share:
28,151

Related videos on Youtube

luca590
Author by

luca590

Lots and lots of interests...

Updated on November 24, 2021

Comments

  • luca590
    luca590 over 2 years

    Is it possible to set the baud rate for Macs in a terminal? If yes, how to set the baud rate in terminal through the terminal?

    I am trying to talk to the Mac using an Arduino (open source microcontroller), an XBee (wireless communicator) to type in the terminal through the serial monitor. The only problem I am having is the baud rate of the serial monitor and terminal are different. I can easily change the baud rate for the serial monitor in the Arduino, but I do not know what the baud rate is for the terminal in Mac.

    • luca590
      luca590
      Well what i am trying to do is talk to the mac using an arduino (open source microcontroller), an xbee (wireless comunicator) to type in terminal through the serial monitor. The only problem i am having is the baud rate of the serial monitor and terminal are different. I can easily change to baud rate in the serial monitor but i do not know how to change the baud rate in the terminal.
  • luca590
    luca590 almost 13 years
    you cant set them this command only allows you to see them. When trying to set the baud rate i get illegal option
  • clt60
    clt60 almost 13 years
    now checked it thru null modem cable and serial port. stty can set the baud rate.
  • Jeff
    Jeff over 10 years
    That would be great, except it doesn't work: > stty -f /dev/tty.usbserial-A96HPNJJ speed 115200 9600 > stty -f /dev/tty.usbserial-A96HPNJJ speed 9600 baud; lflags: -icanon -isig -iexten -echo iflags: -icrnl -ixon -ixany -imaxbel -brkint oflags: -opost -onlcr -oxtabs cflags: cs8 -parenb
  • Jeff
    Jeff over 10 years
    Sorry for the formatting problems. I couldn't get it to format terminal output.
  • Stefan D.
    Stefan D. about 8 years
    I was looking for a solution to this problem for MONTHS! Your solution did it for me. I am using screen to connect to a dev board with 460800 Baud. The first way (using two terminals) you provided didn't work (device busy). But the second one with sending stty to the background did work: stty -f /dev/cu.usbserial-141A 460800 & screen /dev/cu.usbserial-141A 460800
  • Stefan D.
    Stefan D. about 8 years
    I should add that screen or any other terminal program usually doesn't have problems to set the proper baudrate. But there seems to be a bug in OSX that normally doesn't allow to set baudrates higher than 230400. The problem is independent of the terminal program and the driver that is used. I wrote about it here. But with your second solution it is possible to use these higher baudrates. Thanks again!
  • Micha Herrmann
    Micha Herrmann over 4 years
    discussions.apple.com/thread/3798003?tstart=0 "(...)In OS X and other versions of UNIX, closing the serial port restores it to its default settings. (...)"
  • Lewis Peel
    Lewis Peel almost 4 years
    I tried this on macOS Catalina but it didn't work, maybe they changed something?
  • Abhishek Dutt
    Abhishek Dutt over 2 years
    This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Related