Pymodbus 'ModbusIOException'

问题描述

我正在尝试为“Jumo LC100”编写驱动程序,它是我用来读取和控制 Pt100 的 PID 控制器。

我通过 USB>FT232>Max485 通过 Modbus RTU 协议连接了他。 首先,我的程序运行顺利,但现在每次尝试读取值时都会出现 MODbusIO 异常,例如“Temp-ist()”。 设置一个值没问题,比如Temp_soll(30)。

它在开始时有效,但现在我在尝试设置值时一直收到 ModbusIOException。 也许是因为 Jumo 需要

控制器: https://en.jumo.de/web/products/apps/productdetailpage?pdpId=702030

Modbus 说明: https://www.jumo.net/attachments/JUMO/attachmentdownload?id=58923

代码示例:

from time import sleep
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.constants import Endian
import pickle



#Global
conn_state = False

"""Variablen"""

#Serielle connection

baud= 19200                             
#Port= str(input('Port:'))               #'/dev/ttyUSB0' # Port
Port = '/dev/ttyUSB0'
#Geräte
LC100 = 0x01                            #Slave-adress PID-Controller

  

#LC100 register  

temp_ist = 0x0031                       #Controller actual value filterd 32bit register    
temp_soll = 0x0035                      #Controller setpoint 32bit register





"""Serielle Verbindung herstellen"""
def connect(Port):
    global conn_state
    global client 
    client = ModbusClient(method='rtu',port=Port,timeout=2,stopbits=1,bytesize=8,parity='N',baudrate= 19200,strict=False)
    client.connect()
    conn_state = True
    return conn_state

####read values###

#read temperature 
def Temp_ist():
    t = client.read_holding_registers(temp_ist,count=2,unit= LC100)                     #read slave register 
    sleep(0.5)                                                                    
    decoder = BinaryPayloadDecoder.fromregisters(t.registers,byteorder=Endian.Big,wordorder=Endian.Little)   #decode the register into the right order
    v = decoder.decode_32bit_float()    #decode the 2 bytes into a float
    v = round(v,2)                       #round the value to 2 digit after the point
    return v


####write values###

#temperature setpoint
def Temp_soll(t_soll):
    builder = BinaryPayloadBuilder(byteorder=Endian.Big,wordorder=Endian.Little)        #config the builder. bytes not swapped,words swapped
    builder.add_32bit_float(t_soll)                                                     #value is a 32bit float,size of 2 register
    payload = builder.to_registers()                                                    #convert the number into 2 registers
    client.write_registers(temp_soll,payload,unit= LC100)                              #write the value to the slave

我希望我不会缺少任何信息...

谢谢你的帮助,不用我说我对python有点陌生,请原谅我还在学习中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...