Why is my Duet initiated channel event firing twice
jimboat
Posts: 2
I have written a module that turns on/off channels for monitoring by the NetLinx program. The channel events are getting fired twice. Why? How can I prevent the duplicate?
Duet Code:
String dvVirtualStr = this.getProperty("Duet-Device");
DPS dps = new DPS(dvVirtualStr);
dvVirtual = new NetLinxDevice(dps, false);
dvVirtual.initialize();
dvVirtual.on(842);
dvVirtual.off(843);
NetLinx Code:
channel_event[vProj,0]
{
ON: {
integer chan;
chan = channel.channel
send_string 0, "'Virtual Projector Channel ', itoa(chan), ' ON'"
}
OFF: {
integer chan;
chan = channel.channel;
send_string 0, "'Virtual Projector Channel ', itoa(chan), ' OFF'"
}
}
Diagnostics:
Line 10 (11:13:57):: Virtual Projector Channel 842 ON
Line 13 (11:13:57):: Virtual Projector Channel 842 ON
Line 14 (11:13:57):: Virtual Projector Channel 843 OFF
Line 15 (11:13:57):: Virtual Projector Channel 843 OFF
Duet Code:
String dvVirtualStr = this.getProperty("Duet-Device");
DPS dps = new DPS(dvVirtualStr);
dvVirtual = new NetLinxDevice(dps, false);
dvVirtual.initialize();
dvVirtual.on(842);
dvVirtual.off(843);
NetLinx Code:
channel_event[vProj,0]
{
ON: {
integer chan;
chan = channel.channel
send_string 0, "'Virtual Projector Channel ', itoa(chan), ' ON'"
}
OFF: {
integer chan;
chan = channel.channel;
send_string 0, "'Virtual Projector Channel ', itoa(chan), ' OFF'"
}
}
Diagnostics:
Line 10 (11:13:57):: Virtual Projector Channel 842 ON
Line 13 (11:13:57):: Virtual Projector Channel 842 ON
Line 14 (11:13:57):: Virtual Projector Channel 843 OFF
Line 15 (11:13:57):: Virtual Projector Channel 843 OFF
0
Comments
Good Luck!
Jeff
For any interaction you have with the virtual device associated with your module build an AdvancedEvent and process that. It will allow any listeners to be alerted and make sure everything is handled neatly with the interaction between Duet and NetLinx.
I have not been through the Duet training yet, but we intend to set up a class soon. That said, due to the minimal documentation, it's all been trial and error for me. This solution brought up another question.
Rather than just returning true from the respective methods, is there a way to test for isDeviceOnline and isDataInitialized?
Thanks.
One thing to note is that rather than just using a couple of boolean's and flicking these as your state changes you will need to process the appropriate online / initialised event for the channels to flick on the virtual device. Here's a little helper class that might help out - https://gist.github.com/4506054.
Like Phreak said...
Your isDeviceOnline method should only return true when you are getting responses from the device you are controlling. When you get three failed responses, your method should return false.
Your isDataInitialized method should return true when you have successfully got the complete status from the controlled device for every function you are controlling. Reset it to false when you lose communication with the controlled device.
You must use the "processDeviceOnLineEvent" and "processDataInitializedEvent" message handlers to set the channels (251, 252) through SNAPI. Call them when the state actually changes.