Comments (8)
onReadHoldingRegisterRange: address 0, quantity 10
It seems like 10 registers are required. However,
hr = new ModbusHoldingRegisters(10);
hr.set(0, 12345);
hr.set(1, 111);
you only set two. It's a usage problem.
from jlibmodbus.
I have removed the rest eight registers from the code above to make it shorter.
from jlibmodbus.
see the example
below line 94
if (slave.isListening()) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
synchronized (slave) {
slave.notifyAll();
}
}
});
synchronized (slave) {
slave.wait();
}
/*
* using master-branch it should be #slave.close();
*/
slave.shutdown();
}
In your code, the slave would be destroy after the first request.
from jlibmodbus.
Thanks for ideas. Added code:
System.out.println("before slave.isListening()");
if (slave.isListening()) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
synchronized (slave) {
slave.notifyAll();
}
}
});
synchronized (slave) {
slave.wait();
}
/*
* using master-branch it should be #slave.close();
*/
slave.shutdown();
}
System.out.println("after slave.isListening()");
and here are the logs (two requests from external software):
before slave.isListening()
Client connected /10.171.99.99
INFO: Frame recv: 00000000000601030000000A
onReadHoldingRegisterRange: address 0, quantity 10
INFO: Frame sent: 0000000000170103143039006F00DE014D01BC022B029A0309037803E7
WARNING: java.net.SocketTimeoutException: Read timed out
Client disconnected /10.171.99.99
Client connected /10.171.99.99
WARNING: java.net.SocketTimeoutException: Read timed out
Client disconnected /10.171.99.99
After that external software is freezing. In log there is no "after slave...", so this thread is waiting on wait() on tomcat side. I could run it as separate thread, but if synchronous not working, async will not either...
What is interesting, on debuging line by line, (without if() block) external software works fine until Resume thread.
from jlibmodbus.
I tested the slave shutdown code from the SimpleSlaveTCP.java example (line 99-117). My Slave is connected with a Master. I noticed that the code blocks in the wait method and never continuous with the shutdown of the slave. The communication with the Master is not aborted.
I then used the code from the ModbusTest.java and the ExampleTCP.java i.e.:
try {
slave.shutdown();
}
catch (ModbusIOException e) {
e.printStackTrace();
}
This does not block but it still does not interrupt the communication with the Master.
Only when I also set a new empty DataHolder to the slave, is the communication with the Master really interrupted:
try {
this.slave.setDataHolder(new DataHolder());
slave.shutdown();
}
catch (ModbusIOException e) {
e.printStackTrace();
}
Should perhaps the reset of the DataHolder be part of the slave shutdown method?
Best Regards
from jlibmodbus.
Hi @ippodamia, What do you mean by?
it still does not interrupt the communication with the Master.
What type of Slave
you are using?
from jlibmodbus.
Hello browncrane.
I am using a ModbusSlaveTCP slave. After the slave.shutdown();
method has been called the slave is not null and slave.isListening()
returns false. I can see that my Master is still connected to the Slave (makes read requests that are getting answered).
I would expect that after the ModbusSlaveTCP.shutdownImpl()
has been executed the ServerSocket should be closed and my Master should loose its connection.
Since the Socket has not been closed, the DataHolder of the Slave does not know that the Slave has been shutdown. I could check in my DataHolder methods (f.e. readHoldingRegisterRange()
) if the slave is still listening, in order to detect that the Slave has been shutdown.
from jlibmodbus.
Hi @browncrane and @ippodamia,
I ran into the same issue as @ippodamia. After calling the slave.shutdown()
method, Modbus TCP requests received by my application keep being processed.
From my understanding of the code I looked into, the issue come from the following :
The method RequestHandlerTCP.closeConnection()
is not called by the class ModbusSlaveTCP
(as it is by ModbusSlaveSerial
).
As a consequence setListening(false)
is not called neither and the method RequestHandler.isListening()
keep return true.
So the condition to end the "infinite" loop processing the requests in RequestHandlerTCP.run()
is never matched and the connection never closed.
I haven't found any workaround since no reference on the RequestHandlerTCP
is keeped in ModbusSalveTCP
that would allow to call the closeConnection()
method.
com.intelligt.modbus.jlibmodbus.slave.ModbusSlaveTCP.run()
@Override
public void run() {
[...]
threadPool.execute(new RequestHandlerTCP(this, s));
[...]
}
I hope this will help.
Simon
ps : I'm using the version 1.2.9.7
from jlibmodbus.
Related Issues (20)
- Serial RTU Slave doesn't work properly on multi device network. HOT 1
- SimpleMasterTCP How to obtain the Slave station original code?
- WARNING: Maximum PDU size is reached. : 1024
- Cannot create more than one slave under a TCP connection HOT 4
- A problem with FrameEventListener
- Custom function code HOT 1
- simplemasterRTU not running HOT 1
- Using jSerialComm Serial Communication is not working with stop bit 2.
- Problem of register value type HOT 1
- support negative value for register HOT 1
- java.lang.ArrayIndexOutOfBoundsException when accessing coil index HOT 1
- Inconsistency between the source code and the published JAR results in RTU access timeout HOT 1
- Publishing to maven central
- Error When connect to linux serial com
- Using Modbus RTU with custom Baudrate HOT 2
- java.lang.UnsatisfiedLinkError: when using old computer with windows 10 or 11 HOT 1
- Error when connecting to Modbus RTU and connecting with jSerialComm HOT 9
- No pom for latest release (1.2.9.9) HOT 2
- Why can't the slave receive data when the master station sends more than 12 bytes? HOT 1
- Possible update jssc version? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jlibmodbus.