Page 1 of 1

Polling vs Event: Behind the API

Posted: Wed Apr 20, 2022 11:25 pm
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()?

Re: Polling vs Event: Behind the API

Posted: Thu Apr 21, 2022 3:52 pm
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