예제 #1
0
    public void Init(byte USBDeviceNum = 0)
    {
        if (ANT_Common.getNumDetectedUSBDevices() < USBDeviceNum)
        {
            Debug.Log("ANT+ cannot detect USB device #" + USBDeviceNum);
            return;
        }

        // if (deviceList == null)
        //   deviceList = new List<ANT_Device>();
        if (messageQueue == null)
        {
            messageQueue = new Queue <ANT_Response>(16);
        }
        if (errorQueue == null)
        {
            errorQueue = new Queue <SerialError>(16);
        }
        if (channelList == null)
        {
            channelList = new List <AntChannel>();
        }

        //init the device
        if (devices[USBDeviceNum] == null)
        {
            devices[USBDeviceNum] = new ANT_Device(USBDeviceNum, 57000);
            devices[USBDeviceNum].deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse);
            devices[USBDeviceNum].serialError    += new ANT_Device.dSerialErrorHandler(SerialErrorHandler);
            devices[USBDeviceNum].ResetSystem();
            devices[USBDeviceNum].setNetworkKey(0, NETWORK_KEY, 500);
        }
    }
예제 #2
0
    IEnumerator Reconnect(uint serial)
    {
        Debug.Log("looking for usb device " + serial.ToString());
        // polling to try and find the USB device
        while (true)
        {
            if (ANT_Common.getNumDetectedUSBDevices() > nDeviceConnected)
            {
                ANT_Device device = new ANT_Device();
                if (device.getSerialNumber() == serial)
                {
                    Debug.Log("usb found!");
                    AntManager.Instance.Reconnect(device);
                    foreach (AntChannel channel in AntManager.Instance.channelList)
                    {
                        channel.ReOpen(device);
                    }

                    yield break;
                }
                else
                {
                    device.Dispose();
                }
            }

            yield return(new WaitForSeconds(0.1f));
        }
    }
 /// <summary>
 /// Creates an Integrated ANT-FS Client object, specifying the USB device number.  Baud rate is assumed to be 57600bps.
 /// </summary>
 /// <param name="USBDeviceNum">USB device number</param>
 public ANT_IntegratedANTFSClient(byte USBDeviceNum)  : base(USBDeviceNum, 57600)  // For FS-enabled parts, Baud rate is 57600
 {
     ANT_Common.enableDebugLogs();
     responseBuf = new Queue <ANT_Response>();
     if (!this.getDeviceCapabilities().FS)
     {
         this.Dispose();
         throw new ANT_Exception("Found ANT USB device, but does not support FS");
     }
 }
 /// <summary>
 /// Creates an Integrated ANT-FS Client object, by automatically trying to connect to the USB stick
 /// </summary>
 public ANT_IntegratedANTFSClient() : base()  // 57600 is tried first
 {
     ANT_Common.enableDebugLogs();
     if (!this.getDeviceCapabilities().FS)
     {
         this.Dispose();
         throw new ANT_Exception("Found ANT USB device, but does not support FS"); //TODO This is not a very effective auto init, for example: What happens if FS device is second device and first device isn't? Should we connect to other devices to check?
     }
     deviceResponse += dev_deviceResponse;
     deviceResponse += dev_hostdeviceEvents;
 }
예제 #5
0
    void OnSerialError(SerialError serialError)
    {
        Debug.Log("Error:" + serialError.error.ToString());

        //attempt to auto reconnect if the USB was unplugged
        if (serialError.error == ANT_Device.serialErrorCode.DeviceConnectionLost)
        {
            foreach (AntChannel channel in AntManager.Instance.channelList)
            {
                if (channel.device == serialError.sender)
                {
                    channel.PauseChannel();
                }
            }
            nDeviceConnected = ANT_Common.getNumDetectedUSBDevices();
            StartCoroutine("Reconnect", serialError.sender.getSerialNumber());
        }
    }
예제 #6
0
 /// <summary>
 /// Initialize the demo parameters
 /// </summary>
 static void Init()
 {
     try
     {
         Console.WriteLine("Attempting to connect to an ANT USB device...");
         ANT_Common.enableDebugLogs(); // Enable debugging first, to enable ANT-FS specific logging
         device0 = new ANT_Device();   // Create a device instance using the automatic constructor (automatic detection of USB device number and baud rate)
         Console.WriteLine("Initialization was successful!");
     }
     catch (Exception ex)
     {
         if (device0 == null)    // Unable to connect to ANT
         {
             throw new Exception("Could not connect to any device.\n" +
                                 "Details: \n   " + ex.Message);
         }
         else
         {
             throw new Exception("Error connecting to ANT: " + ex.Message);
         }
     }
 }
예제 #7
0
        public AntPlusDevMgr()
        {
            if (antStick == null)
            {
                ANT_Common.enableDebugLogs();
                findUsableAntDevice();
            }


            numChannelsForDevices = antStick.getNumChannels();


            var racer = new List <AntPlusRacerConfig.RacerInput>();

            foreach (AntPlusRacerConfig.RacerInputType i in Enum.GetValues(typeof(AntPlusRacerConfig.RacerInputType)))
            {
                racer.Add(new AntPlusRacerConfig.RacerInput()
                {
                    displayName = "", type = i, defaultDeviceId = 0
                });
            }

            //Add all devices from config
            foreach (AntPlusRacerConfig.RacerInput i in racer)
            {
                switch (i.type)
                {
                //case AntPlusRacerConfig.RacerInputType.ant_BikeCad_UsingSpd:
                //    ds_AntPlus_BikeSpd spdOnly = new ds_AntPlus_BikeSpd();
                //    deviceList.Add(new AntPlus_Connection(spdOnly));
                //    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeCad_UsingSpd(spdOnly)));
                //    break;
                case AntPlusRacerConfig.RacerInputType.ant_BikeCadAndSpd:
                    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeSpdCad()));
                    break;
                    //case AntPlusRacerConfig.RacerInputType.ant_BikeSpd:
                    //    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeSpd()));
                    //    break;
                    //case AntPlusRacerConfig.RacerInputType.ant_FitEqpmt:
                    //    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_Fit()));
                    //    break;
                    //case AntPlusRacerConfig.RacerInputType.ant_StrideSDM:
                    //    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_StrideSDM()));
                    //    break;
                    //default:    //Not one of the ant types, ignore
                    //    break;
                }

                if (i.defaultDeviceId != 0)
                {
                    deviceList.Last().dataSource.searchProfile.deviceNumber = i.defaultDeviceId;
                }

                if (!String.IsNullOrWhiteSpace(i.displayName))
                {
                    deviceList.Last().dataSource.customSourceName = i.displayName;
                }
            }

            startNextSearch();
        }
예제 #8
0
        public ANTManger()
        {
            if (antStick == null)
            {
                ANT_Common.enableDebugLogs();
                findUsableAntDevice();
            }

            /*if (ANT.FrameworkConfig.getInstance().remoteControlDevNum_negativeIsOff > 0)
             * {
             *  numChannelsForDevices = antStick.getNumChannels() - 1;
             *  RacerRemoteControl.startRemoteControl(antStick.getChannel(numChannelsForDevices));
             * }
             * else
             * {
             *  numChannelsForDevices = antStick.getNumChannels();
             * }*/
            numChannelsForDevices = antStick.getNumChannels();


            ds_AntPlus_BikeSpd spdOnly = new ds_AntPlus_BikeSpd();

            deviceList.Add(new AntPlus_Connection(spdOnly));
            deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeCad_UsingSpd(spdOnly)));
            deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeSpdCad()));
            deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeSpd()));
            //Add all devices from config

            /*foreach (ANT.FrameworkConfig.RacerInput i in ANT.FrameworkConfig.getInstance().enabledRacerInputs)
             * {
             *  switch (i.type)
             *  {
             *      case ANT.FrameworkConfig.RacerInputType.ant_BikeCad_UsingSpd:
             *          ds_AntPlus_BikeSpd spdOnly = new ds_AntPlus_BikeSpd();
             *          deviceList.Add(new AntPlus_Connection(spdOnly));
             *          deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeCad_UsingSpd(spdOnly)));
             *          break;
             *      case ANT.FrameworkConfig.RacerInputType.ant_BikeCadAndSpd:
             *          deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeSpdCad()));
             *          break;
             *      case ANT.FrameworkConfig.RacerInputType.ant_BikeSpd:
             *          deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeSpd()));
             *          break;
             *      case ANT.FrameworkConfig.RacerInputType.ant_FitEqpmt:
             *          deviceList.Add(new AntPlus_Connection(new ds_AntPlus_Fit()));
             *          break;
             *      case ANT.FrameworkConfig.RacerInputType.ant_StrideSDM:
             *          deviceList.Add(new AntPlus_Connection(new ds_AntPlus_StrideSDM()));
             *          break;
             *      default:    //Not one of the ant types, ignore
             *          break;
             *  }
             *
             *  if (i.defaultDeviceId != 0)
             *      deviceList.Last().dataSource.searchProfile.deviceNumber = i.defaultDeviceId;
             *
             *  if (!String.IsNullOrWhiteSpace(i.displayName))
             *      deviceList.Last().dataSource.customSourceName = i.displayName;
             * }*/

            startNextSearch();
        }
예제 #9
0
        public AntPlusDevMgr()
        {
            if (antStick == null)
            {
                ANT_Common.enableDebugLogs();
                findUsableAntDevice();
            }

            if (AntPlusRacerConfig.getInstance().remoteControlDevNum_negativeIsOff > 0)
            {
                numChannelsForDevices = antStick.getNumChannels() - 1;
                RacerRemoteControl.startRemoteControl(antStick.getChannel(numChannelsForDevices));
            }
            else
            {
                numChannelsForDevices = antStick.getNumChannels();
            }

            //Add all devices from config
            foreach (AntPlusRacerConfig.RacerInput i in AntPlusRacerConfig.getInstance().enabledRacerInputs)
            {
                switch (i.type)
                {
                case AntPlusRacerConfig.RacerInputType.ant_BikeCad_UsingSpd:
                    ds_AntPlus_BikeSpd spdOnly = new ds_AntPlus_BikeSpd();
                    deviceList.Add(new AntPlus_Connection(spdOnly));
                    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeCad_UsingSpd(spdOnly)));
                    break;

                case AntPlusRacerConfig.RacerInputType.ant_BikeCadAndSpd:
                    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeSpdCad()));
                    break;

                case AntPlusRacerConfig.RacerInputType.ant_BikeSpd:
                    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_BikeSpd()));
                    break;

                case AntPlusRacerConfig.RacerInputType.ant_FitEqpmt:
                    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_Fit()));
                    break;

                case AntPlusRacerConfig.RacerInputType.ant_StrideSDM:
                    deviceList.Add(new AntPlus_Connection(new ds_AntPlus_StrideSDM()));
                    break;

                default:        //Not one of the ant types, ignore
                    break;
                }

                if (i.defaultDeviceId != 0)
                {
                    deviceList.Last().dataSource.searchProfile.deviceNumber = i.defaultDeviceId;
                }

                if (!String.IsNullOrWhiteSpace(i.displayName))
                {
                    deviceList.Last().dataSource.customSourceName = i.displayName;
                }
            }

            startNextSearch();
        }