WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

attach

Registers a callback function that is called when a character is received by the UART.
Syntax
Uart. attach(callback)
Uart. attach(callback,param)
 
Parameters
TypeNameDescription
'callback'
The address of the function to be called when a character is received by the UART.
'param'
A user defined value that is passed to the callback routine. If not specified this will be NULL.
Returns
None
Example
void myReceive(unsigned char data, Uart& uart, void* param){
    // You have just received a byte in the 'data' parameter
    // You can now access the uart using 'uart.functionName()'
}
You can now ask the UART0 to call it when a byte is received by writing:-
UART0.attach(&myReceive, NULL);
Note the '&' character at the start of your function name.
Only one callback routine can be registered at any one time.
There are times when your call back routine also needs to know the device that is using the UART. For example it could be a Drone Cell device. The final parameter of the attach allows you to specify a value that is passed into the 'param' value of your call back function.

 

 

Valid XHTML 1.0 Transitional