python - 在 Python 中从 ttl rs485 转换器读取数据
问题描述
我试图使用连接到 PC 的 ttl rs485 转换器和 ft232 串行转换器从智能电表读取数据。我尝试使用 Pyserial python 模块从串口读取数据并使用下面的代码,但我得到的唯一输出是(“b,”b,“,b),我想知道是否有任何错误在我的代码中!谢谢。
我使用的代码
import serial
ser = serial.Serial(
port= 'COM5',
baudrate= 9600,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout= 2
)
print("connected to: " + ser.portstr, "Please wait" )
print('COM5 is now Open!')
ser.flushInput()
ser.flushOutput()
while True:
data = ser.readline()
print(data)
我得到的输出
connected to: COM5 Please wait
COM5 is now Open!
b''
b''
b''
b''
b''
解决方案
推荐阅读
- html - 在桌面和移动设备的页面上设置不同的字体大小
- javascript - 将逗号分隔的输入转换为 JSON
- sql-server - ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION - 在 while 循环内调用过程时
- python - 初学者 python 程序员对 pandas 和 sklearn 有一些问题
- python - 如何将 TensorFlow pb/ckpt 模型分成两部分?/ 如何去除 TensorFlow pb 模型的前端节点
- javascript - 将页眉/页脚添加到使用 msSaveOrOpenBlob 函数的文件导出
- sql - 给出特定产品或项目的条件总和
- bash - bash:多次运行 sed -i
- python - 层 max_pooling2d_15 的输入 0 与层不兼容:预期 ndim=4,发现 ndim=7。收到的完整形状:(无、100、100、1、1、1、96)
- java - 更改 Spring Security 浏览器中显示的端点