繁体   English   中英

Minimalmodbus - 用于 Raspberry Pi 的 RS485 屏蔽

[英]Minimalmodbus - RS485 shield for Raspberry Pi

我正在尝试将 Seeed Studio 的用于 Raspberry PiRS485 屏蔽与 Raspberry Pi 2B 上的 Python Minimalmodbus库连接起来 -不工作!!!

屏蔽:https ://www.seeedstudio.com/RS-485-Shield-for-Raspberry-Pi.html

我在 Raspberry Pi 上测试了以下内容:

  • 如果我使用 Python串行库发送数据,它工作正常。 它打开从设备上的继电器并正确响应。

ser.write('\\xff\\x05\\x00\\x00\\xff\\x00\\x99\\xe4')

  • 如果我为 Python 使用Minimalmodbus库,则它不起作用

instrument.write_bit(0,1,5)

错误: minimalmodbus.NoResponseError:与仪器无通信(无应答)

注意:我在同一个 RPi 上使用另一个 USB-to-RS485 转换器使用了相同的 Minimalmodbus python 代码,并且运行良好。

派顿代码:

import minimalmodbus

import time

import serial 

instrument = minimalmodbus.Instrument('/dev/ttyAMA0', 255)


instrument.serial.baudrate = 9600      
instrument.serial.bytesize = 8
instrument.serial.stopbits = 1
instrument.serial.timeout  = 1          
instrument.mode = minimalmodbus.MODE_RTU  
instrument.clear_buffers_before_each_transaction = True
instrument.debug = True

while 1:
    
    instrument.write_bit(0,1,5)

    time.sleep(5)

错误: minimalmodbus.NoResponseError:与仪器无通信(无应答)

如果我可以将这个特定的 rs485-shield 与 Minimalmodbus 库一起使用,有人可以帮忙吗? 先感谢您

问候,

write_bit函数在消息发送后读取响应。 而 Seeed RS-485 Shield 需要拨动GPIO18引脚来切换读写。 如文档https://wiki.seeedstudio.com/RS-485_Shield_for_Raspberry_Pi/#communication-test-code中的示例代码所示。

通过检查的代码write_bit功能,我不认为有切换该引脚之间的一种简单的方法serial.writeserial.read这些无处注册自己的钩子,并触发引脚有( https://开头github上。 com/pyhys/minimalmodbus/blob/c08208523b729d178a9f662725a69195924f7c34/minimalmodbus.py#L1379 )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM