作者popo14777 (草草)
看板Python
标题仪器modbus RTU通讯问题
时间Fri Oct 21 21:49:49 2022
各位大大、前辈好
我想要使用python来与仪器进行通讯,设备商有提供modbus RTU指令集,
内容包含modbus RTU通讯设定,以及通讯地址,如下
https://imgur.com/rJcfijX
https://imgur.com/pR0FF4o
https://imgur.com/9kRTjdg
我使用三种方式进行通讯,但不知道为什麽都无法将值读取出来
方式1:使用pymodbus
结果1:地址输入40051或40062或其它值,抛出AttributeError例外
https://imgur.com/1oxM1YD
结果2:地址输入40051或40062或其它值,出现Modbus Error讯息
https://imgur.com/DlXnY8m
方式2:使用modbus_tk
结果:地址输入40053或40062或其它值,出现Response length invalid 0 讯息
https://imgur.com/Sf4KgLR
https://imgur.com/Sf4KgLR
https://imgur.com/Sf4KgLR
https://imgur.com/Sf4KgLR
https://imgur.com/Ag851s9
https://imgur.com/pbTOQVQ
方式3:使用minimalmodbus
结果: 地址输入40053或40060或其它值,抛出ValueError例外
https://imgur.com/lIDf1tH
https://imgur.com/Dz1Bblk
不知道我哪里写错或设定错误,研究好久了..恳求前辈帮忙,
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 42.73.221.228 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1666360191.A.DD4.html
1F:→ lycantrope: 连怎麽错误都还没弄清楚,就换其他package...10/21 23:13
2F:推 a9202507: 我家lab仪器都是gpib接头. 然後用pyvisa控制。10/22 10:55
请问贵家的仪器是?
3F:推 timsheu: minimalbus有一个能试试看,你填的40060变成了0x4006010/22 16:20
4F:→ timsheu: 也就是错误里写的26224010/22 16:21
5F:→ timsheu: 也就是错误里写的26224010/22 16:21
了解,40060是16进制,转成10进制就是262240了,
所以我地址要输入9C7C(16进制),输出才会是40060(10进制)吗?
※ 编辑: popo14777 (118.161.145.189 台湾), 10/22/2022 22:26:48
我刚看了API,read_register()方法第一个参数输入10进位的值,
第二个参数输入小数位数,第三个参数输入有无符号,
read_register(40096, 1, 3, signed = False)
不晓得这样正不正确?
API网址
https://minimalmodbus.readthedocs.io/en/stable/apiminimalmodbus.html
※ 编辑: popo14777 (118.161.145.189 台湾), 10/23/2022 00:07:31
※ 编辑: popo14777 (118.161.145.189 台湾), 10/23/2022 07:43:25
6F:推 a9202507: 我家仪器功能可能跟你不同。但我以为gpib是通用的… 10/23 10:55
7F:推 ccss701: 前面的400不要呢? pymodbus的unit是站号 10/23 22:08
8F:→ ccss701: client.read_holding_registers(61, 1, unit=3) 10/23 22:08
c大,一样回传modbus error的讯息
https://imgur.com/DlXnY8m
还是是连接器的问题?
https://imgur.com/3d3NY7n 我是买这条
※ 编辑: popo14777 (118.161.104.235 台湾), 10/26/2022 22:28:56
9F:推 hidos: 开port之後延迟一下再丢读取command看看 11/29 16:46