Prevent Duet from 'stealing' the device
PhreaK
Posts: 966
Afternoon fellow code monkeys, got an interesting one I'm battling with.
I'm currently in the process of attempting to wrap the RMS v3 NetLinx module inside a duet module so that my RMS integration can play a little nicer with the rest of my project.
I've been able to successfully instantiate the AMX RMS module within my duet module stub and get the test box to register with the server via a config sent to it from Duet - e.g. the stub just instantiates the duet module as standard, and also does a DEFINE_MODULE for the netlinx one contained, everything else happens in duet. Where I run into problems is after the I add the listeners on the duet side this 'steals' the NetLinx virtual away from the AMX RMS module. I've tried using a second proxy device (paired via define_combine as well as manual event handlers) but same thing, as soon as I need to start talking in duet land this severs the link and kills the NetLinx module.
How's that for convoluted? Any help greatly appreciated.
P.S. Yes, I know RMS 2020 is on the horizon and the SDK is duet based and will solve all these issues but I've got something I'm needing to roll out prior.
I'm currently in the process of attempting to wrap the RMS v3 NetLinx module inside a duet module so that my RMS integration can play a little nicer with the rest of my project.
I've been able to successfully instantiate the AMX RMS module within my duet module stub and get the test box to register with the server via a config sent to it from Duet - e.g. the stub just instantiates the duet module as standard, and also does a DEFINE_MODULE for the netlinx one contained, everything else happens in duet. Where I run into problems is after the I add the listeners on the duet side this 'steals' the NetLinx virtual away from the AMX RMS module. I've tried using a second proxy device (paired via define_combine as well as manual event handlers) but same thing, as soon as I need to start talking in duet land this severs the link and kills the NetLinx module.
How's that for convoluted? Any help greatly appreciated.
P.S. Yes, I know RMS 2020 is on the horizon and the SDK is duet based and will solve all these issues but I've got something I'm needing to roll out prior.
0
Comments
First off, this is my duet stub:
Then within my RMS module the following passes all the relevant events to my rmsEngine class which handles all the direct communication with the real rmsEngine and abstracts it into a nice duet friendly API.
Any thoughts, comments, criticisms and abuse appreciated.
That's it. The proxy acts as intended and the Duet module utilizes it the same way as it would talk to a physical device, no tricks required.
The thing that did it was shifting the proxy virtual to be the first argument for the device combining. This not only stopped the doubling of messages (when a command was sent from the module it would be echoed twice thanks to the way NetLinx virtuals behave) but also allows the Duet side of things to initialize the device and treat it as though the AMX RMSEngine module was a normal physical device - listeners behave properly and all comms is nicely handled via the SDK, no translation and re-writes required.
Again, if anyone can suggest improvements I'd be keen to listen.
*edit:
Needed to add in a channel event so that the module can be alerted to channel based feedback from the RMSEngine NetLinx module. As I'm only after socket, database and server online status I've just set this up as a one way thing. Code above updated.
*edit 2:
Modified the channel event to use state assignment rather than on[] and off[] keywords so that input, output and feedback channel events remain intact.
- added dev to be used for the RMSEngine to module parameters to remove possibilty of conflicts
- set internally assigned devices to utilize dynamic_virtual_device rather than static allocations
- changed proxy link to use translate_device rather than combine_device and a channel event handler