如何在终端中为 Mac 设置波特率 [英] How to set the baud rate for Macs in a terminal

查看:41
本文介绍了如何在终端中为 Mac 设置波特率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在终端中为 Mac 设置波特率?如果是,如何通过终端设置终端的波特率?

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?

我正在尝试使用 Arduino(开源微控制器)与 Mac 对话,这是一个XBee(无线通信器)通过串行监视器输入终端.我遇到的唯一问题是串行监视器和终端的波特率不同.我可以轻松更改 Arduino 中串行监视器的波特率,但我不知道 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.

推荐答案

在 Mac OS 上,stty 似乎只能更改正在进行的访问的终端设置.

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

它适用于:

  • 访问串行接口,例如cat/dev/cu.usbserial,首先会使用默认设置.在不同的终端上使用 stty,例如stty -f/dev/cu.usbserial 230400 设置波特率,之前访问的终端设置会发生变化.

  • 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.

在执行 stty 后有一个小的时间窗口,在该窗口中可以使用所需的参数进行访问,例如stty -f/dev/cu.usbserial 230400 &cat/dev/cu.usbserial 执行stty,将其分离,然后立即执行对串行设备的访问.

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.

对于一行命令记录串行端口 /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.(已编辑)

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)

这似乎只适用于 /dev/cu.* 设备文件.我不知道与 /dev/tty.* 文件的区别.

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

这篇关于如何在终端中为 Mac 设置波特率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆