根据这个howToModbusSlave我试图用选定值的寄存器构建我自己的modbus slave(后来我想用来自使用python / jython的受监视设备的数据填充这些值),并使用Predix(云平台)将它们发送出去。由于我是modbus新手,我仍然无法找到如何将我选择的值添加到我的注册持有人的方法。
以下是我用于在localhost上为Master提供数据的从属线程:502:
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();
}
}
}数据节点配置:
我得到这些传输(“输出”):
[{"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?)
可选的Qustions :(我在documentation中不理解的东西)
3)simpleDigitalOut / In代表什么类?
4)ModbusCoupler.getReference()。setUnitID(value)代表什么? (它显然不需要做与数据节点的unitID相同的任何事情
5)SimpleInputRegister和SimpleRegister类有什么区别?