Hello Phidgets community. I am new to Phidgets and I am having some trouble dealing with the digital inputs of the 1063 stepper motor driver. I am able to see that it reads digital input properly through the Phidget Control Panel. However, after I close it, and run the code that I obtain by modifying the stepper-simple example, it doesn't really work. Please give me some advice. Thank you.

p.s. I haven't received any formal training on embedded programming, and most of my knowledge comes from hacking up projects with arduino.

The main block of code I am having trouble with is the second to last function. "checkInput()"

/backAndForth//basically modifying Stepper Simple, and trying various functions// - Stepper simple -// This simple example sets up a Stepper object, hooks the event handlers and opens it for device connections. // Once an Advanced Servo is attached it will move the motor to various positions.//// Please note that this example was designed to work with only one Phidget Stepper connected. //// Copyright 2008 Phidgets Inc. All rights reserved.// This work is licensed under the Creative Commons Attribution 2.5 Canada License. // view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/// modified by : George Huang

//Display the properties of the attached phidget to the screen. We will be displaying the name, serial number and version of the attached device.int display_properties(CPhidgetStepperHandle phid){ int serialNo, version, numMotors; const char* ptr;

//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error. CPhidget_set_OnAttach_Handler((CPhidgetHandle)stepper, AttachHandler, NULL); CPhidget_set_OnDetach_Handler((CPhidgetHandle)stepper, DetachHandler, NULL); CPhidget_set_OnError_Handler((CPhidgetHandle)stepper, ErrorHandler, NULL);

//Registers a callback that will run when the motor position is changed. //Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL). CPhidgetStepper_set_OnPositionChange_Handler(stepper, PositionChangeHandler, NULL);

//get the program to wait for an stepper device to be attached printf("Waiting for Phidget to be attached...."); if ((result = CPhidget_waitForAttachment((CPhidgetHandle)stepper, 10000))) { CPhidget_getErrorDescription(result, &err); printf("Problem waiting for attachment: %s\n", err); return 0; }

//Display the properties of the attached device display_properties(stepper);

//since user input has been read, this is a signal to terminate the program so we will close the phidget and delete the object we created printf("Closing...\n"); CPhidget_close((CPhidgetHandle)stepper); CPhidget_delete((CPhidgetHandle)stepper); return 0;}

printf("Waiting for Phidget to be attached...."); if ((result = CPhidget_waitForAttachment((CPhidgetHandle)stepper, 10000)))

Here you're checking for fail if result is true (defined as not 0), inside a pair of extra parantheses. This time it happens to give correct result (as EPHIDGET_OK is defined as 0), but you really want do this this explicit, as in

..but here your return value mismatch fails. CPhidgetStepper_getInputState returns EPHIDGET_OK on ok, and you're checking for PTRUE (which is defined as 1, which will only be returned if the call fails with EPHIDGET_NOTFOUND). The input state is set in inputState, not in the return value.

I think the part I messed up is mainly not understanding the output of the getInputState function. Your comment on being more explicit is certainly helpful and will definitely save me from a lot of future bugs.