Page 1 of 1

using of callbacks vs polling in c / VS

Posted: Thu May 30, 2019 2:21 am
by rap
We try to use a dial encoder as device for receiving zoom data from a camera.
In a small interval (20ms) we need either a position value or a callback function for this.
We modified the encoder sample to reduce the interval setting, but nothing happens.
...
PhidgetEncoder_setDataInterval(ch, 20);
PhidgetEncoder_setPositionChangeTrigger(ch, 20);

thanks
Ralf

Re: using of callbacks vs polling in c / VS

Posted: Thu May 30, 2019 9:24 am
by jdecoux
If you want the measurement to be updated every 20ms, you will need to set the PositionChangeTrigger to 0.

For encoders, the change trigger prevents the channel from updating until the position changes by the specified amount (20 counts in your sample). A change trigger of 0 will update the position and fire an event every dataInterval (20ms in your case).

Re: using of callbacks vs polling in c / VS

Posted: Thu May 30, 2019 11:34 am
by rap
but this there a special position in code where to set this?
If i change to 0 after init (prc = Phidget_setHubPort((PhidgetHandle)ch, channelInfo.hubPort))... (PhidgetEncoder_setPositionChangeTrigger(ch, 0)) nothing changes, the interval is stable on 1000ms.

Re: using of callbacks vs polling in c / VS

Posted: Fri May 31, 2019 8:29 am
by fraser
You would need to call it after it is attached. Many properties require the device to be attached before setting them. This can be done either in the AttachHandler or once you know it is attached. If you check the return code on PhidgetEncoder_setPositionChangeTrigger(ch, 0) prior to calling open or before it is attached, you would see EPHIDGET_NOTATTACHED.

You'll want something like (pseudo-code):
SetHubPort
SetDeviceSerialNumber
OpenWaitforAttach
SetChangeTrigger
SetDataInterval


or if you have an AttachHandler put
SetChangeTrigger
SetDataInterval

inside of it

Re: using of callbacks vs polling in c / VS

Posted: Sat Jun 01, 2019 2:35 am
by rap
perfect, thanks ralf