首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >树莓Pi的最小RS485屏蔽

树莓Pi的最小RS485屏蔽
EN

Stack Overflow用户
提问于 2020-11-19 17:30:48
回答 1查看 1.1K关注 0票数 0

我正在尝试将Seeed Studio的RS485屏蔽用于Raspberry Pi,以及Raspberry Pi2B上的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')

如果我将Minimalmodbus库用于Python,则无法工作。

instrument.write_bit(0,1,5)

错误: minimalmodbus.NoResponseError:没有与仪器通信(没有回答)

注意:我在同一个RPi上使用了相同的Minimalmodbus python代码,使用了另一个USB到to 485转换器,它工作得很好。

Pyhton代码:

代码语言:javascript
复制
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:没有与仪器通信(没有回答)

如果我能用这个特定的if 485屏蔽和Minimalmodbus库,有人能帮忙吗?提前谢谢你

致以敬意,

EN

回答 1

Stack Overflow用户

发布于 2020-12-02 14:26:39

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

通过检查write_bit函数的代码,我不认为有一种简单的方法可以在serial.writeserial.read之间切换这个引脚,这不是注册自己的钩子和切换pin那里(https://github.com/pyhys/minimalmodbus/blob/c08208523b729d178a9f662725a69195924f7c34/minimalmodbus.py#L1379)的地方。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64916936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档