Ejemplo n.º 1
0
 public void Close()
 {
     if (channel != null)
     {
         channel.closeChannel();
         channel.Dispose();
     }
     if (isBackgroundScan)
     {
         device.enableRxExtendedMessages(false, 500);
         isBackgroundScan = false;
     }
     broadcasting = false;
     AntManager.Instance.channelList.Remove(this);
     AntManager.Instance.channelIDUsed[device.getOpenedUSBDeviceNum(), userChannel] = false;
     Destroy(this);
 }
Ejemplo n.º 2
0
    public void Reconnect(ANT_Device previousDevice)
    {
        int usbNum = previousDevice.getOpenedUSBDeviceNum();

        devices[usbNum] = previousDevice;
        previousDevice.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse);
        previousDevice.serialError    += new ANT_Device.dSerialErrorHandler(SerialErrorHandler);
        previousDevice.ResetSystem();
        previousDevice.setNetworkKey(0, NETWORK_KEY, 500);
    }
Ejemplo n.º 3
0
    public void ReOpen(ANT_Device device)
    {
        if (broadcasting)
        {
            return;
        }

        this.device = device;

        if (!isBackgroundScan)
        {
            ConfigureAnt(channelType, userChannel, deviceNum, deviceType, transType, radioFreq, channelPeriod, pairing, device.getOpenedUSBDeviceNum());
        }
        else
        {
            ConfigureScan(userChannel, (ushort)device.getOpenedUSBDeviceNum());
        }
    }
Ejemplo n.º 4
0
    void OnDeviceResponse(ANT_Response response)
    {
        ANT_Device device = response.sender as ANT_Device;

        Debug.Log("device (usb " + device.getOpenedUSBDeviceNum() + ") : " + response.getMessageID().ToString());
    }
Ejemplo n.º 5
0
        static async void Init()
        {
            try
            {
                WriteLog("Connecting to ANT USB Dongle...");
                //device0 = new ANT_Device();   // Create a device instance using the automatic constructor (automatic detection of USB device number and baud rate)

                device0.serialError    += new ANT_Device.dSerialErrorHandler(SerialError);
                device0.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse); // Add device response function to receive protocol event messages

                channel0 = device0.getChannel(USER_ANT_CHANNEL);                                 // Get channel from ANT device
                channel0.channelResponse += new dChannelResponseHandler(ChannelResponse);        // Add channel response function to receive channel event messages

                WriteLog("ANT USB Dongle initialization successful");
                WriteLog("ANT USB Dongle Device Number: " + device0.getOpenedUSBDeviceNum());
                WriteLog("ANT USB Dongle Serial Number: " + device0.getSerialNumber());
                USER_DEVICENUM = (ushort)device0.getOpenedUSBDeviceNum();

                bReset = false;
                List <Task> tasks = new List <Task>();
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    while (!bReset)
                    {
                        WriteLog("Checking ANT USB Dongle...");
                        Byte[] bytes = new byte[8];
                        try
                        {
                            if (channel0.sendBroadcastData(bytes))
                            {
                                WriteLog("ANT USB Dongle is operationnal");
                            }
                            else
                            {
                                WriteLog("ANT USB Dongle is not operationnal");
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteLog("Problem with ANT USB Dongle...");
                        }
                        System.Threading.Thread.Sleep(5000);
                    }
                }));
                await Task.WhenAll(tasks);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex);
            }

/*
 *              if (device0 == null)    // Unable to connect to ANT
 *              {
 *                  throw new Exception("Could not connect to any ANT device.\n" +
 *                  "Details: \n   " + ex.Message);
 *              }
 *              else
 *              {
 *                  throw new Exception("Error connecting to ANT device: " + ex.Message);
 *              }
 *          }
 */
        }