问题描述
我们有一个电机控制器,它实现了一个 USB->Virtual COM 端口,该端口具有固定的 921600 波特率(手册甚至指出不能更改波特率).我发现如果我使用像Terminal这样的终端程序,我可以通过921600的自定义波特率并且与仪器通信没有问题.我们使用的是 Windows 7 专业版,64 位版本.
We have a motor controller that implements a USB->Virtual COM port that has a fixed baud rate of 921600 (the manual even states that the baud rate cannot be changed). I found that if I use a terminal program like Terminal, I can pass the custom baud rate of 921600 and communicate with the instrument with no issues. We are using Windows 7 pro, 64-bit version.
但是,当我尝试使用 Python 2.7.10(32 位)在 PySerial(v.2.7)中执行此操作时:
However, when I tried to do this in PySerial (v.2.7) using Python 2.7.10 (32 bit) like this:
import serial
ser = serial.Serial("COM3",921600)
我总是遇到错误说参数不正确.
I always encounter error saying that parameter is incorrect.
文件C:\Python27\lib\site-packages\serial\serialwin32.py",第 202 行,在 _reconfigurePortraise ValueError("无法配置端口,某些设置错误.原始消息:%r" % ctypes.WinError())值错误:无法配置端口,某些设置错误.原消息:WindowsError(87, '参数不正确.')
有效波特率似乎是 serialwin32.py 中列出的波特率
The valid Baudrates seem to be the one listed in serialwin32.py
BAUDRATES = (50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
9600, 19200, 38400, 57600, 115200)
当我使用列表中的任何波特率时,我可以打开串行端口(但不需要能够与仪器通信).
When I use any of the baud rate from the list there I can open the serial port (but not necessary able to communicate with the instrument).
在 serialwin32.py 中将 921600 加到这个列表中没有任何作用.我搜索了几个论坛和网站,到目前为止似乎没有人知道如何在 Windows 中设置更高的波特率.115200 以上的波特率过去在旧版本的 Windows 中是不可靠的,但我认为 Windows 7 现在应该能够处理更高的传输速率,尤其是许多 USB IC(如 FTDI 和 CH430)可以处理比 115200 高得多的波特率.
Just adding 921600 hundred to this list in serialwin32.py doesn't do anything. I have searched several forums and websites and so far nobody seems to have an answer on how to set this higher baud rate in Windows. The baudrate above 115200 used to be unreliable in older versions of Windows, but I assume that Windows 7 should be able to handle a much higher transfer rate now especially that many USB IC like FTDI and CH430 can handle a much higher baud rate than 115200.
有没有人知道在 Windows 中让 pySerial 接受比 115200 更高的波特率的方法?
Does anyone know a way to get pySerial to accept a higher baudrate than 115200 in Windows?
推荐答案
我试过 921600 没有任何问题.
I try 921600 and haven't any problem.
您的适配器不支持高速 rs232.
Your adapter not supported high speed rs232.
您需要购买 CP21XX 或同等转换器.
You need buy a CP21XX or equal converter.
Moxa 或 Lantronix 是不错的品牌(测试和使用).
Moxa or Lantronix is good brand(test & using).
试试:win7x64,Python2.7x32
Try on: win7x64,Python2.7x32
这篇关于如何让 PySerial 接受 921600 波特率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!