gccDppConsole Test C++ SDK
20170920
DPP C++ Console Demonstration
|
00001 #pragma once 00002 00003 #ifdef _WIN32 00004 #define LIBUSB_WINUSB_BACKEND 1 00005 #endif 00006 00007 #ifdef LIBUSB_WINUSB_BACKEND 00008 #include "libusb.h" 00009 #ifdef _MSC_VER 00010 #pragma comment(lib, ".\\DeviceIO\\libusb.lib") 00011 #endif 00012 #else 00013 #include <libusb.h> 00014 #endif 00015 00016 #include <stdio.h> 00017 #include <sys/types.h> 00018 #include <string.h> 00019 00020 #define AMPTEK_DP5_VENDOR_ID 0x10C4 00021 #define AMPTEK_DP5_PRODUCT_ID 0x842A 00022 00023 #define INTERFACE_NUMBER 0 00024 #define TIMEOUT_MS 5000 00025 #define BULK_IN_ENDPOINT 0x81 00026 #define BULK_OUT_ENDPOINT 0x02 00027 #define MAX_BULK_IN_TRANSFER_SIZE 32768 00028 #define MAX_BULK_OUT_TRANSFER_SIZE 520 00029 #define STATUS_PACKET_SIZE 64 00030 #define DP5_USB_TIMEOUT 500 // default timeout (500mS) 00031 #define DP5_DIAGDATA_TIMEOUT 2500 // diag data timeout 00032 #define PID1_REQ_SCOPE_MISC_TO 0x03 00033 #define PID2_SEND_DIAGNOSTIC_DATA_TO 0x05 00034 00035 00036 class CDppLibUsb 00037 { 00038 public: 00039 CDppLibUsb(void); 00040 ~CDppLibUsb(void); 00041 00042 unsigned char data_in[MAX_BULK_IN_TRANSFER_SIZE]; // data bytes in 00043 unsigned char data_out[MAX_BULK_OUT_TRANSFER_SIZE]; // data bytes out 00044 00045 libusb_device_handle *DppLibusbHandle; 00046 int NumDevices; 00047 int CurrentDevice; 00048 bool bLibusbReady; 00049 bool bDeviceReady; 00050 char LastLibUsbError[256]; 00051 bool bDeviceConnected; 00052 00053 int InitializeLibusb(); 00054 void DeinitializeLibusb(); 00055 libusb_device_handle * FindUSBDevice(int idxAmptekDevice); 00056 void CloseUSBDevice(libusb_device_handle * devh); 00057 int SendPacketUSB(libusb_device_handle *devh, unsigned char data_out[], unsigned char data_in[]); 00058 bool isAmptekDP5Device(libusb_device_descriptor desc); 00059 int CountDP5LibusbDevices(); 00060 void PrintDevices(); 00061 00062 #ifndef LIBUSB_WINUSB_BACKEND 00063 const char * libusb_strerror(enum libusb_error error_code); 00064 #endif 00065 00066 }; 00067 00068 00069 00070 00071 00072 00073 00074 00075