Page 1 of 1

Calling getAttached() in attach handler

Posted: Sun Sep 19, 2021 12:34 pm
by jnbastoky
I was troubleshooting an issue with setting the RTD type of a temperature sensor in the attach handler. In the process I discovered calling getAttached() on the channel gives a False result. If the attach handler is called then the channel should be attached, right? It appears that maybe the attached status is updated after the attach handler is called since it later calls give a True result.

It seems strange that one would call getAttached() from the attach handler, but I was getting an exception when trying to set the RTD from the attach handler.

Code: Select all

Phidget22.PhidgetException.PhidgetException: PhidgetException 0x34 (Device not Attached)
This can happen for a number of common reasons. Be sure you are opening the channel before trying to use it. If you are opening the channel, the program may not be waiting for the channel to be attached. If possible use openWaitForAttachment. Otherwise, be sure to check the Attached property of the channel before trying to use it.

Re: Calling getAttached() in attach handler

Posted: Tue Sep 21, 2021 3:38 pm
by Patrick
getAttached returns false if you call it from the attach handler. This is because the attach handler context is running at part of the attach process, and the channel is not considered fully attached until the attach handler (and any initialization you do within it) has completed.

This is mostly done this way so that any code elsewhere in your program will not report an attached channel until it's attach handler is complete.

-Patrick