根据这个howToModbusSlave,我正在尝试使用所选值的寄存器构建我自己的modbus从站(稍后我想使用python / jython用来自受监控设备的数据填充这些值)并使用Predix(云平台)将它们发送出去。由于我是一个 modbus 新手,我仍然无法找到如何将我选择的值添加到我的寄存器持有者中的方法。
这是我用来在 localhost:502 上为 Master 提供数据的 Slave 线程:
public class SimpleApp {
public static void main(String args[]) {
try {
//1. The important instances and variables
ModbusTCPListener listener = null;
SimpleProcessImage spi = null;
int port = 502;
//2. Prepare a process image
spi = new SimpleProcessImage();
//I dont understand this part, why do i need it?
spi.addDigitalOut(new SimpleDigitalOut(true));
spi.addDigitalOut(new SimpleDigitalOut(false));
spi.addDigitalIn(new SimpleDigitalIn(false));
spi.addDigitalIn(new SimpleDigitalIn(true));
spi.addDigitalIn(new SimpleDigitalIn(false));
spi.addDigitalIn(new SimpleDigitalIn(true));
//setting up register holders, gonna ask no 10,11,20 and 21 as set in the data node config
for (int i = 0; i < 25; i++) {
int value = 15;
SimpleInputRegister sr = new SimpleInputRegister(value);
spi.addRegister(sr);
}
//3. Set the image on the coupler
ModbusCoupler.getReference().setProcessImage(spi);
ModbusCoupler.getReference().setMaster(false);
ModbusCoupler.getReference().setUnitID(15); //15
//4. Create a listener with 3 threads in pool
listener = new ModbusTCPListener(1); //no of threads
listener.setPort(port);
listener.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
数据节点配置:
<channel protocol="TCP_IP" tcpIpAddress="127.0.0.1" tcpIpPort="502">
<unit id="1">
<register name="Node-1-1" dataType="INTEGER" address="10" registerType="HOLDING" description="temperature"/>
<register name="Node-1-2" dataType="DECIMAL" address="11" registerType="HOLDING" description="pressure"/>
</unit>
<unit id="2">
<register name="Node-2-1" dataType="INTEGER" address="20" registerType="HOLDING" description="temperature"/>
<register name="Node-2-2" dataType="INTEGER" address="21" registerType="HOLDING" description="pressure"/>
</unit>
</channel>
我得到这些转移(“输出”):
[{"address":"com.ge.dspmicro.machineadapter.modbus://127.0.0.1:502/2/20","datatype":"INTEGER","name":"Node-2-1","category":"REAL","value":655370,"timestamp":1464006550991,"quality":"NOT_SUPPORTED (20000000) "},
{"address":"com.ge.dspmicro.machineadapter.modbus://127.0.0.1:502/1/10","datatype":"INTEGER","name":"Node-1-1","category":"REAL","value":655370,"timestamp":1464006550992,"quality":"NOT_SUPPORTED (20000000) "}]
主要问题:
1) 节点 1-2 和 2-2 的数据在哪里(输出中缺失)?
2)如何编辑从寄存器发送的值?(为什么我得到“价值”:655370?)
可选问题:(我在文档中不理解的东西)
3) simpleDigitalOut/In 类代表什么?
4) ModbusCoupler.getReference().setUnitID(value) 代表什么?(它显然不必与数据节点的 unitID 做任何共同的事情
5) SimpleInputRegister 和 SimpleRegister 类有什么区别?