A
I am new to the Modbus and Jamod. My aim is to connect my java application with the meter (electrical device) and get the reading of the meter to be shown in my application.
We can set the IP address at the meter. So, i already set the ip address at the meter and being able to Ping and connect to it with my system. The only thing that i not being able to do is get the meter reading.
So, I do really hope, someone out there can help me solve this solution. Because it has been 3 weeks i stuck at this point.
Below is the code:
<pre>
String address = "10.168.168.197" //my device ip adress
try{
conn = new TCPMasterConnection(InetAddress.getByName(address));
conn.connect();
}catch (UnknownHostException e){
throw new ReaderConnectorException("IP is not reachabled.{" + address + "}", e);
}catch (Exception e){
throw new ReaderConnectorException(e.getMessage(), e);
}
ModbusTCPTransaction transaction = new ModbusTCPTransaction(conn);
transaction.setReconnecting(true);
ReadMultipleRegistersResponse response = null;
ReadMultipleRegistersRequest request = new ReadMultipleRegistersRequest();
request.setUnitID(1);
request.setReference(43085);
request.setWordCount(2);
try {
transaction.setRequest(request);
transaction.execute();
response = (ReadMultipleRegistersResponse) transaction.getResponse();
for (int n = 0; n < response.getWordCount(); n++) {
System.out.println("Word " + n + "=" + response.getRegisterValue);
}
} catch (ModbusIOException e) {
e.printStackTrace();
} catch (ModbusSlaveException e) {
e.printStackTrace();
} catch (ModbusException e) {
e.printStackTrace();
}</pre>
and the output of the code is:
Word 0=32768
Word 1=32768
am i doing wrong somewhere ? All help will be appreciated. Thank you.
We can set the IP address at the meter. So, i already set the ip address at the meter and being able to Ping and connect to it with my system. The only thing that i not being able to do is get the meter reading.
So, I do really hope, someone out there can help me solve this solution. Because it has been 3 weeks i stuck at this point.
Below is the code:
<pre>
String address = "10.168.168.197" //my device ip adress
try{
conn = new TCPMasterConnection(InetAddress.getByName(address));
conn.connect();
}catch (UnknownHostException e){
throw new ReaderConnectorException("IP is not reachabled.{" + address + "}", e);
}catch (Exception e){
throw new ReaderConnectorException(e.getMessage(), e);
}
ModbusTCPTransaction transaction = new ModbusTCPTransaction(conn);
transaction.setReconnecting(true);
ReadMultipleRegistersResponse response = null;
ReadMultipleRegistersRequest request = new ReadMultipleRegistersRequest();
request.setUnitID(1);
request.setReference(43085);
request.setWordCount(2);
try {
transaction.setRequest(request);
transaction.execute();
response = (ReadMultipleRegistersResponse) transaction.getResponse();
for (int n = 0; n < response.getWordCount(); n++) {
System.out.println("Word " + n + "=" + response.getRegisterValue);
}
} catch (ModbusIOException e) {
e.printStackTrace();
} catch (ModbusSlaveException e) {
e.printStackTrace();
} catch (ModbusException e) {
e.printStackTrace();
}</pre>
and the output of the code is:
Word 0=32768
Word 1=32768
am i doing wrong somewhere ? All help will be appreciated. Thank you.