Modbus TCP 从属线程 - set & get 寄存器值



根据ToModbusSlave的操作方式,我正试图用所选值的寄存器构建我自己的modbusSlave(稍后我想使用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) ModbusCouple.getReference().setUnitID(value)代表什么?(它显然不需要与数据节点的unitID做任何共同的事情

5) SimpleInputRegister和SimpleRegister类之间的区别是什么?

这是部分答案:

1) 您需要将节点添加到下面config.xml文件中的dataSubscriptionConfig标记中

2) 这里是您设置值的地方:int value = 15;-您需要实现一种发送动态值的方法

最新更新