eth32_set_event_handler

int eth32_set_event_handler(eth32 handle, eth32_handler *handler);

Summary

This function configures an event handler mechanism within the API, which is able to immediately notify your code when events arrive. The event handler is separate from the event queue and enabling an event handler does not disable the event queue or vice versa.

Parameters

  • handle - The value returned by the eth32_open function.

  • handler - A pointer to an eth32_handler data structure which you have filled in with information about how events should be handled.

Return Value

This function returns zero on success and a negative error code on failure. Please see the Error Codes section for possible error codes.

Example
// This code shows an example of how to set up a 
// callback function event handler.

// Somewhere in your code, define a callback function, which may be
// named anything you want.
// On Windows, it must be stdcall calling convention
void __stdcall event_fired(eth32 handle, eth32_event *event, void *extra)
{
	switch(event->id)
	{
		case 1000:
			// React accordingly to Port 1, Bit 3 event
			break;
		case 1001:
			// React accordingly to Port 1, Bit 4 event
			break;
	}
}

         
         
eth32 handle;
int result;
eth32_handler event_handler={0}; // Initialize all data in the structure to zero.

// .... Your code that establishes a connection here

// Set up our callback function as the event handler for this connection
event_handler.type=HANDLER_CALLBACK;
event_handler.maxqueue=1000;
event_handler.fullqueue=QUEUE_DISCARD_NEW;
event_handler.eventfn=event_fired; // Store the address of the callback
result=eth32_set_event_handler(handle, &event_handler);
if(result)
{
	// handle error
}

// Enable events on Port 1, bits 3 and 4
result=eth32_enable_event(handle, EVENT_DIGITAL, 1, 3, 1000);
if(result)
{
	// handle error
}

result=eth32_enable_event(handle, EVENT_DIGITAL, 1, 4, 1001);
if(result)
{
	// handle error
}

         
See Also

Event Callback Function, eth32_enable_event, eth32_get_event_handler