using of callbacks vs polling in c / VS

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

using of callbacks vs polling in c / VS

Postby rap » Thu May 30, 2019 2:21 am

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: 90
Joined: Mon Nov 13, 2017 10:20 am
Contact:

Re: using of callbacks vs polling in c / VS

Postby jdecoux » Thu May 30, 2019 9:24 am

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

Postby rap » Thu May 30, 2019 11:34 am

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: 254
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: using of callbacks vs polling in c / VS

Postby fraser » Fri May 31, 2019 8:29 am

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

Postby rap » Sat Jun 01, 2019 2:35 am

perfect, thanks ralf


Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 1 guest