Hello everyone,
I am currently working on a project where I need to retrieve information from a meter using both serial and TCP connections. The process involves reading a meter’s UID via the serial port, then obtaining the meter’s IP address, and finally, querying the meter for its details via a TCP connection.
Here’s the sequence of operations I’m following:
1. I read the UID from the meter using the serial port.
2. I close the serial port.
3. After a delay of 500 milliseconds, I attempt to retrieve the IP of the meter using the GXSerial port.
4. Once I have the IP, I attempt to establish a TCP connection to the meter to read its data (such as serial number, profile read, clock).
However, I’m running into the following issues when trying to establish the TCP connection:
Error 1: java.net.SocketException: Connection reset
Error 2: java.net.SocketException: Socket operation on non-socket
Additionally, sometimes the code does not exit from the settings.media.open(); method, and it hangs indefinitely.
Troubleshooting Steps Taken:
I’ve verified that the serial communication and the retrieval of the UID work as expected.
Close the media below code i have used
finally {
if (reader != null) {
try {
reader.close(); // diconnect request
settings.media.close()
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
Any advice or insights into solving this issue would be greatly appreciated.
Thank you in advance for your help!
Hi, SocketException is…
Hi,
SocketException is coming from Java and it usually means that your TCP/IP address or port is invalid. Check those at the start.
BR,
Mikko
Hi Mikko, Thanks for the…
Hi Mikko, Thanks for the suggestion. The IP and port are correct, but in this case, I'm continuously reading data.
It seems that when I try to connect to the internet (Mobile network), It might be encountering below issue.
Could this be related to a network fluctuation or a timeout when switching connections or related to meter connectivity?
Or, here socket connection is happening with GXNet jar file, Can i create my own socket logic to communicate with meter. If its is possible let me know and explain with simple program to read serial number through TCP.
BR,
Tharun
Hi, Is your meter using a…
Hi,
Is your meter using a static or dynamic IP address? Read this at first.
https://gurux.fi/Gurux.DLMS.DynamicIP
It will help you to get started.
BR,
Mikko
Hi Mikko, Our meter is using…
Hi Mikko,
Our meter is using a static IP, so in this case, the meter can initiate the connection to the server. However, when I continuously try to read data, I am getting a socket exception. The IP we are using is obtained via the GXSerial HDLC port.
The same IP is being used to read the meter information. In this case, I am able to successfully read the data the first time, but on the second attempt, I can retrieve the IP through the port, but when I try to read using the IP, I encounter an exception in below line.
I observed that once I get the IP, I am trying to ping using the code below.
However, I encountered the following exception.
Based on this, it seems that I am unable to create a socket connection. Is there any issue related to the meter?
BR,
Tharun
Hi, There is something wrong…
Hi,
There is something wrong with TCP/IP connection.
The reason is usually the wrong IP address or port number. Sometimes there is a firewall that blocks the connection.
Check those at first.
BR,
Mikko
Hi,I have checked firewall…
Hi,
I have checked firewall settings, Everything is fine only, I have made TCP connection using below code
Here I am connected mobile internet for to create connection between meter and pc.
Once I read data through ip i have close the resource which is followed by gurux sample client code.
Now my problem second time when I try to read data through ip, I have got socket exception.
Note: Here ip I have got through the GXDLMS HDLC port so it can't be wrong.
So kindly check the TCP connection code is there any issue let me know sir.
BR,
Tharun
Hi, I'm sorry, but I can't…
Hi,
I'm sorry, but I can't help you with this. This is Java connection problem and the reason can be anything. For some reason, the TCP/IP connection fails and I have proposed a few reasons.
BR,
Mikko
Hi, Could you please let me…
Hi,
Could you please let me know which Java version is supported for this connection?
In my project I am using java 21. This will help in troubleshooting the issue more effectively.
Please reply ASAP.
BR,
Tharun
Hi, All Java versions…
Hi,
All Java versions support this. The socket connection established fails for some reason. I have told you the possible reasons why the connection might fail.
BR,
Mikko