You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
(27) |
Dec
(9) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(2) |
Feb
(19) |
Mar
(13) |
Apr
(15) |
May
(11) |
Jun
(17) |
Jul
(31) |
Aug
(45) |
Sep
(10) |
Oct
(40) |
Nov
(39) |
Dec
(45) |
2005 |
Jan
(113) |
Feb
(45) |
Mar
(38) |
Apr
(53) |
May
(11) |
Jun
(42) |
Jul
(56) |
Aug
(50) |
Sep
(32) |
Oct
(32) |
Nov
(47) |
Dec
(22) |
2006 |
Jan
(19) |
Feb
(32) |
Mar
(40) |
Apr
(40) |
May
(41) |
Jun
(44) |
Jul
(37) |
Aug
(51) |
Sep
(30) |
Oct
(30) |
Nov
(51) |
Dec
(20) |
2007 |
Jan
(7) |
Feb
(20) |
Mar
(17) |
Apr
(67) |
May
(13) |
Jun
(73) |
Jul
(16) |
Aug
(58) |
Sep
(29) |
Oct
(5) |
Nov
(74) |
Dec
(9) |
2008 |
Jan
(17) |
Feb
(12) |
Mar
(65) |
Apr
(22) |
May
(40) |
Jun
(32) |
Jul
(11) |
Aug
(8) |
Sep
(3) |
Oct
(41) |
Nov
(34) |
Dec
(12) |
2009 |
Jan
(44) |
Feb
(33) |
Mar
(16) |
Apr
(109) |
May
(11) |
Jun
(22) |
Jul
(21) |
Aug
(37) |
Sep
(5) |
Oct
(23) |
Nov
(7) |
Dec
(7) |
2010 |
Jan
(36) |
Feb
(40) |
Mar
(35) |
Apr
(45) |
May
(42) |
Jun
(104) |
Jul
(135) |
Aug
(50) |
Sep
(65) |
Oct
(110) |
Nov
(129) |
Dec
(75) |
2011 |
Jan
(105) |
Feb
(48) |
Mar
(93) |
Apr
(166) |
May
(169) |
Jun
(188) |
Jul
(106) |
Aug
(33) |
Sep
(85) |
Oct
(46) |
Nov
(102) |
Dec
(105) |
2012 |
Jan
(81) |
Feb
(115) |
Mar
(56) |
Apr
(93) |
May
(56) |
Jun
(77) |
Jul
(88) |
Aug
(52) |
Sep
(72) |
Oct
(16) |
Nov
(70) |
Dec
(70) |
2013 |
Jan
(23) |
Feb
(85) |
Mar
(38) |
Apr
(48) |
May
(40) |
Jun
(49) |
Jul
(33) |
Aug
(28) |
Sep
(66) |
Oct
(28) |
Nov
(28) |
Dec
(16) |
2014 |
Jan
(33) |
Feb
(58) |
Mar
(17) |
Apr
(50) |
May
(16) |
Jun
(24) |
Jul
(19) |
Aug
(32) |
Sep
(10) |
Oct
(10) |
Nov
(4) |
Dec
(10) |
2015 |
Jan
(11) |
Feb
(2) |
Mar
(4) |
Apr
(14) |
May
(1) |
Jun
(6) |
Jul
(16) |
Aug
(29) |
Sep
(6) |
Oct
(26) |
Nov
(10) |
Dec
|
2016 |
Jan
|
Feb
(20) |
Mar
(6) |
Apr
|
May
(3) |
Jun
(3) |
Jul
|
Aug
(16) |
Sep
(6) |
Oct
|
Nov
(15) |
Dec
|
2017 |
Jan
(1) |
Feb
(2) |
Mar
(4) |
Apr
|
May
(1) |
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2018 |
Jan
|
Feb
(8) |
Mar
(10) |
Apr
(16) |
May
|
Jun
(15) |
Jul
|
Aug
(3) |
Sep
(19) |
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
(1) |
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(3) |
Oct
|
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
|
Jul
(7) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2021 |
Jan
(5) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(5) |
Jul
(3) |
Aug
|
Sep
(6) |
Oct
(2) |
Nov
(4) |
Dec
|
2022 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
(1) |
May
|
Jun
(5) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2023 |
Jan
(5) |
Feb
(1) |
Mar
|
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2024 |
Jan
|
Feb
(3) |
Mar
(1) |
Apr
(1) |
May
(11) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
(3) |
Dec
|
From: Travis <lib...@gm...> - 2016-06-07 13:06:17
|
Greetings, STmK is just a threaded reader/writer for a USB pipe. You should be able to do something similar. Regards, Travis On 6/7/2016 12:28 AM, Chris E wrote: > Hi guys. > As the title suggests, I need to port some libusbK code to a different > library in order to make it cross-platform. > > The software uses both control requests handled by UsbK, and > isochronous requests handled by StmK. > > I've looked into libusb-1.0, and it looks like it will be simple to > port the UsbK code. However, I couldn't see any immediate equivalent > to StmK. > > Is there a way to set up something similar to StmK in libusb-1.0? > Alternatively, is there another library with cross-platform support > and an StmK-like module? > > Thanks, > ~Chris > > > > > ------------------------------------------------------------------------------ > What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic > patterns at an interface-level. Reveals which users, apps, and protocols are > consuming the most bandwidth. Provides multi-vendor support for NetFlow, > J-Flow, sFlow and other flows. Make informed decisions using capacity > planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e > > > _______________________________________________ > Libusb-win32-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel |
From: Isaac A. <IA...@mt...> - 2016-06-07 12:23:44
|
///////////////////////////////////////////////////////////////////////////// // USBCommunicationsInterface.cpp : implementation file ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "USBCommunicationsInterface.h" #include "mti_lib/cpp/common/HighResolutionTimer.h" //////////////////////////////////////////////////////////////////////////// // DECLARATIONS //////////////////////////////////////////////////////////////////////////// #define COMMAND_EP_WRITE 0x01 #define COMMAND_EP_READ 0x81 #define STREAM_EP_READ 0x82 //---------------------------------------- // STREAMING // // It is unclear what the ideal values for // these parameters are. These values were // copied directly from an example because // they work. //---------------------------------------- #define MAX_XFER_SIZE 4096 // Maximum number of bytes transferred at once (see UsbK_GetPipePolicy) #define MAX_PEND_XFERS 128 // Maximum number of transfers to store at one time #define MAX_PEND_IO 3 // Maximum number of overlapped IO transfers pending at one time CUSBCommunicationsInterface::CUSBCommunicationsInterface(void) //===================================================================== //===================================================================== { mpDeviceNames = 0; mpDeviceModel = 0; mpDeviceSerial = 0; mpDeviceVersion = 0; mDeviceCount = 0; mDeviceIndex = -1; #ifdef USE_LIBUSBK mpKDeviceList = 0; mKDeviceList = NULL; mKHandle = NULL; mKStmHandle = NULL; #else mHandle = NULL; mpStreamThread = 0; mStreamState = 0; mPartialDataIndex = 0; mPartialDataItem = NULL; mPendingIO = 0; mPendingTransfer = 0; libusb_init(NULL); libusb_set_debug(NULL, 3); #if defined LINUX_TARGET sem_init(&mStopStream, 0, 0); sem_init(&mStreamStartStop, 0, 0); pthread_mutex_init(&mCS, NULL); #endif #endif mVID = MTI_VID; //MTII mPID = DACC_PID; //default to DACC mPrintTraceMessages = TRUE; } CUSBCommunicationsInterface::~CUSBCommunicationsInterface(void) //===================================================================== //===================================================================== { if(mpDeviceNames) { delete[] mpDeviceNames; mpDeviceNames = 0; } if(mpDeviceModel) { delete[] mpDeviceModel; mpDeviceModel = 0; } if(mpDeviceSerial) { delete[] mpDeviceSerial; mpDeviceSerial = 0; } if(mpDeviceVersion) { delete[] mpDeviceVersion; mpDeviceVersion = 0; } mDeviceCount = 0; mDeviceIndex = -1; #ifdef USE_LIBUSBK if(mKStmHandle) { StmK_Free(mKStmHandle); mKStmHandle = 0; } if(mKHandle) { mKUsb.Free(mKHandle); mKHandle = NULL; } if(mKDeviceList) { LstK_Free(mKDeviceList); mKDeviceList = NULL; } if(mpKDeviceList) { delete[] mpKDeviceList; mpKDeviceList = 0; } #else if(mHandle) { libusb_close(mHandle); mHandle = NULL; } libusb_exit(NULL); #if defined LINUX_TARGET pthread_mutex_destroy(&mCS); #endif #endif } int CUSBCommunicationsInterface::GetDeviceIndex( CString name ) //===================================================================== // GetDeviceIndex - Scan our list of USB Devices // for one with name. // // Return -1 if not found // Index number if found //===================================================================== { for(int i=0; i<mDeviceCount; i++) { if( mpDeviceNames[i].Compare(name) == 0 ) { return i; } } return -1; } CString CUSBCommunicationsInterface::GetDeviceName( int index ) //===================================================================== // GetDeviceName - Return the name string at index. // // Return NULL if bad index //===================================================================== { if(index < mDeviceCount) { return mpDeviceNames[index]; } else { return CString(""); } } CString CUSBCommunicationsInterface::GetDeviceModelNumber( int index ) //===================================================================== // GetDeviceModelNumber - Return the model number string at index. // // Return NULL if bad index //===================================================================== { if(index < mDeviceCount) { return mpDeviceModel[index]; } else { return CString(""); } } CString CUSBCommunicationsInterface::GetDeviceSerialNumber( int index ) //===================================================================== // GetDeviceSerialNumber - Return the serial number string at index. // // Return NULL if bad index //===================================================================== { if(index < mDeviceCount) { return mpDeviceSerial[index]; } else { return CString(""); } } CString CUSBCommunicationsInterface::GetDeviceSoftwareVersion( int index ) //===================================================================== // GetDeviceSoftwareVersion - Return the software version string at index. // // Return NULL if bad index //===================================================================== { if(index < mDeviceCount) { return mpDeviceVersion[index]; } else { return CString(""); } } int CUSBCommunicationsInterface::ConnectToDevice( CString name ) //===================================================================== // ConnectToDevice - Attempt to open a connection to device by name // // Return 0 if success //===================================================================== { int index = GetDeviceIndex(name); if(index >= 0) { return ConnectToDevice(index); } else { return 1; } } void CUSBCommunicationsInterface::Disconnect(void) //===================================================================== // Disconnect - Disconnect from all USB devices & free handle //===================================================================== { StopStream(); //------------------------------------------------------------------ // Release the interface //------------------------------------------------------------------ #ifdef USE_LIBUSBK if(mKHandle) { mKUsb.ReleaseInterface(mKHandle,0,TRUE); mKUsb.Free(mKHandle); mKHandle = NULL; } #else if(mHandle) { libusb_release_interface(mHandle, 0); libusb_close(mHandle); mHandle = NULL; } #endif mDeviceIndex = -1; } bool CUSBCommunicationsInterface::IsConnected(void) //===================================================================== //===================================================================== { #ifdef USE_LIBUSBK if(mKHandle != NULL && mDeviceIndex != -1) #else if(mHandle != NULL && mDeviceIndex != -1) #endif { return true; } else { return false; } } bool CUSBCommunicationsInterface::ReadyToStream(void) //===================================================================== //===================================================================== { #ifdef USE_LIBUSBK if(mKStmHandle != NULL) #else if( mStreamState == 1 ) #endif { return true; } else { return false; } } int CUSBCommunicationsInterface::WriteCommand(const char *buffer, int bytesToWrite, int *bytesWritten) //===================================================================== // Write - Write data to USB port // // INPUTS: buffer - buffer contining data to write // bytesToWrite - number of bytes to write // // OUTPUTS: bytesWritten - bytes actually written // // RETURNS: status code // 0 = OK // -1 = device not open // 8 = Error From WritePipe // 10 = Write Timeout //===================================================================== { if(bytesWritten) *bytesWritten = 0; #ifdef USE_LIBUSBK if(!mKHandle) #else if(!mHandle) #endif { return -1; } if( bytesToWrite <= 0 ) { return 0; } //------------------------------------------------------------------ // Set the Timeout of WritePipe() for the Command OUT endpoint //------------------------------------------------------------------ #ifdef USE_LIBUSBK UINT newPipeTimeout = 1000; BOOL success = mKUsb.SetPipePolicy(mKHandle, COMMAND_EP_WRITE, PIPE_TRANSFER_TIMEOUT, sizeof(UINT), &newPipeTimeout); if (!success) { if(mPrintTraceMessages) { TRACE("Error From SetPipePolicy(USB)=%d\n", GetLastError()); } return 9; } #endif #ifdef USE_LIBUSBK PUCHAR sendBuffer = (PUCHAR)buffer; UINT bufferLength = bytesToWrite; UINT lengthTransferred = 0; success = mKUsb.WritePipe(mKHandle, COMMAND_EP_WRITE, sendBuffer, bufferLength, &lengthTransferred, NULL); if(success) { *bytesWritten = lengthTransferred; return 0; } else { return 8; } #else unsigned char * sendBuffer = (unsigned char *)buffer; int bufferLength = bytesToWrite; int lengthTransferred = 0; int rc = libusb_bulk_transfer(mHandle, COMMAND_EP_WRITE, sendBuffer, bufferLength, &lengthTransferred, 1000); if(rc == 0) { *bytesWritten = lengthTransferred; return 0; } else if(rc == LIBUSB_ERROR_TIMEOUT) { return 10; } else { return 8; } #endif } int CUSBCommunicationsInterface::ReadResponse(char *buffer, int maxBytesToRead, int *bytesRead, int tmo) //===================================================================== // Read - Read a line from USB command IN endpoint // // INPUTS: buffer - read buffer // maxBytesToRead - max size of read buffer // timeout - timeout (milliseconds) // // OUTPUTS: bytesRead - bytes actually read // // RETURNS: status code // 0 = OK // -1 = Port not open // 9 = Error From ReadPipe // 10 = Read Timeout //===================================================================== { CString text; if(bytesRead) *bytesRead = 0; if(buffer) memset(buffer, 0, maxBytesToRead); #ifdef USE_LIBUSBK if(!mKHandle) #else if(!mHandle) #endif { return -1; } if( maxBytesToRead <= 0 ) { return 0; } #ifdef USE_LIBUSBK //------------------------------------------------------------------ // Set the Timeout of ReadPipe() for the Command IN endpoint //------------------------------------------------------------------ UINT newPipeTimeout = tmo; BOOL success = mKUsb.SetPipePolicy(mKHandle, COMMAND_EP_READ, PIPE_TRANSFER_TIMEOUT, sizeof(UINT), &newPipeTimeout); if (!success) { if(mPrintTraceMessages) { TRACE("Usb.SetPipePolicy failed. (0x%08X)\n", GetLastError()); } return 9; } #endif CHighResolutionTimer timer; timer.StartTimer(); unsigned char internalBuffer[64]; int count = 0; #ifdef USE_LIBUSBK UINT numRead = 0; while(1) { success = mKUsb.ReadPipe(mKHandle, COMMAND_EP_READ, &internalBuffer[0], 1, &numRead, NULL); if( !success ) { if(mPrintTraceMessages) { text.Format("Error From ReadPipe(USB)=%d\n", GetLastError()); TRACE((const char*)text); } *bytesRead = count; return 9; } else if(numRead == 0) { if(mPrintTraceMessages) { text.Format("Timeout From ReadPipe(USB)=%d\n", GetLastError()); TRACE((const char*)text); } *bytesRead = count; return 10; } else if(internalBuffer[0] < ' ') { if(internalBuffer[0] == '\n') { *bytesRead = count; break; } } else if(*bytesRead < maxBytesToRead) { buffer[count] = internalBuffer[0]; count += numRead; } // Check for timeout if( tmo > 0 ) { if( timer.GetTimeInMilliSeconds() > (double)tmo ) { *bytesRead = count; return 10; } } } #else int numRead = 0; while(1) { int rc = libusb_bulk_transfer(mHandle, COMMAND_EP_READ, &internalBuffer[0], 64, &numRead, (unsigned int)tmo); if( rc == LIBUSB_ERROR_TIMEOUT) { if(mPrintTraceMessages) { text.Format("Timeout From ReadPipe(USB)=%d\n", rc); TRACE((const char*)text); } *bytesRead = count; return 10; } else if( rc != 0 ) { if(mPrintTraceMessages) { text.Format("Error From ReadPipe(USB)=%d\n", rc); TRACE((const char*)text); } *bytesRead = count; return 9; } else { if(numRead == 0) { if(mPrintTraceMessages) { text.Format("No Data From ReadPipe(USB)=%d\n", rc); TRACE((const char*)text); } *bytesRead = count; return 9; } else if(internalBuffer[numRead-1] < ' ') { if(internalBuffer[numRead-1] == '\n') { memcpy(&buffer[count], &internalBuffer[0], numRead-1); count += (numRead-1); *bytesRead = count; break; } } else if(*bytesRead < maxBytesToRead) { memcpy(&buffer[count], &internalBuffer[0], numRead); count += numRead; } } // Check for timeout if( tmo > 0 ) { if( timer.GetTimeInMilliSeconds() > (double)tmo ) { *bytesRead = count; return 10; } } } #endif return 0; } int CUSBCommunicationsInterface::ReadStreaming(char *buffer, int minBytesToRead, int maxBytesToRead, int *bytesRead, int tmo) //===================================================================== // ReadStreaming - Read data from USB Streaming IN endpoint. // // INPUTS: buffer - read buffer // minBytesToRead - min number of bytes to read before returning (set to -1 if unused) // maxBytesToRead - max size of read buffer // timeout - timeout (milliseconds) // // OUTPUTS: bytesRead - bytes actually read // // RETURNS: status code // 0 = OK // -1 = Port not open // 9 = Error From ReadPipe // 10 = Read Timeout //===================================================================== { if(bytesRead) *bytesRead = 0; #ifdef USE_LIBUSBK if(!mKStmHandle) #else if(!mpStreamThread) #endif { return -1; } if( maxBytesToRead <= 0 || minBytesToRead <= 0 ) { return 0; } if(buffer) memset(buffer, 0, maxBytesToRead); CHighResolutionTimer timer; timer.StartTimer(); int retVal = 0; unsigned char * recBuffer = (unsigned char *)buffer; UINT bufferLength = maxBytesToRead; int totalTransferred = 0; while( totalTransferred < minBytesToRead ) { UINT transferred = 0; #ifdef USE_LIBUSBK BOOL success = StmK_Read(mKStmHandle, recBuffer, 0, bufferLength, &transferred); if(success) { totalTransferred += transferred; bufferLength -= transferred; recBuffer = (PUCHAR)&buffer[totalTransferred]; } else { // If the return result is ERROR_NO_MORE_ITEMS then there is no more data // to read. Other errors indicate a problem. if (GetLastError() != ERROR_NO_MORE_ITEMS) { retVal = 9; break; } // Handle ERROR_NO_MORE_ITEMS: // Do nothing } #else int rc = StreamRead(recBuffer, bufferLength, &transferred); if(rc == 0) { totalTransferred += transferred; bufferLength -= transferred; recBuffer = (unsigned char *)&buffer[totalTransferred]; } else { // If the return result is ERROR_NO_MORE_ITEMS then there is no more data // to read. Other errors indicate a problem. if (rc != 1) { retVal = 9; break; } // Handle ERROR_NO_MORE_ITEMS: // Do nothing } #endif // Check for timeout if( tmo > 0 ) { if( timer.GetTimeInMilliSeconds() > (double)tmo ) { retVal = 10; break; } } } *bytesRead = totalTransferred; return retVal; } int CUSBCommunicationsInterface::FlushCommand(void) //===================================================================== // FlushCommand - Flush command endpoint input and output pipes // // INPUTS: none // // OUTPUTS: none // // RETURNS: status code // -1 = Port not open // 0 = OK // 7 = Error From FlushPipe //===================================================================== { #ifdef USE_LIBUSBK if(!mKHandle) { return -1; } if( mKUsb.FlushPipe(mKHandle, COMMAND_EP_READ) == false ) { return 7; } if( mKUsb.FlushPipe(mKHandle, COMMAND_EP_WRITE) == false ) { return 7; } #endif return 0; } int CUSBCommunicationsInterface::FlushStreaming(void) //===================================================================== // FlushStreaming - Flush streaming endpoint input pipe // // Note: This is not normally called // // INPUTS: none // // OUTPUTS: none // // RETURNS: status code // -1 = Port not open // 0 = OK // 7 = Error From FlushPipe //===================================================================== { #ifdef USE_LIBUSBK if(!mKHandle) { return -1; } if( mKUsb.FlushPipe(mKHandle, STREAM_EP_READ) == false ) { return 7; } #endif return 0; } //********************************************************************************** //********************************************************************************** //********************************************************************************** //********************************************************************************** //********************************************************************************** //********************************************************************************** // LIBUSBK #ifdef USE_LIBUSBK //int CUSBCommunicationsInterface::FindAllDevices(int maxDevices) //{ //} int CUSBCommunicationsInterface::FindAllDevices(int maxDevices) //===================================================================== // FindAllUSBDevices - Scan USB Devices for ones that match // MTII USB VID and PID. // // Allocate and build list of USB Devices // Return number of devices found //===================================================================== { BYTE buffer1[128]; BYTE buffer2[128]; //--------------------------- // Delete previous nodes list //--------------------------- if(mpKDeviceList) { delete[] mpKDeviceList; mpKDeviceList = 0; } if(mpDeviceNames) { delete[] mpDeviceNames; mpDeviceNames = 0; } if(mpDeviceModel) { delete[] mpDeviceModel; mpDeviceModel = 0; } if(mpDeviceSerial) { delete[] mpDeviceSerial; mpDeviceSerial = 0; } if(mpDeviceVersion) { delete[] mpDeviceVersion; mpDeviceVersion = 0; } mDeviceCount = 0; //----------------------- // Allocate new device list //----------------------- if(maxDevices > 0) { mpKDeviceList = new KLST_DEVINFO_HANDLE[maxDevices]; mpDeviceNames = new CString[maxDevices]; mpDeviceModel = new CString[maxDevices]; mpDeviceSerial = new CString[maxDevices]; mpDeviceVersion = new CString[maxDevices]; } //------------------------------------------------------------------ // Get the device list & make sure one or more devices were found //------------------------------------------------------------------ UINT deviceCount = 0; KLST_DEVINFO_HANDLE deviceInfo = NULL; if ( !LstK_Init(&mKDeviceList, (KLST_FLAG)0) ) { if(mPrintTraceMessages) { TRACE("Error Initializing USB Device List.\n"); } return 0; } LstK_Count(mKDeviceList, &deviceCount); if(deviceCount == 0) { if(mPrintTraceMessages) { TRACE("Device list empty.\n"); } SetLastError(ERROR_DEVICE_NOT_CONNECTED); // If LstK_Init returns TRUE, the list must be freed. LstK_Free(mKDeviceList); return 0; } //------------------------------------------------------------------ // Look For MTII USB devices //------------------------------------------------------------------ if(mPrintTraceMessages) { TRACE("Looking for USB Devices by vid/pid %04X/%04X..\n", mVID, mPID); } //------------------------------------------------------------------ // Enumerate the device list using it's internal "current" position. //------------------------------------------------------------------ unsigned int lengthTransferred; LstK_MoveReset(mKDeviceList); //Reset the device list position //------------------------------------------------------------------ // Call LstK_MoveNext after a LstK_MoveReset to advance to the first element. //------------------------------------------------------------------ while( LstK_MoveNext(mKDeviceList, &deviceInfo) && ( mDeviceCount < maxDevices) ) { if( deviceInfo->Common.Vid == mVID && deviceInfo->Common.Pid == mPID ) { //------------------------------------------------------------------ // Load the device driver //------------------------------------------------------------------ LibK_LoadDriverAPI(&mKUsb, deviceInfo->DriverID); //------------------------------------------------------------------ // Initialize the device //------------------------------------------------------------------ mKUsb.Init(&mKHandle, deviceInfo); //------------------------------------------------------------------ // Get the Friendly Name of the device // // 0x0409 is the USB-IF language index for American English //------------------------------------------------------------------ memset(buffer1, 0, sizeof(buffer1)); BOOL fname_retv = mKUsb.GetDescriptor(mKHandle, USB_DESCRIPTOR_TYPE_STRING, 6, 0x0409, buffer1, sizeof(buffer1), &lengthTransferred); PUSB_STRING_DESCRIPTOR name = (PUSB_STRING_DESCRIPTOR)buffer1; //------------------------------------------------------------------ // Get the model number of the device // // 0x0409 is the USB-IF language index for American English //------------------------------------------------------------------ memset(buffer2, 0, sizeof(buffer2)); BOOL model_retv = mKUsb.GetDescriptor(mKHandle, USB_DESCRIPTOR_TYPE_STRING, 7, 0x0409, buffer2, sizeof(buffer2), &lengthTransferred); PUSB_STRING_DESCRIPTOR model = (PUSB_STRING_DESCRIPTOR)buffer2; //------------------------------------------------------------------ // Save Serial Number //------------------------------------------------------------------ mpDeviceSerial[mDeviceCount] = deviceInfo->SerialNumber; //------------------------------------------------------------------ // Free the device handle //------------------------------------------------------------------ mKUsb.Free(mKHandle); //------------------------------------------------------------------ // Save the friendly name of the device & deviceInfo pointer //------------------------------------------------------------------ mpKDeviceList[mDeviceCount] = deviceInfo; if(fname_retv) mpDeviceNames[mDeviceCount] = name->bString; else mpDeviceNames[mDeviceCount] = "unavailable"; if(model_retv) mpDeviceModel[mDeviceCount] = model->bString; else mpDeviceModel[mDeviceCount] = "unavailable"; mpDeviceVersion[mDeviceCount] = ""; ++mDeviceCount; //------------------------------------------------------------------ // print some information about the device. //------------------------------------------------------------------ if(mPrintTraceMessages) { TRACE("[%d]: %ls %04X:%04X (%s-%s): %s - %s\n", mDeviceCount, name->bString, deviceInfo->Common.Vid, deviceInfo->Common.Pid, deviceInfo->Common.InstanceID, deviceInfo->SerialNumber, deviceInfo->DeviceDesc, deviceInfo->Mfg); } } } return mDeviceCount; } int CUSBCommunicationsInterface::ConnectToDevice( int index ) //===================================================================== // ConnectToDevice - Attempt to open a connection to device by index // // Return 0 if success // 1 if set-up failure // 2 if device busy //===================================================================== { if(index >= mDeviceCount) { return 1; } //------------------------------------------------------------------ // Load the device driver //------------------------------------------------------------------ if( !LibK_LoadDriverAPI(&mKUsb, mpKDeviceList[index]->DriverID) ) { if(mPrintTraceMessages) { TRACE("LibK_LoadDriverAPI failed. ErrorCode: %08Xh\n", GetLastError()); } return 1; } //------------------------------------------------------------------ // Initialize the device //------------------------------------------------------------------ if (!mKUsb.Init(&mKHandle, mpKDeviceList[index])) { if(mPrintTraceMessages) { TRACE("Usb.Init failed. ErrorCode: %08Xh\n", GetLastError()); } return 1; } mDeviceIndex = index; //------------------------------------------------------------------ // Claim the interface // - This step is not necessary when using WinUSB, but is included // for completeness //------------------------------------------------------------------ BOOL success = mKUsb.ClaimInterface(mKHandle,0,TRUE); if( !success ) { DWORD err = GetLastError(); if( err == ERROR_BUSY ) { TRACE("Usb.ClaimInterface failed - Device Busy"); return 2; } else { TRACE("Usb.ClaimInterface failed. (0x%08X)\n", err); return 1; } } //------------------------------------------------------------------ // Set the Timeout of ReadPipe() for the Command IN endpoint //------------------------------------------------------------------ UINT newPipeTimeout = 10000; //Time-out in milliseconds success = mKUsb.SetPipePolicy(mKHandle, COMMAND_EP_READ, PIPE_TRANSFER_TIMEOUT, sizeof(UINT), &newPipeTimeout); if (!success && mPrintTraceMessages) { TRACE("Usb.SetPipePolicy failed. (0x%08X)\n", GetLastError()); } //------------------------------------------------------------------ // Start streaming thread on Streaming IN endpoint //------------------------------------------------------------------ int rc = StartStream(); if( rc != 0 && mPrintTraceMessages) { TRACE("StartStream() failed. ErrorCode: %08Xh\n", rc); } if(mPrintTraceMessages) { TRACE("Device opened successfully!\n"); } return 0; } int CUSBCommunicationsInterface::StartStream(void) //===================================================================== // ConnectToStream - Initialize the Stream // // INPUTS: none // // RETURNS: status code // 0 = OK // -1 = device not open // 1 = error from Init // 2 = error from Start //===================================================================== { if(mKStmHandle) { return 0; } if(!mKHandle) { return -1; } CString text; BOOL success; //------------------------------------------------------------------ // Initialize the stream. //------------------------------------------------------------------ success = StmK_Init(&mKStmHandle, mKHandle, STREAM_EP_READ, MAX_XFER_SIZE, MAX_PEND_XFERS, MAX_PEND_IO, NULL, KSTM_FLAG_NONE); if (!success) { if(mPrintTraceMessages) { text.Format("StmK_Init failed. ErrorCode: %08Xh\n", GetLastError()); TRACE((const char*)text); } return 1; } //------------------------------------------------------------------ // Start the stream. //------------------------------------------------------------------ success = StmK_Start(mKStmHandle); if (!success) { StmK_Free(mKStmHandle); mKStmHandle = 0; if(mPrintTraceMessages) { text.Format("StmK_Start failed. ErrorCode: %08Xh\n", GetLastError()); TRACE((const char*)text); } return 2; } return 0; } void CUSBCommunicationsInterface::StopStream(void) //===================================================================== // StopStream - Stop the stream and free resources. // // According to the documentation StmK_Free will also stop the stream // before freeing resources, but I found that if the device has been // disconnected StmK_Stop will fail and StmK_Free will crash the program. //===================================================================== { BOOL success; CString text; if(mKStmHandle) { success = StmK_Stop(mKStmHandle, 0); if (!success) { if(mPrintTraceMessages) { text.Format("StmK_Stop failed. ErrorCode: %08Xh\n", GetLastError()); TRACE((const char*)text); } } else { StmK_Free(mKStmHandle); } mKStmHandle = 0; } } int CUSBCommunicationsInterface::ReadCommand(char *buffer, int maxBytesToRead, int *bytesRead, int tmo) //===================================================================== // Read - Read data from USB command IN endpoint // // INPUTS: buffer - read buffer // maxBytesToRead - max size of read buffer // timeout - timeout (milliseconds) // // OUTPUTS: bytesRead - bytes actually read // // RETURNS: status code // 0 = OK // -1 = Port not open // 9 = Error From ReadPipe // 10 = Read Timeout // // // ---- THIS FUNCTION IS UNUSED ---- //===================================================================== { if(bytesRead) *bytesRead = 0; if(buffer) memset(buffer, 0, maxBytesToRead); if(!mKHandle) { return -1; } if( maxBytesToRead <= 0 ) { return 0; } PUCHAR recBuffer = (PUCHAR)buffer; UINT bufferLength = maxBytesToRead; UINT lengthTransferred; BOOL success = mKUsb.ReadPipe(mKHandle, COMMAND_EP_READ, recBuffer, bufferLength, &lengthTransferred, NULL); if(success) { *bytesRead = lengthTransferred; return 0; } else { return 9; } } //********************************************************************************** //********************************************************************************** //********************************************************************************** //********************************************************************************** //********************************************************************************** //********************************************************************************** // LibUsb 1.0 #else int CUSBCommunicationsInterface::FindAllDevices(int maxDevices) //===================================================================== // FindAllUSBDevices - Scan USB Devices for ones that match // MTII USB VID and PID. // // Allocate and build list of USB Devices // Return number of devices found //===================================================================== { const char * buffer1[128]; //--------------------------- // Delete previous nodes list //--------------------------- if(mpDeviceNames) { delete[] mpDeviceNames; mpDeviceNames = 0; } if(mpDeviceModel) { delete[] mpDeviceModel; mpDeviceModel = 0; } if(mpDeviceSerial) { delete[] mpDeviceSerial; mpDeviceSerial = 0; } if(mpDeviceVersion) { delete[] mpDeviceVersion; mpDeviceVersion = 0; } mDeviceCount = 0; //----------------------- // Allocate new device list //----------------------- if(maxDevices > 0) { mpDeviceNames = new CString[maxDevices]; mpDeviceModel = new CString[maxDevices]; mpDeviceSerial = new CString[maxDevices]; mpDeviceVersion = new CString[maxDevices]; } //------------------------------------------------------------------ // Get the device list & make sure one or more devices were found //------------------------------------------------------------------ libusb_device **devs; ssize_t cnt = libusb_get_device_list(NULL, &devs); if (cnt < 0) { if(mPrintTraceMessages) { TRACE("Error Initializing USB Device List.\n"); } return 0; } else if(cnt == 0) { if(mPrintTraceMessages) { TRACE("Device list empty.\n"); } libusb_free_device_list(devs, 1); return 0; } //------------------------------------------------------------------ // Look For MTII USB devices //------------------------------------------------------------------ if(mPrintTraceMessages) { TRACE("Looking for USB Devices by vid/pid %04X/%04X..\n", mVID, mPID); } libusb_device *dev; int i = 0; while ((dev = devs[i++]) != NULL) { struct libusb_device_descriptor desc; int r = libusb_get_device_descriptor(dev, &desc); if (r == 0) { if( desc.idVendor == mVID && desc.idProduct == mPID ) { libusb_device_handle *handle; r = libusb_open(dev, &handle); if (r == 0) { //******************************* // String descriptors //******************************* // 0 g_pLangDescriptor, // 1 g_pManufacturerString, // 2 g_pProductString, // 3 g_pSerialNumberString, // 4 g_pConfigString, // 5 g_pInterfaceString, // 6 g_pFriendlyNameString, // 7 g_pModelNumberString, // 8 g_pFirmwareVersionString r = libusb_get_string_descriptor_ascii(handle, 3, (unsigned char*)buffer1, 128); if (r >= 0) { mpDeviceSerial[mDeviceCount] = CString((const char*)buffer1); } else { mpDeviceSerial[mDeviceCount] = "unavailable"; } r = libusb_get_string_descriptor_ascii(handle, 6, (unsigned char*)buffer1, 128); if (r >= 0) { mpDeviceNames[mDeviceCount] = CString((const char*)buffer1); } else { mpDeviceNames[mDeviceCount] = "unavailable"; } r = libusb_get_string_descriptor_ascii(handle, 7, (unsigned char*)buffer1, 128); if (r >= 0) { mpDeviceModel[mDeviceCount] = CString((const char*)buffer1); } else { mpDeviceModel[mDeviceCount] = "unavailable"; } r = libusb_get_string_descriptor_ascii(handle, 8, (unsigned char*)buffer1, 128); if (r >= 0) { mpDeviceVersion[mDeviceCount] = CString((const char*)buffer1); } else { mpDeviceVersion[mDeviceCount] = "unavailable"; } libusb_close(handle); ++mDeviceCount; } } } } libusb_free_device_list(devs, 1); return mDeviceCount; } int CUSBCommunicationsInterface::ConnectToDevice( int index ) //===================================================================== // ConnectToDevice - Attempt to open a connection to device by index // // Return 0 if success // 1 if set-up failure // 2 if device busy //===================================================================== { char buffer1[128]; if(index >= mDeviceCount) { return 1; } //*************************************************************** // Search attached USB devices to find one that matches the index //*************************************************************** libusb_device **devs; ssize_t cnt = libusb_get_device_list(NULL, &devs); if (cnt < 0) { return 1; } else if(cnt == 0) { libusb_free_device_list(devs, 1); return 1; } libusb_device *dev; int i = 0; int r; while ((dev = devs[i++]) != NULL) { struct libusb_device_descriptor desc; r = libusb_get_device_descriptor(dev, &desc); if (r == 0) { if( desc.idVendor == mVID && desc.idProduct == mPID ) { libusb_device_handle *handle; r = libusb_open(dev, &handle); if (r == 0) { int matches = 0; r = libusb_get_string_descriptor_ascii(handle, 3, (unsigned char*)buffer1, 128); if (r >= 0) { if( strcmp(mpDeviceSerial[index], buffer1) == 0 ) { matches++; } } r = libusb_get_string_descriptor_ascii(handle, 6, (unsigned char*)buffer1, 128); if (r >= 0) { if( strcmp(mpDeviceNames[index], buffer1) == 0 ) { matches++; } } r = libusb_get_string_descriptor_ascii(handle, 7, (unsigned char*)buffer1, 128); if (r >= 0) { if( strcmp(mpDeviceModel[index], buffer1) == 0 ) { matches++; } } r = libusb_get_string_descriptor_ascii(handle, 8, (unsigned char*)buffer1, 128); if (r >= 0) { if( strcmp(mpDeviceVersion[index], buffer1) == 0 ) { matches++; } } if(matches > 0) //If anything matches, we will assume it is the correct unit { mDeviceIndex = index; mHandle = handle; } else { libusb_close(handle); } } } } } libusb_free_device_list(devs, 1); if(mHandle == NULL) { return 1; } //------------------------------------------------------------------ // Claim the interface //------------------------------------------------------------------ r = libusb_claim_interface(mHandle, 0); if( r == LIBUSB_ERROR_BUSY ) { if(mPrintTraceMessages) { TRACE("Usb.ClaimInterface failed - Device Busy"); } return 2; } else if( r != 0 ) { if(mPrintTraceMessages) { TRACE("Usb.ClaimInterface failed. (0x%08X)\n", r); } return 1; } //------------------------------------------------------------------ // Start streaming thread on Streaming IN endpoint //------------------------------------------------------------------ int rc = StartStream(); if( rc != 0 && mPrintTraceMessages) { TRACE("StartStream() failed. ErrorCode: %08Xh\n", rc); } if(mPrintTraceMessages) { TRACE("Device opened successfully!\n"); } return 0; } #if defined(_WINDOWS) static UINT StartStreamThread(void *pObj) //===================================================================== // StartStreamThread -- Helper function for stream thread //===================================================================== { if(pObj) { return ((CUSBCommunicationsInterface *)pObj)->StreamThread(); } return 0; } #elif defined LINUX_TARGET void * StartStreamThread(void *pObj) //===================================================================== // StartStreamThread -- Helper function for starting a task //===================================================================== { if(pObj) { ((CUSBCommunicationsInterface *)pObj)->StreamThread(); } return NULL; } #endif int CUSBCommunicationsInterface::StartStream(void) //===================================================================== // ConnectToStream - Initialize the Stream // // INPUTS: none // // RETURNS: status code // 0 = OK // -1 = device not open // 1 = error from Init // 2 = error from Start //===================================================================== { if(!mHandle) { return -1; } //---------------------------- // Is streaming already Active //---------------------------- if(mpStreamThread != 0) { return -1; } //------------------------------------------------------------------ // Initialize the stream. //------------------------------------------------------------------ mStreamState = 0; //----------------- // Reset our events //----------------- #if defined(_WINDOWS) mStopStream.ResetEvent(); mStreamStartStop.ResetEvent(); #elif defined(LINUX_TARGET) while(sem_trywait(&mStopStream) == 0); while(sem_trywait(&mStreamStartStop) == 0); #endif #if defined(_WINDOWS) //------------------------------------------------------------------ // Start the stream - WINDOWS //------------------------------------------------------------------ mpStreamThread = AfxBeginThread(::StartStreamThread, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); if(mpStreamThread == 0) //AfxBeginThread failed { return 2; } mpStreamThread->m_bAutoDelete = TRUE; //This is the default mpStreamThread->ResumeThread(); #elif defined LINUX_TARGET //------------------------------------------------------------------ // Start the stream - LINUX //------------------------------------------------------------------ int rc = pthread_create(&mpStreamThread, NULL, ::StartStreamThread, this); if(rc != 0) { return 2; } #endif if(mpStreamThread == 0) //StreamThread shut itself down { return 2; } return 0; } int CUSBCommunicationsInterface::StreamThread() //===================================================================== // StreamThread //===================================================================== { #if defined(_WINDOWS) DWORD dwResult; #elif defined LINUX_TARGET int rc; #endif std::map<void*, bool>::iterator map_it; std::list<unsigned char *>::iterator list_it; struct libusb_transfer *xfr = NULL; struct timeval zero_tv; zero_tv.tv_sec = 0; zero_tv.tv_usec = 0; mPendingIO = 0; mPendingTransfer = 0; mDataList.clear(); //Allocate buffers mAvailableBuffers.clear(); for(int i=0; i<MAX_PEND_XFERS; i++) { unsigned char * data = (unsigned char*)malloc(MAX_XFER_SIZE); mAvailableBuffers.push_back(data); } //Allocate transfers mTransfers.clear(); for(int i=0; i<MAX_PEND_IO; i++) { xfr = libusb_alloc_transfer(0); mTransfers[(void*)xfr] = false; } mPartialDataItem = NULL; mPartialDataIndex = 0; //-------------- // We are active //-------------- mStreamState = 1; #if defined(_WINDOWS) mStreamStartStop.SetEvent(); //Alert caller #elif defined LINUX_TARGET sem_post(&mStreamStartStop); #endif bool stopMessageReceived; while(1) { //------------------------------------- // Check for STOP STREAM //------------------------------------- stopMessageReceived = FALSE; #if defined (_WINDOWS) dwResult = ::WaitForSingleObject(mStopStream.m_hObject, 0); if(dwResult == WAIT_OBJECT_0) { stopMessageReceived = TRUE; } #elif defined LINUX_TARGET while((rc=sem_trywait(&mStopStream))==-1 && errno==EINTR); if(rc == 0) { stopMessageReceived = TRUE; } #endif if(stopMessageReceived) { // Cancel any pending transfer requests: GetDataAccess(); { for(map_it = mTransfers.begin(); map_it != mTransfers.end(); map_it++) { if(map_it->second == true) { xfr = (struct libusb_transfer*)(map_it->first); int err = libusb_cancel_transfer(xfr); if(mPrintTraceMessages) { if(err) { TRACE("Cancel Transfer Error = %d\n", err); } else { TRACE("Transfer Cancelled\n"); } } } } } ReleaseDataAccess(); } if(libusb_handle_events_timeout_completed(NULL, &zero_tv, NULL) != LIBUSB_SUCCESS) { break; } if( (mStreamState == 1) && (mPendingIO < MAX_PEND_IO) && (mPendingTransfer < MAX_PEND_XFERS) ) { // Submit new transfer SubmitTransfer(); } if( (mStreamState == 2) && (mPendingIO == 0) ) { // Streaming Cancelled and pendingIO cancelled break; } //Sleep(0); } // Free memory GetDataAccess(); { while(mDataList.size() > 0) { DataItem * item = mDataList.back(); free((void*)(item->data)); delete item; mDataList.pop_back(); } for(map_it = mTransfers.begin(); map_it != mTransfers.end(); map_it++) { xfr = (struct libusb_transfer*)(map_it->first); libusb_free_transfer(xfr); } for(list_it = mAvailableBuffers.begin(); list_it != mAvailableBuffers.end(); list_it++) { free(*list_it); } mAvailableBuffers.clear(); } ReleaseDataAccess(); if(mPartialDataItem != NULL) { free(mPartialDataItem->data); delete mPartialDataItem; mPartialDataItem = NULL; } mStreamState = 0; mpStreamThread = 0; #if defined(_WINDOWS) mStreamStartStop.SetEvent(); #elif defined LINUX_TARGET sem_post(&mStreamStartStop); #endif return 0; } void CallbackUSBTransferCompleteHelper(struct libusb_transfer *xfr) //===================================================================== // callbackUSBTransferCompleteHelper -- Helper function for callback //===================================================================== { if(xfr) { ((CUSBCommunicationsInterface *)(xfr->user_data))->CallbackUSBTransferComplete(xfr); } } void CUSBCommunicationsInterface::SubmitTransfer(void) //===================================================================== // SubmitTransfer -- Submit a transfer request to libusb //===================================================================== { struct libusb_transfer *xfr = NULL; unsigned char * data = NULL; std::map<void*, bool>::iterator it; // Find available xfr structure & data buffer GetDataAccess(); { for(it = mTransfers.begin(); it != mTransfers.end(); it++) { if(it->second == false) { xfr = (struct libusb_transfer*)(it->first); } } if(mAvailableBuffers.size() > 0) { data = mAvailableBuffers.front(); } if( (xfr != NULL) && (data != NULL) ) { mTransfers[(void*)xfr] = true; mAvailableBuffers.pop_front(); } } ReleaseDataAccess(); // Configure transfer structure if( (xfr != NULL) && (data != NULL) ) { libusb_fill_bulk_transfer(xfr, mHandle, STREAM_EP_READ, data, MAX_XFER_SIZE, (libusb_transfer_cb_fn)(::CallbackUSBTransferCompleteHelper), this, 0); if(libusb_submit_transfer(xfr) < 0) { // Error GetDataAccess(); { mTransfers[(void*)xfr] = false; mAvailableBuffers.push_back(data); } ReleaseDataAccess(); if(mPrintTraceMessages) { TRACE("Transfer Submit Failed\n"); } } else { ++mPendingIO; ++mPendingTransfer; //TRACE("Transfer Submitted, pendingIO=%d, pendingTransfer=%d\n", mPendingIO, mPendingTransfer); } } } void CUSBCommunicationsInterface::CallbackUSBTransferComplete(struct libusb_transfer *xfr) { DataItem *newItem; switch(xfr->status) { case LIBUSB_TRANSFER_COMPLETED: // Success here, data transfered are inside xfr->buffer // and the length is xfr->actual_length newItem = new DataItem; newItem->size = xfr->actual_length; newItem->data = xfr->buffer; GetDataAccess(); { mDataList.push_front(newItem); mTransfers[(void*)xfr] = false; } ReleaseDataAccess(); --mPendingIO; //TRACE("Transfer Completed, length=%d, pendingIO=%d, pendingTransfer=%d\n", newItem->size, mPendingIO, mPendingTransfer); if( (mPendingIO < MAX_PEND_IO) && (mPendingTransfer < MAX_PEND_XFERS) ) { // Submit new transfer SubmitTransfer(); } break; case LIBUSB_TRANSFER_CANCELLED: case LIBUSB_TRANSFER_NO_DEVICE: case LIBUSB_TRANSFER_TIMED_OUT: case LIBUSB_TRANSFER_ERROR: case LIBUSB_TRANSFER_STALL: case LIBUSB_TRANSFER_OVERFLOW: //libusb_free_transfer(xfr); GetDataAccess(); { mTransfers[(void*)xfr] = false; mAvailableBuffers.push_back(xfr->buffer); } ReleaseDataAccess(); --mPendingIO; if(mPrintTraceMessages) { TRACE("LIBUSB ERROR = %d, PendingIO=%d\n", xfr->status, mPendingIO); } break; } } //**** // TODO: header // returns 0=success // 1=no more items //**** int CUSBCommunicationsInterface::StreamRead(unsigned char * buffer, unsigned int length, unsigned int * transferredLength) { int list_size; if(!buffer) return FALSE; *transferredLength = 0; // We keep a pointer to the last buffer if it wasn't fully emptied // Check it first if(mPartialDataItem != NULL) { if(length >= (mPartialDataItem->size - mPartialDataIndex)) //Buffer to fill is larger than data remaining { // Copy the rest of the buffer memcpy(buffer, &((mPartialDataItem->data)[mPartialDataIndex]), (mPartialDataItem->size - mPartialDataIndex)); *transferredLength += (mPartialDataItem->size - mPartialDataIndex); GetDataAccess(); { mAvailableBuffers.push_back(mPartialDataItem->data); } ReleaseDataAccess(); delete mPartialDataItem; mPartialDataItem = NULL; } else //Can only fit some of the data in this buffer { // Copy some of the buffer memcpy(buffer, &((mPartialDataItem->data)[mPartialDataIndex]), length); mPartialDataIndex += length; // Return *transferredLength = length; return 0; } } GetDataAccess(); { list_size = mDataList.size(); } ReleaseDataAccess(); if(list_size < 1) { if(*transferredLength == 0) { return 1; } else { return 0; } } //Iterate through list getting as much data as we can: do { GetDataAccess(); { mPartialDataItem = mDataList.back(); mPartialDataIndex = 0; mDataList.pop_back(); --mPendingTransfer; list_size = mDataList.size(); } ReleaseDataAccess(); //TRACE("Transfer Retrieved, pendingIO=%d, pendingTransfer=%d\n", mPendingIO, mPendingTransfer); if((length - *transferredLength) >= mPartialDataItem->size) { // Copy all of the buffer memcpy(&buffer[*transferredLength], mPartialDataItem->data, mPartialDataItem->size); *transferredLength += mPartialDataItem->size; GetDataAccess(); { mAvailableBuffers.push_back(mPartialDataItem->data); } ReleaseDataAccess(); delete mPartialDataItem; mPartialDataItem = NULL; } else { // Copy some of the buffer memcpy(&buffer[*transferredLength], mPartialDataItem->data, (length - *transferredLength)); mPartialDataIndex += (length - *transferredLength); *transferredLength += (length - *transferredLength); return 0; } } while(list_size > 0); return 0; } void CUSBCommunicationsInterface::StopStream(void) //===================================================================== // StopStream - Stop the stream and free resources. // //===================================================================== { //------------------------- // Stop Streaming - WINDOWS //------------------------- #if defined _WINDOWS if(mpStreamThread != 0) { if(mPrintTraceMessages) { TRACE("Set Stop Event\n"); } mStreamState = 2; mStreamStartStop.ResetEvent(); mStopStream.SetEvent(); if(!mStreamStartStop.Lock(5000)) { if(mPrintTraceMessages) { TRACE("Timeout Waiting For libusb Stream to Stop\n"); } } } else { mStopStream.SetEvent(); //Just in case thread is really active } #elif defined LINUX_TARGET if(mpStreamThread != 0) { mStreamState = 2; while(sem_trywait(&mStreamStartStop) == 0); sem_post(&mStopStream); pthread_join(mpStreamThread, NULL); } else { sem_post(&mStopStream); //Just in case thread is really active } #endif } void CUSBCommunicationsInterface::GetDataAccess() //===================================================================== //===================================================================== { #if defined(_WINDOWS) mCS.Lock(); #elif defined(LINUX_TARGET) pthread_mutex_lock(&mCS); #endif } void CUSBCommunicationsInterface::ReleaseDataAccess() //===================================================================== //===================================================================== { #if defined(_WINDOWS) mCS.Unlock(); #elif defined(LINUX_TARGET) pthread_mutex_unlock(&mCS); #endif } #endif |
From: Chris E <sp...@gm...> - 2016-06-07 06:28:35
|
Hi guys. As the title suggests, I need to port some libusbK code to a different library in order to make it cross-platform. The software uses both control requests handled by UsbK, and isochronous requests handled by StmK. I've looked into libusb-1.0, and it looks like it will be simple to port the UsbK code. However, I couldn't see any immediate equivalent to StmK. Is there a way to set up something similar to StmK in libusb-1.0? Alternatively, is there another library with cross-platform support and an StmK-like module? Thanks, ~Chris |
From: michel <dia...@ya...> - 2016-05-11 18:50:22
|
Installer is big because it contain 32 and 64 bit version As far i remember it also include the 3 libusb0,libusbk, and in winusb base driver by default. If you use only one of this then you may remove the non related files and "re-pack" to get smaller installer In the help (http://libusbk.sourceforge.net/UsbK3/usbk_installers.html) i do not see any warring about redistribution limitation. The installer must be run/insatlled at customer site, user will get usual warning about provider check unless you resign the installer properly. -- View this message in context: http://libusb.6.n5.nabble.com/Device-Driver-Client-Installer-tp5715807p5715808.html Sent from the LibUSB Dev - Win32 mailing list archive at Nabble.com. |
From: Louis L. <Lo...@Ke...> - 2016-05-10 19:44:20
|
Hi All, I need it to install a USB driver (on Windows) for the X10 CM19a Transceiver. I have things setup to do so with a copy of InstallDriver.exe that seem to work just fine. However, InstallDriver.exe is about 3.5MB in size which seem very large to me. Have I done something wrong? Exactly what do I need to distribute with my program to have the X10 CM19a Transceiver driver get installed at a user site? Many thanks in advance. Lou -- Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon |
From: Chris E <sp...@gm...> - 2016-05-07 03:16:36
|
Hi guys. Looks like I've managed to stumble across some kind of reverse Heisenbug, and it's been doing my head in for days. I am developing a program using the Qt Library and LibusbK (precompiled .dll/.lib). When I compile and run, it works great - in debug or release mode. I can even deploy it on other machines and there are no immediate issues. However, when I try to debug using CDB (the Qt/Visual Studio debugger), UsbK_Init will always fail. This is, of course, a little bit problematic. Is there a way to get around it? If it helps, UsbK_Init returns error code 0x03 if compiled with Visual C++ 2013 (x86 and x64), and 0xCE if compiled with MinGW x86. Is this a known issue? Do desktop debuggers do this often? (If you haven't guessed already, I have fairly minimal experience developing Desktop software; I'm mainly used to microcontrollers and even there I'm no expert.) Thanks, ~Chris |
From: michel <dia...@ya...> - 2016-03-24 21:05:26
|
i have seen also weird "slow" response time using asynchronous api on windows on a "bulk loop" test made of bulk out and bulk (not fx2). The loop time using full asynchronous in + out call is bigger than asynch in + synchronous out . I have not investigate why. It was couple 100 usec more for about 200 us loop time on bus. I Also did observe the same on diffeerent usb 2.0 and usb3.0 host controller. Still I get good performance from FX2 bulk in streaming (>24MB/sec) using large (2MB) "synchronous " request on one device i have . Might not optimal but ok for my use case loosing some micro second and some KB/sec is acceptable vs added complexity of asynchronous (specially when to abort in middle of streaming). -- View this message in context: http://libusb.6.n5.nabble.com/Bulk-IN-transfer-rate-issue-with-FX2LP-on-Windows-tp5715721p5715732.html Sent from the LibUSB Dev - Win32 mailing list archive at Nabble.com. |
From: Xiaofan C. <xia...@gm...> - 2016-03-20 12:16:58
|
On Sun, Mar 20, 2016 at 7:05 PM, y.salnikov <y.s...@gm...> wrote: > Hi. > I have some problem with transfer rate with asynchronous bulk transfers on > windows. > I wrote a simple test program based on sigrok. It constantly streams data > through bulk endpoint. The firmware for FX2LP is also based on sigrok. > It works perfectly on linux with transfer rate up to 24MB/s. But on windows > it can work only up to 4 MB/s. > FX2LP have internal FIFO and when it overflow, device stops streaming data, > so it can be latency problem. > I also try to use different USB-controller on PCI card with same result. > Interesting thing is that sigrok Pulseview works fine on windows with > transfer rate up to 24 MB/s. > The code is there: https://github.com/y-salnikov/usb_tst/tree/bulk > Sorry for my english. It will be better that you use libusb mailing list since you are not using libusb-win32. Take note libusb-win32 mailing list is mainly for libusb-win32, libusbk and libusbdotnet users. libusb mailing list: https://lists.sourceforge.net/lists/listinfo/libusb-devel -- Xiaofan |
From: y.salnikov <y.s...@gm...> - 2016-03-20 11:05:26
|
Hi. I have some problem with transfer rate with asynchronous bulk transfers on windows. I wrote a simple test program based on sigrok. It constantly streams data through bulk endpoint. The firmware for FX2LP is also based on sigrok. It works perfectly on linux with transfer rate up to 24MB/s. But on windows it can work only up to 4 MB/s. FX2LP have internal FIFO and when it overflow, device stops streaming data, so it can be latency problem. I also try to use different USB-controller on PCI card with same result. Interesting thing is that sigrok Pulseview works fine on windows with transfer rate up to 24 MB/s. The code is there: https://github.com/y-salnikov/usb_tst/tree/bulk Sorry for my english. -- View this message in context: http://libusb.6.n5.nabble.com/Bulk-IN-transfer-rate-issue-with-FX2LP-on-Windows-tp5715721.html Sent from the LibUSB Dev - Win32 mailing list archive at Nabble.com. |
From: 若水 <shl...@gm...> - 2016-03-08 06:23:20
|
Hello, I am very sorry. I have not any document about STlink library. Best Regards, Shang Jing 2016-03-06 21:27 GMT+08:00 ouled omar ilyes <oul...@gm...>: > Hello, > First, congratulation for your excellence. I've read this site ( > https://sourceforge.net/p/libusb-win32/mailman/message/29925266/) and i'm > really interressant in using the same logic behind it. > I'm developing an application on C# in order to communicate with STM32. > So, i need the STlink library to use in my application. > Do you know where can i get a copy from it, or can you help me with some > documents to develop one. > I hope that i get an answer from you. > Thanks. > Best regards > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Libusb-win32-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel > > |
From: Xiaofan C. <xia...@gm...> - 2016-03-06 14:30:21
|
On Sun, Mar 6, 2016 at 9:27 PM, ouled omar ilyes <oul...@gm...> wrote: > Hello, > First, congratulation for your excellence. I've read this site > (https://sourceforge.net/p/libusb-win32/mailman/message/29925266/) and i'm > really interressant in using the same logic behind it. > I'm developing an application on C# in order to communicate with STM32. > So, i need the STlink library to use in my application. > Do you know where can i get a copy from it, or can you help me with some > documents to develop one. > I hope that i get an answer from you. I do not quite understand you. If you are interested in the ST-Link protocol, you may want to look at this one. https://github.com/texane/stlink Or OpenOCD. http://repo.or.cz/openocd.git/blob/HEAD:/src/jtag/drivers/stlink_usb.c If you need to make an USB device using STM32 and then use C# to talk to it, then it has nothing to do with ST-Link. -- Xiaofan |
From: ouled o. i. <oul...@gm...> - 2016-03-06 13:27:31
|
Hello, First, congratulation for your excellence. I've read this site ( https://sourceforge.net/p/libusb-win32/mailman/message/29925266/) and i'm really interressant in using the same logic behind it. I'm developing an application on C# in order to communicate with STM32. So, i need the STlink library to use in my application. Do you know where can i get a copy from it, or can you help me with some documents to develop one. I hope that i get an answer from you. Thanks. Best regards |
From: 若水 <shl...@gm...> - 2016-02-26 12:01:14
|
Thanks. I see. Best Regards, Shang Jing 2016-02-26 19:04 GMT+08:00 Xiaofan Chen <xia...@gm...>: > On Fri, Feb 26, 2016 at 4:42 PM, Graeme Gill <gr...@ar...> > wrote: > > Xiaofan Chen wrote: > > > >> As for libusbk.sys, I think the usage is probably pretty low since > WinUSB > >> will be a better alternative. > > > > Except for those devices it doesn't work with. > > Take note this thread is about libusbk.sys and not libusb0.sys. > libusbk.sys is based on KMDF and it will have the same problem > like WinUSB for the device you mentioned which works only with > libusb0.sys and not WinUSB/libusbk.sys. > > > -- > Xiaofan > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > Libusb-win32-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel > |
From: Xiaofan C. <xia...@gm...> - 2016-02-26 11:04:10
|
On Fri, Feb 26, 2016 at 4:42 PM, Graeme Gill <gr...@ar...> wrote: > Xiaofan Chen wrote: > >> As for libusbk.sys, I think the usage is probably pretty low since WinUSB >> will be a better alternative. > > Except for those devices it doesn't work with. Take note this thread is about libusbk.sys and not libusb0.sys. libusbk.sys is based on KMDF and it will have the same problem like WinUSB for the device you mentioned which works only with libusb0.sys and not WinUSB/libusbk.sys. -- Xiaofan |
From: Xiaofan C. <xia...@gm...> - 2016-02-26 11:02:49
|
On Fri, Feb 26, 2016 at 5:07 PM, 若水 <shl...@gm...> wrote: > Thank you for your support. > You mean that I do not need to modify FW and use WinUSB > to control my usb audio device. Right? No. This thread has nothing to do with your issue. If you use WinUSB to replace usbaudio.sys, your device will again lose the functionality of being USB Audio Device. -- Xiaofan |
From: 若水 <shl...@gm...> - 2016-02-26 09:07:12
|
Thank you for your support. You mean that I do not need to modify FW and use WinUSB to control my usb audio device. Right? Best Regards, Shang Jing 2016-02-26 16:42 GMT+08:00 Graeme Gill <gr...@ar...>: > Xiaofan Chen wrote: > > > As for libusbk.sys, I think the usage is probably pretty low since WinUSB > > will be a better alternative. > > Except for those devices it doesn't work with. > > Graeme Gill. > > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > Libusb-win32-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel > |
From: Graeme G. <gr...@ar...> - 2016-02-26 08:59:08
|
Xiaofan Chen wrote: > As for libusbk.sys, I think the usage is probably pretty low since WinUSB > will be a better alternative. Except for those devices it doesn't work with. Graeme Gill. |
From: 若水 <shl...@gm...> - 2016-02-26 05:41:00
|
Thanks. Best Regards, Shang Jing 2016-02-26 13:33 GMT+08:00 Xiaofan Chen <xia...@gm...>: > On Fri, Feb 26, 2016 at 12:57 PM, Børge Strand-Bergesen > <bor...@gm...> wrote: > > I use it! The ASIO driver at www.henryaudio.com depends on it. > > I don't know if I have the skill to port this system to another library. > > > > > If you are happy with libusbK API or libusbK kernel driver, both of > them will still work. > > > -- > Xiaofan > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > Libusb-win32-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel > |
From: Xiaofan C. <xia...@gm...> - 2016-02-26 05:33:53
|
On Fri, Feb 26, 2016 at 12:57 PM, Børge Strand-Bergesen <bor...@gm...> wrote: > I use it! The ASIO driver at www.henryaudio.com depends on it. > I don't know if I have the skill to port this system to another library. > If you are happy with libusbK API or libusbK kernel driver, both of them will still work. -- Xiaofan |
From: 若水 <shl...@gm...> - 2016-02-26 05:19:22
|
Thank you very much. I will try the method. Best Regards, Shang Jing 2016-02-26 13:00 GMT+08:00 Børge Strand-Bergesen <bor...@gm...>: > Look at the ASIO driver I use with www.he ryaudio.com. Follow the links > at the bottom of the page. > > We use one PID for UAC1 and the class driver, and another for UAC2 in the > ASIO-driver. > > Børge > > > On Friday, February 26, 2016, 若水 <shl...@gm...> wrote: > >> Hello, >> I have an USB Audio device (win7 x64bit system). It uses system >> internal driver (usbaudio.sys) and works well. >> Now, I need to add some new functions. I tried to install libusbk >> driver and run my new functions program. The new functions work well. But >> there is a problem, after I installed libusbk driver, the device will NOT >> be an USB Audio device. In order to solve the problem, I have to uninstall >> the libusbk driver and install libusbk FILTER driver. At that time, the USB >> Audio device works well. However, the new functions program cannot work. I >> debugged new functions program and found that *UsbK_IsoWritePipe* failed. >> The error code is 1168 (Element not found). Could you give me some >> instructions to solve the problems? Thanks. >> >> Best Regards, >> Shang Jing >> > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > Libusb-win32-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel > > |
From: Børge Strand-B. <bor...@gm...> - 2016-02-26 05:00:50
|
Look at the ASIO driver I use with www.he ryaudio.com. Follow the links at the bottom of the page. We use one PID for UAC1 and the class driver, and another for UAC2 in the ASIO-driver. Børge On Friday, February 26, 2016, 若水 <shl...@gm...> wrote: > Hello, > I have an USB Audio device (win7 x64bit system). It uses system > internal driver (usbaudio.sys) and works well. > Now, I need to add some new functions. I tried to install libusbk > driver and run my new functions program. The new functions work well. But > there is a problem, after I installed libusbk driver, the device will NOT > be an USB Audio device. In order to solve the problem, I have to uninstall > the libusbk driver and install libusbk FILTER driver. At that time, the USB > Audio device works well. However, the new functions program cannot work. I > debugged new functions program and found that *UsbK_IsoWritePipe* failed. > The error code is 1168 (Element not found). Could you give me some > instructions to solve the problems? Thanks. > > Best Regards, > Shang Jing > |
From: 若水 <shl...@gm...> - 2016-02-26 04:51:06
|
I see, Thank you. I will modify the device FW. Thanks. Best Regards, Shang Jing 2016-02-26 12:47 GMT+08:00 Xiaofan Chen <xia...@gm...>: > On Fri, Feb 26, 2016 at 12:24 PM, Xiaofan Chen <xia...@gm...> wrote: > > On Fri, Feb 26, 2016 at 12:22 PM, Xiaofan Chen <xia...@gm...> > wrote: > >> I think you'd better forget about the libusb-win32 filter driver. It may > >> or may not work. If it works that is good. If it does not, we will not > >> support it. > > > > Take note there is no libusbk filter driver. The filter driver is the > > libusb-win32 filter driver. > > > > If you want to use something like the libusb-win32 filter driver but > > is more updated, you may want to look at usbdk. > > https://github.com/daynix/UsbDk > > > > usbdk has been integrated in libusb (libusb-1.0 API) git and > > will be included in the upcoming libusb 1.0.21 release. > > I believe the better way for you is to create a USB Composite > Device with one of the interfaces as a custom USB device and use > the libusbK API (or libusb-1.0 API). You can keep the other interface > as the USB Audio Device and keep using the original Windows driver > (USBAudio.sys). > > The extra function (say FW upgrade) can be implemented in the > custom USB device interface. > > -- > Xiaofan > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > Libusb-win32-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel > |
From: Xiaofan C. <xia...@gm...> - 2016-02-26 04:47:32
|
On Fri, Feb 26, 2016 at 12:24 PM, Xiaofan Chen <xia...@gm...> wrote: > On Fri, Feb 26, 2016 at 12:22 PM, Xiaofan Chen <xia...@gm...> wrote: >> I think you'd better forget about the libusb-win32 filter driver. It may >> or may not work. If it works that is good. If it does not, we will not >> support it. > > Take note there is no libusbk filter driver. The filter driver is the > libusb-win32 filter driver. > > If you want to use something like the libusb-win32 filter driver but > is more updated, you may want to look at usbdk. > https://github.com/daynix/UsbDk > > usbdk has been integrated in libusb (libusb-1.0 API) git and > will be included in the upcoming libusb 1.0.21 release. I believe the better way for you is to create a USB Composite Device with one of the interfaces as a custom USB device and use the libusbK API (or libusb-1.0 API). You can keep the other interface as the USB Audio Device and keep using the original Windows driver (USBAudio.sys). The extra function (say FW upgrade) can be implemented in the custom USB device interface. -- Xiaofan |
From: Xiaofan C. <xia...@gm...> - 2016-02-26 04:44:19
|
On Fri, Feb 26, 2016 at 12:40 PM, 若水 <shl...@gm...> wrote: > Thank you for your support. > " you can use libusb-compat already under Windows." I do not known how to > use libusb-compat. Could you give me some instructions? Thanks. > libusb-compat is just libusb-0.1 API which libusb-win32 API is a super set. It will not help your situation. It needs to use WinUSB driver and when you use WinUSB driver, your device will no longer be a USB Audio driver. The correct way for you is to create a USB Composite Device with one of the interfaces as a generic USB device and use the libusbK API (or libusb-1.0 API). -- Xiaofan |
From: 若水 <shl...@gm...> - 2016-02-26 04:40:48
|
Thank you for your support. " you can use libusb-compat already under Windows." I do not known how to use libusb-compat. Could you give me some instructions? Thanks. Best Regards, Shang Jing 2016-02-26 12:30 GMT+08:00 Xiaofan Chen <xia...@gm...>: > On Sun, Aug 2, 2015 at 12:10 AM, Xiaofan Chen <xia...@gm...> wrote: > > On Sun, Aug 2, 2015 at 12:07 AM, Xiaofan Chen <xia...@gm...> > wrote: > >> So I guess if you are happy with libusb-win32 you can continue to use > >> it. If not, better start to switch to libusb. > > > > BTW, you can use libusb-compat already under Windows. It just lacks > > the enhanced Windows only libusb-win32 API. But since it sits on top > > of libusb Windows, you can use WinUSB driver. > > > > For users of libusb-win32 filter driver, it may or may not work. If it > works > that is good. If it does not, we will not support it. > > If you want to use something like the libusb-win32 filter driver but > is more updated, you may want to look at usbdk. > https://github.com/daynix/UsbDk > > usbdk has been integrated in libusb (libusb-1.0 API) git and > will be included in the upcoming libusb 1.0.21 release. > > libusb: https://github.com/libusb/libusb/wiki > > -- > Xiaofan > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > Libusb-win32-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel > |