XT2640OperatingManual 13July2016 Page136of187
HidUart_Open
Opensadeviceusingadevicenumberbetween0andHidUart_GetNumDevices()–1andreturnsadeviceobjectpointer
whichwillbeusedforsubsequentaccesses.
HID_UART_STATUS HidUart_Open (HID_UART_DEVICE* device, DWORD deviceNum, WORD vid, WORD
pid)
device
—ReturnsapointertoaXT2640deviceobject.Thispointerwillbeusedbyallsubsequentaccessestothedevice.
deviceNum—Zero‐baseddeviceindex,between0and(HidUart_GetNumDevices()–1).
vid—FilterdeviceresultsbyvendorID.
pid—FilterdeviceresultsbyproductID.
ReturnValue:HID_UART_STATUS=HID_UART_SUCCESS,HID_UART_INVALID_DEVICE_OBJECT,
HID_UART_DEVICE_NOT_FOUND,HID_UART_INVALID_PARAMETER,HID_UART_DEVICE_IO_FAILED,
HID_UART_DEVICE_ACCESS_ERROR,HID_UART_DEVICE_NOT_SUPPORTED
Note‐Becarefulwhenopeningadevice.AnyHIDdevicemaybeopenedbythislibrary.However,ifthedeviceisnot
actuallyaXT2640,useofthislibrarywillcauseundesirableresults.TheXT2640PIDandVIDmustalwaysbeused.
HidUart_Close
ClosesanopeneddeviceusingthedeviceobjectpointerprovidedbyHidUart_Open().
HID_UART_STATUS HidUart_Close (HID_UART_DEVICE device)
device
—DeviceobjectpointerasreturnedbyHidUart_Open().
ReturnValue:HID_UART_STATUS=HID_UART_SUCCESS,HID_UART_INVALID_DEVICE_OBJECT,
HID_UART_INVALID_HANDLE,HID_UART_DEVICE_ACCESS_ERROR
Note‐
deviceisinvalidaftercallingHidUart_Close().ItisrecommendedtosetdevicetoNULLafterthiscall.
HidUart_IsOpened
Returnsthedeviceopenedstatus.
HID_UART_STATUS HidUart_IsOpened (HID_UART_DEVICE device, BOOL* opened)
device
—DeviceobjectpointerasreturnedbyHidUart_Open().
opened—ReturnsTRUEifthedeviceobjectpointerisvalidandthedevicehasbeenopenedusingHidUart_Open().
ReturnValue:HID_UART_STATUS=HID_UART_SUCCESS,HID_UART_INVALID_DEVICE_OBJECT,
HID_UART_INVALID_PARAMETER
HidUart_Read
Readstheavailablenumberofbytesintothesuppliedbufferandreturnsthenumberofbytesreadwhichcanbelessthan
thenumberofbytesrequested.Thisfunctionreturnssynchronouslyafterreadingtherequestednumberofbytesorafter
thetimeoutdurationhaselapsed.Readandwritetimeoutscanbesetusing
HidUart_SetTimeouts().
HID_UART_STATUS HidUart_Read (HID_UART_DEVICE device, BYTE* buffer, DWORD
numBytesToRead, DWORD* numBytesRead)
device
—DeviceobjectpointerasreturnedbyHidUart_Open().
buffer—Addressofabuffertobefilledwithreaddata.
numBytesToRead—Numberofbytestoreadfromthedeviceintothebuffer(1–32768).Thisvaluemustbelessthanor
equaltothesizeof
buffer.
numBytesRead
—Returnsthenumberofbytesactuallyreadintothebufferoncompletion.
ReturnValue:HID_UART_STATUS=HID_UART_SUCCESS,HID_UART_READ_ERROR,HID_UART_INVALID_PARAMETER,
HID_UART_INVALID_DEVICE_OBJECT,HID_UART_READ_TIMED_OUT,HID_UART_INVALID_REQUEST_LENGTH
Note‐
HidUart_Read()returnsHID_UART_READ_TIMED_OUTifthenumberofbytesreadislessthanthenumberofbytes
requested.Thiswillonlyoccurafterthereadtimeouthaselapsed.Ifthenumberofbytesreadmatchesthenumberofbytes
requested,thisfunctionwillreturnHID_UART_SUCCESS.
HidUart_Write
Writethespecifiednumberofbytesfromthesuppliedbuffertothedevice.Thisfunctionreturnssynchronouslyafter
writingtherequestednumberofbytesorafterthetimeoutdurationhaselapsed.Readandwritetimeoutscanbesetusing
HidUart_SetTimeouts().
HID_UART_STATUS HidUart_Write (HID_UART_DEVICE device, BYTE* buffer, DWORD
numBytesToWrite, DWORD* numBytesWritten)
device
—DeviceobjectpointerasreturnedbyHidUart_Open().
buffer—Addressofabuffertobesenttothedevice.
numBytesToWrite—Numberofbytestowritetothedevice(1–4096bytes).Thisvaluemustbelessthanorequaltothesize
ofbuffer.
numBytesWritten
—Returnsthenumberofbytesactuallywrittentothedevice.
ReturnValue:HID_UART_STATUS=HID_UART_SUCCESS,HID_UART_WRITE_ERROR,HID_UART_INVALID_PARAMETER,
HID_UART_INVALID_DEVICE_OBJECT,HID_UART_WRITE_TIMED_OUT,HID_UART_INVALID_REQUEST_LENGTH
Note‐
HidUart_Write()returnsHID_UART_WRITE_TIMED_OUTifthenumberofbyteswrittenislessthanthenumberof
bytesrequested.
HidUart_FlushBuffers