根据这个howToModbusSlave,我尝试用所选值的寄存器来构建我自己的modbus从服务器(稍后,我想用使用python/jython的监视设备中的数据填充这些值),并使用Predix (云平台)将它们发送出去。由于我是一个modbus新手,我仍然找不到一种方法来添加我选择的价值到我的注册持有人。
下面是我用来为localhost上的主服务器提供数据的my Slave线程: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();
}
}
}数据节点配置:
<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?)
可选的问题:(在http://jamod.sourceforge.net/api/net/wimpi/modbus/procimg/Register.html中我不理解的东西)
3)这个类简单表示什么?
4) ModbusCoupler.getReference().setUnitID(value)代表什么?(显然,它不必与数据节点的unitID有任何共同之处。
5) SimpleInputRegister和SimpleRegister类有什么区别?
发布于 2016-09-15 16:53:06
这是一个部分的答案:
1)需要将节点添加到dataSubscriptionConfig文件中的下面的config.xml标记中
2)下面是设置值的位置:int value = 15; --需要实现一种发送动态值的方法
https://stackoverflow.com/questions/37391978
复制相似问题