Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用于覆盆子Pi的最小Modbus-RS485屏蔽_Python_Raspberry Pi_Modbus_Rs485_Minimalmodbus - Fatal编程技术网

Python 用于覆盆子Pi的最小Modbus-RS485屏蔽

Python 用于覆盆子Pi的最小Modbus-RS485屏蔽,python,raspberry-pi,modbus,rs485,minimalmodbus,Python,Raspberry Pi,Modbus,Rs485,Minimalmodbus,我正在尝试连接Seeed Studio的Raspberry Pi的RS485屏蔽以及Raspberry Pi 2B上的PythonMinimalmodbus库-不工作 盾牌: 我在树莓皮上测试了以下内容: 如果我使用Python串行库发送数据,效果很好。它打开从设备上的继电器并正确响应 ser.write('\xff\x05\x00\x00\xff\x00\x99\xe4') 如果我使用Python的库,它将不起作用 仪器。写入位(0,1,5) 错误:最小Modbus.NoRespons

我正在尝试连接Seeed Studio的Raspberry Pi的RS485屏蔽以及Raspberry Pi 2B上的PythonMinimalmodbus库-不工作

盾牌:

我在树莓皮上测试了以下内容:

  • 如果我使用Python串行库发送数据,效果很好。它打开从设备上的继电器并正确响应
ser.write('\xff\x05\x00\x00\xff\x00\x99\xe4')

  • 如果我使用Python的库,它将不起作用
仪器。写入位(0,1,5)

错误:最小Modbus.NoResponseError:与仪器无通信(无应答)

注意:我在同一个RPi上使用了另一个USB-to-RS485转换器,使用了相同的Modbus python代码,效果很好。

Pyton代码:

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)
错误:最小Modbus.NoResponseError:与仪器无通信(无应答)

如果我可以将这个特定的rs485屏蔽与Modbus库一起使用,有人能帮忙吗? 先谢谢你


在这方面,

在发送消息后,
write\u bit
函数正在读取响应。Seeed RS-485屏蔽需要切换
GPIO18
引脚以在读写之间切换。如文档中的示例代码所示

通过检查
write_位
功能的代码,我认为在
serial.write
serial.read
之间切换插脚不是一个简单的方法,因为没有地方注册自己的钩子并在那里切换插脚()