python - Raspberry Pi 零 W 串行通信
问题描述
我刚得到一个 RPI 零 w,我想通过串行通信与设备通信。我还有一个MAX232 板和一个RS232 TTL 转换器。我想使用其中一个板来与该设备通信,因为我读到的内容我不能直接使用 RPI 的串行引脚来添加我需要的奇偶校验位。
我已经尝试了很多事情来让它工作,但似乎我做的事情是错误的,无法弄清楚。代码在 python 中,如果我使用 USB 串行转换器,效果很好。
import time
import serial
import binascii
import re
ser = serial.Serial(
port = '/dev/ttyAMA0',
baudrate = 19200,
parity = serial.PARITY_MARK,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = 2
)
while True:
print("Connected to: " + ser.name)
counters = [0x01,0x0F]
ser.write(counters)
a = ser.read(30)
state = binascii.hexlify(a)
asd = re.sub(rb'([0-9, a-z, A-Z])(?!$)', rb'\1,', state)
print(asd)
这就是我正在使用的代码,我没有得到任何数据。
我是所有这些东西的初学者,但我希望有人可以帮助我完成这项工作。
解决方案
推荐阅读
- c# - Blazor LiteDB 查询问题
- c# - 使用工作单元和存储库模式与 MVC 的 Autofac 关系问题
- java - 在不使用 Time Zone API 的情况下从用户的当前地理位置获取时区
- c - 试图从汇编程序(64 位)的 glibc 调用 C 函数
- css - 如何“打破”引导布局然后打印?
- python - 改组 itertools.permutation(range(15)) 时出现 Python OOM 错误
- android - 如何在 Android 的操作栏上方显示自定义视图
- html - CSS - 调用元素 [attribute^=value] 后未应用边框 X 颜色的原因
- collision-detection - 多物体碰撞检测与响应
- python - Python 在不断更新单独的窗口时诅咒字符串输入?