IO Provider Class Pattern
The IO Provider Class Pattern builds on the Base Class Pattern to provide a foundation to access a collection of IO Classes.
Constructor
IOProvider()
Creates a new IOProvider
object instance.
Parameters
options
An object of properties used to construct the class. The options object defines the hardware connections of the provider. These use the same properties as the IO types corresponding to the hardware connection. The following are defined by this abstract class:
onReady
(optional): A callback function that is invoked when the instance is ready for use.
onError
(optional): A callback function that is invoked when a non-recoverable error occurs. The function may be passed anError
depending on the IO type.
Instance Properties
This class inherits all instance properties from the Base Class Pattern.
Instance Methods
close
Releases all resources associated with the instance before completing. It may be called more than once without erroring. Once this method has been called, calling other methods on the instance throws an exception.
If an instance provides any asynchronous methods, it should provide an asynchronous close method via the callback function.
Parameters
callbackFn
For asynchronous classes, a function that executes when the close process has completed.
result
The first argument to the completion callback is always a result code. A value of 0 indicates success; an Error object indicates failure.
Examples
The following code is an example of using an IO Provider to access a Digital pin on a GPIO expander connected via I²C, such as MCP23017: