2017-06-19 473 views
0

我已經創建了modbus從站來將數據寫入寄存器。 我能夠從從端寫入浮點值和整數值。MODBUS-tk讀取主站中從站的浮點值

在modbus master中,我只能訪問整數值但不能讀取浮點值。

我經歷了這個https://github.com/ljean/modbus-tk/issues/72但這並沒有解決我的問題。

對於讀取的整數值,我可以使用下面的代碼並讀取值。

master = modbus_tcp.TcpMaster() 
master.set_timeout(time_out_period) 
result = master.execute(slave = 100, function_code = 3 , starting_address = 0, quantity_of_x = 25) 

但是,對於float值,我使用了上面和下面的代碼。

master = modbus_tcp.TcpMaster() 
master.set_timeout(time_out_period) 
result = master.execute(slave = 100, function_code = 3 , starting_address = 0, quantity_of_x = 25 , data_format='>f') 

我得到錯誤而讀浮子如,

解壓縮需要長度的字節對象4

+0

什麼是你試圖寫的浮點值? – Sanju

回答

0

x的量應該是2的倍數。由於浮需要兩個16位寄存器或字,所以如果你想要25它應該是50.