Hardware manual

UPS25 API Manual for Windows 2000/XP/Vista
6
Using The Driver
The UPS25 can be controlled from software via the driver’s IOCTL interface. Using an IOCTL
interface is the standard way of communicating with a Windows driver. This interface is accessed
using the’ DeviceIOControl’ function.
In the application source code you can find different examples of how to use the driver. Some
special examples are given below.
Getting a handle to the board
The ‘DeviceIOControl’ function (which is used to communicate with the board) requires a handle
as the first parameter. To get the handle you must open a device file using the following code:
HANDLE hDevice;
hDevice = CreateFile( "\\\\.\\Ups250",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
Catching Interrupts
The driver can signal a program when an interrupt is received from the board. To do this, you
should use the ‘UPS25_SET_MODE’ IOCTL:
ENABLEINTERRUPTS Msg;
OVERLAPPED o;
ULONG i;
o.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
Msg.IntEvent = o.hEvent;
DeviceIoControl( hDevice,
UPS25_SET_MODE,
&Msg,
sizeof(ENABLEINTERRUPTS),
NULL,
0,
&i,
&o);
When an interrupt is received from the board, the event ‘o.hEvent’ will be signaled. Normally,
you would have a thread waiting on the event before performing an action. See the
‘ServiceThread’ function in the application source for how to do this. Also see the ‘OpenDevice’
function where it creates a thread using ‘CreateThread’.