SciFiDryer / ModbusMechanic

Cross platform GUI MODBUS TCP/RTU simulator & gateway. Interprets data types including ascii float and int.
Apache License 2.0
169 stars 15 forks source link

TimeoutException when using Slave ID other than 1 #12

Closed Pratched closed 1 year ago

Pratched commented 1 year ago

I am trying to add functionality to my communication (as the master) with inverters (the slaves) via a corporate Modbus implementation (from SMA Solar Technologies), without actually connecting to the hardware all the time. Id hoped, that this tool might ease things for me.

However so far, I could not even get it to run with itself. I thought I tried the simpliest queries I already managed to implement in my own communication. Reading Input Registers with FunctionCode 0x04 at Register 30843. Unsigned32 (2 Registers) at SlaveID 3 and of course ProtocolID 0.

But all I got is a TimeoutException (see screenshot below). Is there anything I could check or read up on to figure out where things went wrong?

PS: I am running a Debian Bookworm system with OpenJDK 17.0.5+8-2 using Hotspot JIT. Maybe I should mention, that if I am running the .jar without sudo and trying to connect to 127.0.0.1 it says java.net.ConnecException: Connection Refused.

image

SciFiDryer commented 1 year ago

Usually this situation arises when the application is run without privileges to bind to port 502 or another application has already bound itself. You can start the application with the debug argument "java -jar ModbusMechanic.jar -debug" from the ModbusMechanic directory to see verbose debugging information. Another helpful command to run is "netstat -an" to see if anything is listening on port 502. Look for LISTENING on the netstat list under port 502.

If another application has already bound itself to port 502, ModbusMechanic will not be able to start a TCP slave simulator. You may have already tried this but can you connect to your Ethernet or WiFi IP?

Iptables or firewall rules can also cause packets to be dropped. I like to use tcpdump for verifying packet flow.

Pratched commented 1 year ago

Thanks for your quick response.

So I tried with -debug, of course again with sudo and it just says, that no bytes have been received. image

I tried (with root privileges) netstat -an | grep 502 respectively netstat -an | grep LISTENING, neither show any significant entrys.

When you say connecting to WiFi or Ethernet IP you mean trying to enter my wifi interface's , i.e. inet 192.168.178.68 in the IP field within ModbusMechanic?

EDIT: The following shows merely the Master's ModbusTCP request but no response: image

SciFiDryer commented 1 year ago

I was able to reproduce this exact error and it turns out there was a typo in my code. The simulator slave ID was hardcoded to always be 1 so it was not answering on 3. This is fixed in 06df4d7 and version 2.4 which is now available. Thanks for your feedback and data, it looks like the typo had been overlooked for a while.

Pratched commented 1 year ago

Ah that is very good to hear. Was thinking to try SlaveID 1, as 3 is needed for my Hardware but good on you figuring this out. Cheers!

However, the version I used to stumble upon this issue came from the .zip file linked to here, respectively this one (v2.4 via this way works great!). However I went ahead and cloned the entire project to my local machine after your fix today and tried installing or launching it with linuxlauncher.sh. Neither worked (I am running KDE Plasme 5), as it created the respective .desktop when installing, I had to make it executable. But whenever trying to launch it nothing happens. Not much of a bash semi-professional, but maybe it doesnt find the correct .jar? At least its not in that directory.

SciFiDryer commented 1 year ago

Not sure I follow on the link. The link from the other website just links to the most recent release - it would have been 2.3 yesterday. As soon as 2.4 was posted it would be 2.4.

If you are cloning the project as opposed to launching the binary from the jar, the binaries will need to be built. I build them with the NetBeans IDE. When NetBeans builds the binaries, they go to the dist subdirectory, so this could be why. If the project is cloned but not built no jar file will exist.

Pratched commented 1 year ago

Yeah didnt explain that to well, doesnt matter however.

Thanks for clearing things up. Everything works well!