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

查看:412
本文介绍了如何在终端中为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.

它可以执行以下操作之一:

It works to either:

  • 访问串行接口,例如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天全站免登陆