Reading data from serial port (COM3) using pyserial module on Windows XP

北战南征 提交于 2019-12-11 11:59:57

问题


Before going into the problem, here is some hardware/software information:

Device accessed: Ohaus Scout Pro Digital Weight Machine (product link) Interface used: USB (product link) Serial Port: COM3 OS: WinXP Python Version: Activestate Python 2.7 pyserial version: 2.5

Python recognized this serial port and had no problems opening it. I am new to python as well as pyserial. I couldn't figure out how exactly can I read data from the serial port. I used the following code:

1 import serial
2 ser=serial.Serial(port='COM3',timeout=3)
3 s=ser.read(100) #reading up to 100 bytes
4 print s

This prints nothing. During those 3 seconds timeout, I placed an object on the weighing machine and it showed 100grams on the machine. But, this data is not showing on the computer. How can I read this data using pyserial?


回答1:


The baudrate is missing. You must specify baudrate. Most serial devices can not tolerate a wrong communication speed.



来源:https://stackoverflow.com/questions/5602349/reading-data-from-serial-port-com3-using-pyserial-module-on-windows-xp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!