Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Finding USB1 Stick - DSISerialGeneric::AutoInit()

Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

Hey guys,

I use the class dsi_serial_generic.cpp and the function "AutoInit()" to find and open the first available ANT+ stick. It seems to have problem finding USB1 type of stick (no problem finding USB2 stick). Do you think with some tweaking to AutoInit(), it would be possible to also find USB1 stick?

I know GoldenCheetah can find USB1 stick with this code :
https://github.com/GoldenCheetah/GoldenCheetah/blob/master/src/ANT.h

Hoping to find a solution, a lot of people are still using USB1 stick and can't use my software so far :/
Thanks

Code (untouched from source) :
//defines used by AutoInit
#define ANT_USB_STICK_PID     0x1004
#define ANT_USB_DEV_BOARD_PID 0x1006
#define ANT_USB_STICK_BAUD    ((USHORT)50000)
#define ANT_DEFAULT_BAUD      ((USHORT)57600)

BOOL DSISerialGeneric::AutoInit()
{
   Close
();
   if (
pclDevice)
      
delete pclDevice;
   
pclDevice NULL;
   
ucDeviceNumber 0xFF;   

   const 
ANTDeviceList clDeviceList USBDeviceHandle::GetAvailableDevices();  //saves a copy of the list and all of the elements
   
   
if(clDeviceList.GetSize() == 0)
   
{
      
//When this is being polled repeatedly, as in the ANTFS host class, the USBReset calls to WinDevice Enable/Disable take a large amount if CPU, so we limit the
      //reset here to only be called a maximum of once every 30s
      
time_t curTime time(NULL);
      if(
curTime lastUsbResetTime 30)
      
{
         lastUsbResetTime 
curTime;
         
this->USBReset();
      
}
      
return FALSE;
   
}   

   
   USBDeviceHandle
::CopyANTDevice(pclDeviceclDeviceList[0]); 
   
ucDeviceNumber 0;            //initialize it to 0 for now (all devices that use autoinit will have a 0 device number) //TODO this devicenumber is useless because it can't be used to access the list again
   
switch (pclDevice->GetPid())
   
{
      
case ANT_USB_STICK_PID:      
         
ulBaud ANT_USB_STICK_BAUD;
         break;
      case 
ANT_USB_DEV_BOARD_PID:
      default:
         
ulBaud ANT_DEFAULT_BAUD;
         break;
   
}

   
return TRUE;


GetAvailableDevices
//!!Just here temporarily until we get ANTDeviceList to do it.
const ANTDeviceList USBDeviceHandle::GetAvailableDevices(ULONG ulDeviceTypeField_)
{
   ANTDeviceList clDeviceList
;

   if( (
ulDeviceTypeField_ DeviceType::SI_LABS) != 0)
   
{
      
const USBDeviceListSI clDeviceSIList USBDeviceHandleSI::GetAvailableDevices();  //!!There is a list copy here!
      
clDeviceList.Add(clDeviceSIList.GetSubList(SiDeviceMatch) );
   
}

   
if( (ulDeviceTypeField_ DeviceType::LIBUSB) != 0)
   
{
      
const USBDeviceListLibusb clDeviceLibusbList USBDeviceHandleLibusb::GetAvailableDevices();  //!!There is a list copy here!
      
clDeviceList.Add(clDeviceLibusbList.GetSubList(LibusbDeviceMatch) );
   
}

   
return clDeviceList;
     

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com