The sonar is definitely not yet attached at that instance of code. Doing something like calling Phidget_openWaitForAttachment() instead of Phidget_open() will block the function until the device attaches, or times-out per your argument to the call. However, often even after calling openWaitForAttachment, the device could still take a small amount of time to successfully return polling functions.
But more importantly, make sure you check your return codes in c/c++.
For example, define a function to output error codes, and call that function after every phidget call. (shown with a temperature object polling for Attached property)
Code: Select all
void DisplayError(PhidgetReturnCode returnCode)
{
PhidgetReturnCode prc;
const char* error;
prc = Phidget_getErrorDescription(returnCode, &error);
if (EPHIDGET_OK != prc)
{
printf("Error getting error description\n");
DisplayError(prc);
}
else
{
printf("->Error Description: %s<-\n", error);
}
}
Code: Select all
bool IsAttached(PhidgetTemperatureSensorHandle temperature)
{
PhidgetReturnCode prc;
int attached;
prc = Phidget_getAttached((PhidgetHandle)temperature, &attached);
if (EPHIDGET_OK != prc){
printf("Failed on getAttached. [%x]\n", prc);
DisplayError(prc);
}
if (attached)
return true;
else return false;
}
You can adapt this code to work for the sonar:
Code: Select all
int QuietMode(PhidgetDistanceSensorHandle dst1200)
{
PhidgetReturnCode prc;
int quietmode;
prc = PhidgetDistanceSensor_getSonarQuietMode(dst1200, &quietmode);
if (EPHIDGET_OK != prc){
printf("Failed on getQuietMode. [%x]\n", prc);
DisplayError(prc);
}
return quietmode;
}