Connecting a Device with Jamod Library and MODBUS RTU.

A

Thread Starter

AJ

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(n));
}

} 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.
 
M

mariobergeron

I have not used much this library for a long time, but looking at this
section of your code:<pre>
> ReadMultipleRegistersResponse response = null;
> ReadMultipleRegistersRequest request = new ReadMultipleRegistersRequest();
> request.setUnitID(1);
> request.setReference(43085);
> request.setWordCount(2);</pre>
You reference the holding register 43085. Is that what you want?
Or do you want a register of type 4 (notation often used for holding registers) at address 3085?

The register might be off by 1 also compare to other Modbus software.
 
that 43085 if after I add 40001 to the original register list. the original register list is 3084.

Original Register List: 3084 (Total Power Factor)
Modbus Protocol: Original Register List + 40001
The reference is: 43085

That is how I get the 43085 value.
 
>that 43085 if after I add 40001 to the original register
>list. the original register list is 3084.
>
>Original Register List: 3084 (Total Power Factor)
>Modbus Protocol: Original Register List + 40001
>The reference is: 43085
>
>That is how I get the 43085 value.

You want to provide 3084 in the request. The "40001" convention doesn't mean you add "40001", it means that is a holding register.

Also, I maintain j2mod (a fork of jamod, which is also available from SourceForge). I don't know if the author of jamod posts here, but I do and you can usually get support by posting to the SourceForge project page.
 
Top