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 串口
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
