OpenModSim icon indicating copy to clipboard operation
OpenModSim copied to clipboard

Unable to set different device id for different modsim instances.

Open evo0705 opened this issue 1 year ago • 3 comments

Somehow, when changing the device id in ModSim2, it changes the device id in ModSim1 to the same Id. image

evo0705 avatar Sep 23 '24 15:09 evo0705

Hello @evo0705. This is the “feature”. Because Qt Modbus stack doesn’t allow use multiple id's.

sanny32 avatar Sep 23 '24 16:09 sanny32

@sanny32 this is really shame as your programm is superb and multiple slaves (addresses) would be really really needed. I use OpenModSim for testing and find it comparable to ModBus slave except this "feature" that limits use. Please add this to new release

talenat-st avatar Nov 03 '24 15:11 talenat-st

Even better would be the ability to configure arrays of devices to simulate, ie 1-N devices running at the same time with the same script, or possible script groups assigned.

drush avatar Dec 31 '24 01:12 drush

Hi sanny32, Can you rethink of addig this feature to your superb program? Something like in modbus tools modbus slave simulator where you can open multiple windows with differetn slave ID's. This would be perfect extension to your tool.

talenat-st avatar Jun 21 '25 14:06 talenat-st

This will require rewriting the modbus stack from the qt library, which I would not like to do.

sanny32 avatar Jun 21 '25 16:06 sanny32

I do not work with Qt but why it would need rewriting modbus stack? Since Qt QModbusServer do not support multiple instances bind to same port it is needed to write custom dispatcher that handles incoming requests and routes them to different logic blocks based on the server ID—all within a single QModbusServer instance. It needs some work but it sure do not require rewriting of Qtmodbus stack. This is just an idea to really imrpove value of you slave slimulator.

talenat-st avatar Jun 21 '25 22:06 talenat-st

Of course, there is no need to rewrite the entire stack. But the functionality responsible for processing incoming modbus requests is in the private Qt class and cannot be redefined from the outside (see https://github.com/qt/qtserialbus/blob/dev/src/serialbus/qmodbustcpserver_p.h#L72). Therefore, there is a need to rewrite the stack in terms of processing all incoming requests. And this entails moving the entire modbus stack of qt inside the program.

sanny32 avatar Jun 22 '25 09:06 sanny32

But the functionality responsible for processing incoming modbus requests is in the private Qt class and cannot be redefined from the outside

This is not entirely true. We can replace ModbusTcpServer's internal object, d_ptr, with our own one by using its swap() method and re-assembling it with private classes from the Qt source code changing for example the QModbusTcpServerPrivate::matchingServerAddress() method.

If the hack with d_ptr doesn't work, then we'll have to extend both the public and private parts of the classes.

raspopov avatar Sep 18 '25 16:09 raspopov

Will be implemented in the next release.

sanny32 avatar Sep 23 '25 16:09 sanny32

I would like to express my sincere gratitude for this feature! Debugging complex hardware is much easier now. 😊

raspopov avatar Oct 16 '25 19:10 raspopov