Calling getAttached() in attach handler

Supporting 2.7 and 3.2+
Post Reply
jnbastoky
Phidgetsian
Posts: 13
Joined: Sun Apr 15, 2018 9:03 am
Contact:

Calling getAttached() in attach handler

Post 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.
User avatar
Patrick
Lead Developer
Posts: 3399
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Calling getAttached() in attach handler

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests