macos 如何在终端中为 Mac 设置波特率
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5539192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set the baud rate for Macs in a terminal
提问by luca590
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?
是否可以在终端中为 Mac 设置波特率?如果是,如何通过终端设置终端的波特率?
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.
我正在尝试使用Arduino(开源微控制器)和XBee(无线通信器)与 Mac 对话,以通过串行监视器在终端中输入内容。我遇到的唯一问题是串行监视器和终端的波特率不同。我可以轻松更改 Arduino 中串行监视器的波特率,但我不知道 Mac 中终端的波特率是多少。
回答by jon911
On Mac OS, stty
seemingly can only change terminal settings for an ongoing access.
在 Mac OS 上,stty
似乎只能更改终端设置以进行持续访问。
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 usestty
, 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
executesstty
, 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 tocat.out
and terminating the logging by pressingCtrl+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 typeCtrl+C
to terminate logging tocat.out
. (edited)
访问串行接口,例如
cat /dev/cu.usbserial
,首先使用默认设置。在不同的终端使用stty
,例如stty -f /dev/cu.usbserial 230400
设置波特率,之前访问的终端的设置会改变。执行后有一个很小的时间窗口
stty
,在该窗口中可以使用所需的参数执行访问,例如stty -f /dev/cu.usbserial 230400 & cat /dev/cu.usbserial
执行stty
,将其分离,然后立即执行对串行设备的访问。对于一行命令将串行端口
/dev/tty.usbserial-X
的输出cat.out
记录到并通过按 终止记录Ctrl+C
,这里是解决方案:trap 'kill $(jobs -p)' SIGINT ; cat /dev/tty.usbserial-X | tee cat.out & stty -f /dev/tty.usbserial-X 115200
。您可以键入Ctrl+C
以终止记录到cat.out
. (已编辑)
This only seems to work for the /dev/cu.*
device files. I don't know the difference from /dev/tty.*
files.
这似乎只适用于/dev/cu.*
设备文件。我不知道与/dev/tty.*
文件的区别。
回答by ZnArK
Minicomis an excellent tool that does exactly what you're asking for. You can get it using apt on ubuntu but should check this Tutorialout for Mac.
Minicom是一款出色的工具,可以完全满足您的要求。你可以在 ubuntu 上使用 apt 来获得它,但应该在 Mac 上查看这个教程。
Keep the serial reset issue in mind if you plan on sending data to the Arduino. see http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection
如果您计划向 Arduino 发送数据,请记住串行重置问题。见http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection
回答by jm666
stty 19200or so.
stty 19200左右。
Check man stty
, you can set stop bits, speed, etc.
勾选man stty
,可以设置停止位、速度等。