EasyManua.ls Logo

ABLE Ap1400 - Page 35

ABLE Ap1400
42 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Ref: "Ap1400ProgGuide1_2.docx" Page 35 of 42
Document Revision: “1.2”
Document Date: “9 Apr. 2013”
OpenDevice
Opens a device and prepares it to send/receive data
Prototype
int WINAPI OpenDevice(int *pIndex);
Description
Opens a device and associates a unique handle with the device. An open device
has the whole interface claimed(all control points & endpoints) making its use
exclusive to the handle holder. Once successfully opened, data can be freely
exchanged between the host and the device using the returned handle.
Use CloseDevice to release the handle and free the attached device.
Arguments
pIndex – Pointer to the index of the device. This must be an integer value
>=0<GetEnumPrinterCount();
If this value is outside of this range then an exception will be thrown.
Returns
An int representing the handle of the device, or INVALID_HANDLE_VALUE if the
device open failed. If the returned handle is set to INVALID_HANDLE_VALUE then
the system error code will be set to fully describe the problem. This can be retrieved
by calling GetLastError().
Example
//Check range prior to call
if(iDevIndex>=0&&iDevIndex< GetEnumPrinterCount)
{
int iHandle=OpenDevice(&iDevIndex);
Check result
if(iHandle==INVALID_HANDLE_VALUE)
{
CString csError;
csError.Format(_T(“Device open failed. R/C=%d.”),
GetLastError());
AfxMessageBox(csError,MB_ICONSTOP|MB_OK);
return;
}
//device is open and may be used
TRACE(_T(“Device open success. Handle=%d.\n”),
iHandle);
}

Related product manuals