#include "stdafx.h" #include #include #include #include "cusb.h" #include "cusb.c" #ifndef max #define max(x, y) (((x) > (y)) ? (x) : (y)) #endif #ifndef min #define min(x, y) (((x) < (y)) ? (x) : (y)) #endif extern "C" { void __declspec(dllexport) getADCs(int *, int); }; #define FW_VERSION "V100" #define PIPE_AD7739 4 #ifdef __cplusplus extern "C"{ #endif extern u8 fw_bin[]; #ifdef __cplusplus } #endif HANDLE dev_handle; BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch(ul_reason_for_call){ case DLL_PROCESS_ATTACH: if(cusb_init(0, &dev_handle, fw_bin, (s8 *)"RGIO", (s8 *)FW_VERSION)){ return FALSE; } break; case DLL_PROCESS_DETACH: usb_close(&dev_handle); break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: break; } return TRUE; } void __declspec(dllexport) getADCs(int *iArray, int array_size) { unsigned char buf[64]; int index = 0; usb_bulk_read(&dev_handle, PIPE_AD7739, buf, sizeof(buf)); long global_ms = 0; (global_ms |= buf[index++]); global_ms <<= 8; (global_ms |= buf[index++]); global_ms <<= 8; (global_ms |= buf[index++]); global_ms <<= 8; (global_ms |= buf[index++]); for(int ch = 0; ch < min(8, array_size); ch++){ int *target = iArray + ch; (*target |= buf[index++]); *target <<= 8; (*target |= buf[index++]); *target <<= 8; (*target |= buf[index++]); } }