Page 1 of 1
[BUG?] Attached not set until AFTER Attach event
Posted: Mon Dec 12, 2022 12:38 am
by scsm
I'm trying to determine when all expected devices on ports are attached.
For DigitalInputs, it appears that digitalInput.Attached is not set until sometime AFTER the Attach event fires. Is this a bug?
If this is by design, does that mean need to keep track of all Attach and Detach events ourselves?
Re: [BUG?] Attached not set until AFTER Attach event
Posted: Mon Dec 12, 2022 11:51 am
by Patrick
The attach event is fired during the 'attaching' phase of opening a device - the device isn't considered fully attached until after the attach event returns.
The attach event context is meant to device initialization. For example, you generally won't be able to read back device state from the attach event, but you are able to set device state.
In terms of the internal attach logic for opening a channel, this system does this:
1. Finds a matching channel based on your set matching parameters
2. Opens a connection to that device, over USB, Network, etc.
3. Sends a reset packet to reset the state of the channel
4. Sets any defaults values, as specified in the channel API
5. Fires the attach event, if you registered one - you can set your own initial values/state here
6. Sends an enable packet - now the channel is fully enabled. If it's a sensor it will start streaming back data, if it's a controller it may start driving a motor, etc.
7. The Attached property become true
8. If you called open() with a timeout, it will now wait for any initial state to come back from the device (sensor values, etc.), up to the timeout value, and then open() returns.
-Patrick
Re: [BUG?] Attached not set until AFTER Attach event
Posted: Mon Dec 12, 2022 7:15 pm
by scsm
Patrick wrote: ↑Mon Dec 12, 2022 11:51 am
The attach event is fired during the 'attaching' phase of opening a device - the device isn't considered fully attached until after the attach event returns.
The attach event context is meant to device initialization. For example, you generally won't be able to read back device state from the attach event, but you are able to set device state.
In terms of the internal attach logic for opening a channel, this system does this:
1. Finds a matching channel based on your set matching parameters
2. Opens a connection to that device, over USB, Network, etc.
3. Sends a reset packet to reset the state of the channel
4. Sets any defaults values, as specified in the channel API
5. Fires the attach event, if you registered one - you can set your own initial values/state here
6. Sends an enable packet - now the channel is fully enabled. If it's a sensor it will start streaming back data, if it's a controller it may start driving a motor, etc.
7. The Attached property become true
8. If you called open() with a timeout, it will now wait for any initial state to come back from the device (sensor values, etc.), up to the timeout value, and then open() returns.
-Patrick
Thanks again Patrick. We moved the Attached status check until after the Open port with timeout returns and it now updates in the UI correctly.