在 Windows XP 上使用 pyserial 模块从串口(COM3)读取数据 [英] Reading data from serial port (COM3) using pyserial module on Windows XP

查看:106
本文介绍了在 Windows XP 上使用 pyserial 模块从串口(COM3)读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进入问题之前,这里有一些硬件/软件信息:

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

访问的设备:Ohaus Scout Pro 数字称重机(产品链接)使用的接口:USB(产品链接)串口:COM3操作系统:WinXPPython 版本:Activestate Python 2.7pyserial 版本:2.5

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 识别出这个串口并且打开它没有问题.我是 python 和 pyserial 的新手.我无法弄清楚如何从串行端口读取数据.我使用了以下代码:

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

这不会打印任何内容.在这 3 秒的超时时间内,我将一个物体放在称重机上,它在机器上显示 100 克.但是,此数据未显示在计算机上.如何使用 pyserial 读取这些数据?

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?

推荐答案

缺少波特率.您必须指定波特率.大多数串行设备不能容忍错误的通信速度.

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

这篇关于在 Windows XP 上使用 pyserial 模块从串口(COM3)读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆