Phidget_openWaitForAttachment fails ??

Comments & issues
Supporting Windows 8 or newer
Nakgerman
Fresh meat
Posts: 2
Joined: Wed Nov 12, 2025 10:17 am

Phidget_openWaitForAttachment fails ??

Post by Nakgerman »

I am using a VINT HUB0002_0, I have a STC1005_0 connected to port 0 and it attaches fine. The I am trying to configure port 1 for digital input. It fails at openWaitForAttachment with a timeout error. I intend to connect a limit switch to it. Here is the code:

// Continue with Forward limit switch on channel 1
RetCode = PhidgetDigitalInput_create(&FrwdLmt);
RetCode = Phidget_setHubPort((PhidgetHandle)FrwdLmt, 1);
// Can assign event handlers here
RetCode = Phidget_openWaitForAttachment((PhidgetHandle)FrwdLmt,
PHIDGET_TIMEOUT_DEFAULT);
if (RetCode != EPHIDGET_OK) {
MessageBox(NULL, "Cannot attach Forward Limit Channel",
"Phidget interface initialization", MB_OK);
return FALSE;
}
User avatar
mparadis
Site Admin
Posts: 684
Joined: Fri Oct 28, 2011 12:17 pm

Re: Phidget_openWaitForAttachment fails ??

Post by mparadis »

In addition to setting the hub port index, you also need to set IsHubPortDevice to 1, otherwise the software will be looking for an actual Phidget device with a digitalInput channel, rather than opening the port itself as a Digital Input.

Code: Select all

#include <phidget22.h>
#include <stdio.h>

static void CCONV onStateChange(PhidgetDigitalInputHandle ch, void * ctx, int state) {
	printf("State: %d\n", state);
}

int main() {
	PhidgetDigitalInputHandle digitalInput0;

	PhidgetDigitalInput_create(&digitalInput0);

	Phidget_setIsHubPortDevice((PhidgetHandle)digitalInput0, 1);
	Phidget_setHubPort((PhidgetHandle)digitalInput0, 0);

	PhidgetDigitalInput_setOnStateChangeHandler(digitalInput0, onStateChange, NULL);

	Phidget_openWaitForAttachment((PhidgetHandle)digitalInput0, 5000);

	//Wait until Enter has been pressed before exiting
	getchar();

	Phidget_close((PhidgetHandle)digitalInput0);

	PhidgetDigitalInput_delete(&digitalInput0);
}