using of callbacks vs polling in c / VS

C, C++, and Visual C++
Post Reply
rap
Fresh meat
Posts: 3
Joined: Thu May 30, 2019 2:09 am
Contact:

using of callbacks vs polling in c / VS

Post 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
jdecoux
Labview Developer
Posts: 180
Joined: Mon Nov 13, 2017 10:20 am
Contact:

Re: using of callbacks vs polling in c / VS

Post 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).
rap
Fresh meat
Posts: 3
Joined: Thu May 30, 2019 2:09 am
Contact:

Re: using of callbacks vs polling in c / VS

Post 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.
fraser
Engineering
Posts: 138
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: using of callbacks vs polling in c / VS

Post 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
rap
Fresh meat
Posts: 3
Joined: Thu May 30, 2019 2:09 am
Contact:

Re: using of callbacks vs polling in c / VS

Post by rap »

perfect, thanks ralf
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests