/*
**********************************************************************
* Micrium, Inc.
* 949 Crestview Circle
* Weston, FL 33327-1848
*
* uC/USB-Bulk
*
* (c) Copyright 2003 - 2004, Micrium, Inc.
* All rights reserved.
*
***********************************************************************
----------------------------------------------------------------------
File : SampleApp.c
Purpose : USB BULK Sample Application
---------------------------END-OF-HEADER------------------------------
*/
#include <stdio.h>
#include <windows.h>
#include "USBBULK.h"
typedef BOOL (WINAPI* TTT) (WORD);
TTT _CancelIo; external;
/*********************************************************************
*
* _MessageBox
*
*/
static void _MessageBox(const char * s) {
MessageBox(NULL, s, "USB Bulk sample application", MB_OK);
}
/*********************************************************************
*
* _SendReceive1
*
*/
static int _SendReceive1(unsigned char DataTx) {
unsigned char DataRx[100];
int r;
printf("Writing one byte\n");
r = USBBULK_Write(&DataTx, 63);
if (r == 0) {
_MessageBox("Could not write to device");
}
printf("Reading one byte\n");
r = USBBULK_Read (&DataRx, 63);
if (r == 0) {
_MessageBox("Could not read from device (time out)");
}
if (DataRx != (DataTx + 1)) {
// _MessageBox("Wrong data read");
return 1;
}
printf("Operation succesful!\n\n");
return 0;
}
/*********************************************************************
*
* _Test
*
*/
int Test(void) {
int r;
r = _SendReceive1(0x12);
if (r) {
return r;
}
r = _SendReceive1(0x13);
return r;
}
/*********************************************************************
*
* main
*
* Function description
*/
int main(int argc, char* argv[]) {
int r;
HANDLE h;
h = LoadLibrary("KERNEL32.DLL");
_CancelIo = (TTT)GetProcAddress(GetModuleHandle("KERNEL32.DLL"),"CancelIo");
if (USBBULK_Open() == NULL) {
_MessageBox("Unable to connect to USB BULK device");
return 1;
}
while(1) r = Test();
USBBULK_Close();
if (r == 0) {
// _MessageBox("Communication with USB BULK device succesful!");
}
return r;
}