Polling vs Event: Behind the API

Comments & issues
Post Reply
Rhybot
Phidgeteer!
Posts: 52
Joined: Wed Aug 14, 2019 4:58 pm
Contact:

Polling vs Event: Behind the API

Post by Rhybot »

As an example case, the HUB0000_0's VoltageInput API functionality for Python supports:
- getVoltage(): polling-driven approach
- setOnVoltageChangeHandler(handler): Event-driven approach

The differences between polling and Events are documented here: https://www.phidgets.com/docs/Using_Events

Now, my question is, in the VoltageInput API's backend ("behind the scenes"), how do the two actually work with the hardware?

From the docs, it seems like Phidgets hardware internally uses an Event-driven approach. We can key into new values streaming in via setOnVoltageChangeHandler(handler). Furthermore, the last value streamed in is stored. When one calls getVoltage(), is it:
- Reading from that last stored value
- Perform a round-trip hardware I/O get?

Why do I ask this question?

It's very clear to me that setDataInterval(dataInterval) is closely related with setOnVoltageChangeHandler(handler). However, I am wondering, is setDataInterval(dataInterval) also related to getVoltage()? In other words, does setDataInterval(dataInterval) change the "freshness" of the value returned by getVoltage()?
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Polling vs Event: Behind the API

Post by Patrick »

Polling just returns the most recent value from the library - this value is updated immediately before the data event is fired.

Data Interval affect the rate of events - and also the rate at which the value for polling gets updated. A longer data interval generally introduces averaging in the value, so you get lower noise.

-Patrick
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests