Access USB serial ports using Python and pyserial(使用 Python 和 pyserial 访问 USB 串口)
问题描述
如何使用 pyserial 访问 USB 端口?我看过 示例与:
How do I access the USB port using pyserial? I have seen an example with:
import serial
ser = serial.Serial('/dev/ttyUSB0')
我曾经在 Windows 上从 MATLAB 访问串行端口,并使用适当的语法,/dev/ttyUSB0 将替换为 COM1 或任何其他 COM 端口.
I used to access the serial port from MATLAB on Windows and using the appropriate syntax, /dev/ttyUSB0 would be replaced by COM1 or any other COM port.
我在 Mac 上,我尝试使用 串行端口扫描器 在 pyserial 文档上无济于事.我想我应该这样写:
I'm on a Mac and I tried using the serial port scanners on the pyserial documentation to no avail. I think I should write it like this:
import serial
name = ? # Names of serial ports on Mac OS X
ser = serial.Serial(name)
我如何找出 Mac 上的 name 应该是什么?
How do I find out what name should be on a Mac?
针对下面的回答,我想了解如何访问 USB 到 RS232 转换器以及纯 USB 端口.
In response to an answer below, I'd like to find out how to access both USB to RS232 converters as well as pure USB ports.
推荐答案
您只能使用 pyserial(即 USB RS-232 加密狗)访问 USB 串行适配器.如果您想要通用 USB 访问,您应该查看libusb".如果您尝试通过 USB 访问的是 RS-232,那么您应该在/dev 中查找以 cu.usb* 开头的文件(例如/dev/cu.usbserial-181).
You can only access USB Serial Adapters using pyserial (i.e., USB RS-232 dongles). If you want generic USB access you should be looking into "libusb". If it is RS-232 you are trying to access through USB then you should look for a file in /dev starting with cu.usb* (/dev/cu.usbserial-181 for example).
这篇关于使用 Python 和 pyserial 访问 USB 串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Python 和 pyserial 访问 USB 串口
基础教程推荐
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
