python - How to read modbus slaves (RTU) connected to a Siemens PAC4200 gateway (TCP) with python?
问题描述
Please note I need to read the meters remote via the network via modbus gateway.
Siemens documentation states gateway can be reached via port 17002 (module 1)
I tried a TCP-client to the server on port 502 which works fine with pymodbus.
Slaves addresses are at 10-24.
a piece of sample code would be great.
解决方案
If you have already connected to the PAC4200's server the gateways to the RS485 bus should be very much the same.
Just change the port, Modbus unit ID and target the registers you want to read.
A bare minimum should look like this:
from pymodbus.client.sync import ModbusTcpClient
host = 'device_IP' # The same you used already for port 502
port = 17002 # for MOD1 slot, use 17003 for MOD2
client = ModbusTcpClient(host, port)
client.connect()
start_reg=0x1 # write starting target register here
number_of_regs=10 # write number of registers to read here
slave_unit=10 # write slave ID of target device here
rr = client.read_holding_registers(start_reg,number_of_regs,unit=slave_unit)
print rr.registers # print registers, change to print(rr.registers) for Python 3.x
I'm not able to infer what devices you are connecting to the RS485 bus. If the sample code above is not working you should double-check the device's Modbus map and the connections to the PAC (see section 6.6 Connecting the PAC RS485 expansion module on the manual).
推荐阅读
- tensorflow - nv-nsight-cu-cli 导致 TensorFlow 失败
- reactjs - Webpack:“有多个模块的名称只是大小写不同”但引用的模块是相同的“但我找不到错字
- rest - 如何在 drupal 8 的 Rest 视图中显示文章的选定分类
- push-notification - 在 Actions on Google 中向其调用意图发送推送通知标题
- c# - 使用任务并行库时如何修复跨线程错误?
- php - 我在托管服务中做 curl 有问题(godaddy)
- c++ - 与 QGIS C++ API 斗争
- c - 编译时出错,collect2: 找不到 ld
- azure - 通过流量管理器 URL 访问网站时出现错误 404
- c# - 在 ASP.Net MVC 中没有身份验证的个人用户帐户