首页 > 解决方案 > 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)

这就是我正在使用的代码,我没有得到任何数据。

这些是我建立的联系

我是所有这些东西的初学者,但我希望有人可以帮助我完成这项工作。

标签: pythonserial-communicationraspberry-pi-zero

解决方案


推荐阅读