我使用JAMOD和android来读取modbus的数据。我有一个奴隶和一个主类。(奴隶运行在netbeans中)
triing与android连接,得到标题中的错误消息。你能帮我纠正我的应用程序吗?
import net.wimpi.modbus.Modbus;
import net.wimpi.modbus.ModbusCoupler;
import net.wimpi.modbus.net.ModbusTCPListener;
import net.wimpi.modbus.procimg.*;
public class Modbus_slave_server {
public static void main(String[] args) {
ModbusTCPListener listener = null;
SimpleProcessImage spi = new SimpleProcessImage();
int port = Modbus.DEFAULT_PORT;
if (Modbus.debug) {
System.out.println("jModbus Modbus TCP Slave");
}
if (args != null && args.length >= 1) {
port = Integer.parseInt(args[0]);
}
try {
//2. Prepare a process image
spi = new SimpleProcessImage();
spi.addInputRegister(new SimpleInputRegister(635)); //érték beállítás
//3. Set the image on the coupler
ModbusCoupler.getReference().setProcessImage(spi);
ModbusCoupler.getReference().setMaster(false);
ModbusCoupler.getReference().setUnitID(1);
//3. create a listener with 3 threads in pool
if (Modbus.debug) {
System.out.println("Listening...");
}
listener = new ModbusTCPListener(1);
listener.setPort(port);
listener.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}//main
}发布于 2014-01-16 01:30:24
我在C#(NModbus)中为modbus使用liblary,SlaveException表示从设备返回错误:http://www.simplymodbus.ca/exceptions.htm错误代码2表示:
在查询中接收的数据地址不是从服务器允许的地址。更具体地说,参考编号和传输长度的组合是无效的。对于具有100个寄存器的控制器,具有偏移量96和长度4的请求将成功,具有偏移量96和长度5的请求将产生异常02。
Codes.pdf
https://stackoverflow.com/questions/18591328
复制相似问题