Linux c modbus 线程,Modbus TCP Slave Thread - 设置和获取寄存器值

根据这个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类有什么区别?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值