Hubo Library

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Typedefs | Functions
Digital input support

## Typedefs
typedef void(* | HuboLib::T_pfn_DIChangedCallback) (unsigned char changedDigitalInputValues, unsigned char digitalInputValues)
| Prototype definition of the callback function beeing called whenever a change of any of the digital inputs is detected. More...

## Functions
bool | HuboLib::Get_DI_Channels (unsigned char &value)
| Retrieves the value of all digital inputs. More...
bool | HuboLib::Get_DI_Channels_Raw (unsigned char &values)
| Retrieves the unbuffered values of all digital inputs (of the Hubo master module). More...
bool | HuboLib::Get_Slave_DI_Channels (int slaveNo, unsigned char &value)
| Retrieves the value of all digital inputs. More...
bool | HuboLib::Get_DI_Channel (int channel, bool &bValue)
| Retrieves the value of one digital input. More...
bool | HuboLib::Get_Slave_DI_Channel (int slaveNo, int channel, bool &bValue)
| Retrieves the value of one digital input for a given slave. More...
bool | HuboLib::Register_DIChangedCallback (T_pfn_DIChangedCallback pFnDIChangedCallback)
| Register a callback to be called whenever one or more of the digital inputs have changed. More...
bool | HuboLib::Unregister_DIChangedCallback (T_pfn_DIChangedCallback pFnDIChangedCallback)
| Unregister a callback previouly registered by a call to Register_DIChangedCallback(). More...

## Detailed Description

## Typedef Documentation

typedef void(* HuboLib::T_pfn_DIChangedCallback) (unsigned char changedDigitalInputValues, unsigned char digitalInputValues)

Prototype definition of the callback function beeing called whenever a change of any of the digital inputs is detected.

Registering a callback routine provides a way to an application to get notified whenever the background thread detects the changing of an digital input. This can be usefull to an application that does not want to poll for changes on the digital inputs but use the background threads cycle time for detection instead. The callback is executed after inputs and outputs have been processed by the background thread but prior to calls to the callbacks for the cycle tick and the channel delay.
Just like the cycle tick callback this function is also called by the background thread - thus all timing considerations also apply to this callback function.

Parameters

  changedDigitalInputValues | The bit mask indicating a changed input via the bit set.
  digitalInputValues | The current state of the digital inputs.

See also
  For an example on how to register and use the digital input changed callback function refer to the demo DigitalInput5.cpp.

Note
  Be aware of that the callback routine will be executed within the background thread!

Definition at line 115 of file hubolib.h.

## Function Documentation

bool HuboLib::Get_DI_Channel | ( | int | channel,
|  | bool & | bValue
| ) |  |

Retrieves the value of one digital input.

This function returns the buffered value of the last latched digital inputs.

Parameters

  channel | The digital input channel to retrieve the state from. Valid ranges are 0 through 7.
  bValue | If the channel is being set bValue is true, otherwise false.

Returns
  Since a call to this function will access the internal buffers, a call will always return true as long as the IO expander is present, has properly been initialized and the channel value is within the allowed range of 0..7.

See also
  Get_DI_Channels(), Get_Slave_DI_Channel()
  For an example on how to read a single digital inputs refer to the demos DigitalInput1.cpp, DigitalInput2.cpp and DigitalInput3.cpp.

bool HuboLib::Get_DI_Channels | ( | unsigned char & | value | ) |

Retrieves the value of all digital inputs.

This function returns the buffered value of the last latched digital inputs.

Parameters

  value | The bit mask representing the current state of the digital inputs.

Returns
  Since a call to this function will access the internal buffers, a call will always return true as long as the IO expander is present and has properly been initialized.

See also
  Get_DI_Channel(), Get_Slave_DI_Channels()
  For an example on how to read the digital inputs refer to the demos DigitalInput4.cpp and SetCycleTime.cpp.

bool HuboLib::Get_DI_Channels_Raw | ( | unsigned char & | values | ) |

Retrieves the unbuffered values of all digital inputs (of the Hubo master module).

While this function requires a proper initialization by a call to Initialize() it does not require any further operations. It does not provide a check for correct initialization but directly accesses the hardware without storing the results in the buffers associated with the digital inputs. The function should be used in cases where very fast access to digital input values is required (up to 2kHz) which cannot be achieved by further decreasing of the cycle time. This can be handy when trying to follow (or capture) a signal once a certain condition is met. However, remember that the background thread runs at a very high priority likely to prevent the rest of the system from running. So make sure your callback routine is taking this into account.

Parameters

  value | The bit mask representing the current state of the digital inputs.

Returns
  Since a call to this function will directly access the hardware it might return false when failing to read a new input value. Otherwise the return value is true.

See also
  Get_DI_Channel(), Get_AI_Channel_Raw()
  For an example on how to raw read the digital inputs refer to the demo DigitalRawInput.cpp.

bool HuboLib::Get_Slave_DI_Channel | ( | int | slaveNo,
|  | int | channel,
|  | bool & | bValue
| ) |  |

Retrieves the value of one digital input for a given slave.

This function behaves like Get_DI_Channel() but works on a slave as specified.

Parameters

  slaveNo | The slave index in the list of slave addresses as specified by g_I2CConfig.m_MCP23017SlaveDeviceAddressList.
  channel | The digital input channel to retrieve the state from. Valid ranges are 0 through 7.
  bValue | If the channel is being set bValue is true, otherwise false.

Returns
  Since a call to this function will access the internal buffers, a call will always return true as long as the slave is present, has properly been initialized and the channel value is within the allowed range of 0..7.

See also
  Get_DI_Channel(), Get_Slave_DI_Channels()
  For an example on how to read a single digital inputs refer to the demo DigitalSlaveInput1.cpp.

bool HuboLib::Get_Slave_DI_Channels | ( | int | slaveNo,
|  | unsigned char & | value
| ) |  |

Retrieves the value of all digital inputs.

This function returns the buffered value of the last latched digital inputs for a given slave. This function behaves like Get_DI_Channels() but works on a slave as specified.

Parameters

  slaveNo | The slave index in the list of slave addresses as specified by g_I2CConfig.m_MCP23017SlaveDeviceAddressList.
  value | The bit mask representing the current state of the digital inputs.

Returns
  Since a call to this function will access the internal buffers, a call will always return true as long as the slave is present and has properly been initialized.

See also
  Get_DI_Channels(), Get_Slave_DI_Channel()
  For an example on how to read the digital inputs refer to the demo DigitalSlaveInput2.cpp.

bool HuboLib::Register_DIChangedCallback | ( | T_pfn_DIChangedCallback | pFnDIChangedCallback | ) |

Register a callback to be called whenever one or more of the digital inputs have changed.

This function is used to register a callback routine that is called whenever one or more of the digital inputs have changed during the last cycle time. The callback routine receives information on the bit mask the input changes as well as the current state of the inputs.
Unregistration is performed by Unregister_DIChangedCallback().

Parameters

  pFnDIChangedCallback | Pointer to the callback function to be called whenever one or more digital inputs have changed their state. Function pointers are not chained. Passing 0 as an argument disables the callback.

Returns
  The function returns true if the new callback could be registered. If the maximum number of callback functions has been reached the function returns false.

See also
  Unregister_DIChangedCallback(), T_pfn_DIChangedCallback
  For an example on how to use Register_DIChangedCallback() refer to the demo DigitalInput5.cpp.

Note
  Be aware of that the callback routine will be executed within the background thread! In order to avoid dead lock situations callback routines must not call any of the functions as exposed by the hubolib.h interface (unless otherwise stated e.g. for xxx_Raw()-routines)!

bool HuboLib::Unregister_DIChangedCallback | ( | T_pfn_DIChangedCallback | pFnDIChangedCallback | ) |

Unregister a callback previouly registered by a call to Register_DIChangedCallback().

This function is used to unregister a single callback routine previously added. If pFnDIChangedCallback is 0 then the call will unregister all callback routines.

Parameters

  pFnDIChangedCallback | Pointer to the callback to be unregistered from the list of callback functions or 0 if all callback functions are to be removed from the list.

Returns
  The function returns true if the callback could be found and unregistered.

See also
  Register_DIChangedCallback()
  For an example on how to use Unregister_DIChangedCallback() refer to the demo DigitalInput5.cpp.