コード例 #1
0
    public void Close()
    {
        if (channel != null)
        {
            channel.closeChannel();
            channel.Dispose();
        }
        if (isBackgroundScan)
        {
            device.enableRxExtendedMessages(false, 500);
        }

        broadcasting = false;
        AntManager.Instance.channelList.Remove(this);
        Destroy(this);
    }
コード例 #2
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);
 }
コード例 #3
0
        public Network()
        {
            device = new ANT_Device();                                                      // Create a device instance using the automatic constructor (automatic detection of USB device number and baud rate)
            device.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse); // Add device response function to receive protocol event messages

            device.ResetSystem();                                                           // Soft reset
            System.Threading.Thread.Sleep(500);                                             // Delay 500ms after a reset

            // If you call the setup functions specifying a wait time, you can check the return value for success or failure of the command
            // This function is blocking - the thread will be blocked while waiting for a response.
            // 500ms is usually a safe value to ensure you wait long enough for any response
            // If you do not specify a wait time, the command is simply sent, and you have to monitor the protocol events for the response,
            if (!device.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
            {
                throw new Exception("Error configuring network key");
            }

            device.enableRxExtendedMessages(true);
        }
コード例 #4
0
    public void ConfigureScan(byte userChannel)
    {
        this.userChannel = userChannel;
        RXQueue          = new Queue <byte[]>(16);
        messageQueue     = new Queue <ANT_Response>(16);
        device           = AntManager.Instance.device;
        device.enableRxExtendedMessages(true, 500);
        channel = device.getChannel(userChannel);
        channel.channelResponse += new dChannelResponseHandler(ChannelResponse);

        channel.assignChannelExt(ANT_ReferenceLibrary.ChannelType.ADV_TxRx_Only_or_RxAlwaysWildCard_0x40, 0, ANT_ReferenceLibrary.ChannelTypeExtended.ADV_AlwaysSearch_0x01, 500);
        channel.setChannelID(0, false, 0, 0, 500);
        channel.setChannelFreq(57, 500);
        channel.setChannelSearchTimeout(0);
        channel.setLowPrioritySearchTimeout((byte)0xFF);
        isBackgroundScan = true;
        channel.openChannel();

        broadcasting = true;
    }
コード例 #5
0
    public void ConfigureContinuousScan(ANT_ReferenceLibrary.ChannelType channelType, byte radioFreq, ushort USBNum)
    {
        userChannel  = 0;
        RXQueue      = new Queue <byte[]>(16);
        messageQueue = new Queue <ANT_Response>(16);
        device       = AntManager.Instance.devices[USBNum];
        device.enableRxExtendedMessages(true, 500);
        channel = device.getChannel(0);
        channel.channelResponse += new dChannelResponseHandler(ChannelResponse);

        channel.assignChannelExt(ANT_ReferenceLibrary.ChannelType.ADV_TxRx_Only_or_RxAlwaysWildCard_0x40, 0, ANT_ReferenceLibrary.ChannelTypeExtended.ADV_AlwaysSearch_0x01, 500);
        channel.setChannelID(0, false, 0, 0, 500);
        channel.setChannelFreq(radioFreq, 500);
        channel.setChannelSearchTimeout(0);
        channel.setLowPrioritySearchTimeout((byte)0xFF);
        isBackgroundScan = true;
        channel.openChannel();
        device.openRxScanMode();
        broadcasting = true;
    }
コード例 #6
0
        ////////////////////////////////////////////////////////////////////////////////
        // ConfigureANT
        //
        // Resets the system, configures the ANT channel and starts the demo
        ////////////////////////////////////////////////////////////////////////////////
        private static void ConfigureANT()
        {
            Console.WriteLine("Resetting module...");
            device0.ResetSystem();              // Soft reset
            System.Threading.Thread.Sleep(500); // Delay 500ms after a reset

            // If you call the setup functions specifying a wait time, you can check the return value for success or failure of the command
            // This function is blocking - the thread will be blocked while waiting for a response.
            // 500ms is usually a safe value to ensure you wait long enough for any response
            // If you do not specify a wait time, the command is simply sent, and you have to monitor the protocol events for the response,
            Console.WriteLine("Setting network key...");
            if (device0.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
            {
                Console.WriteLine("Network key set");
            }
            else
            {
                throw new Exception("Error configuring network key");
            }

            Console.WriteLine("Assigning channel...");
            if (channel0.assignChannel(channelType, USER_NETWORK_NUM, 500))
            {
                Console.WriteLine("Channel assigned");
            }
            else
            {
                throw new Exception("Error assigning channel");
            }

            Console.WriteLine("Setting Channel ID...");
            if (channel0.setChannelID(user_devicenum, false, user_devicetype, USER_TRANSTYPE, 500))  // Not using pairing bit
            {
                Console.WriteLine("Channel ID set");
            }
            else
            {
                throw new Exception("Error configuring Channel ID");
            }

            Console.WriteLine("Setting Radio Frequency...");
            if (channel0.setChannelFreq(USER_RADIOFREQ, 500))
            {
                Console.WriteLine("Radio Frequency set");
            }
            else
            {
                throw new Exception("Error configuring Radio Frequency");
            }

            Console.WriteLine("Setting Channel Period...");
            if (channel0.setChannelPeriod(user_channelperiod, 500))
            {
                Console.WriteLine("Channel Period set");
            }
            else
            {
                throw new Exception("Error configuring Channel Period");
            }

            Console.WriteLine("Opening channel...");
            bBroadcasting = true;
            if (channel0.openChannel(500))
            {
                Console.WriteLine("Channel opened");
            }
            else
            {
                bBroadcasting = false;
                throw new Exception("Error opening channel");
            }

#if (ENABLE_EXTENDED_MESSAGES)
            // Extended messages are not supported in all ANT devices, so
            // we will not wait for the response here, and instead will monitor
            // the protocol events
            Console.WriteLine("Enabling extended messages...");
            device0.enableRxExtendedMessages(true);
#endif
        }
コード例 #7
0
        private void setupAndOpenScan(ANT_Device deviceToSetup, ANT_ReferenceLibrary.ChannelType channelType)
        {
            //We try-catch and forward exceptions to the calling function to handle and pass the errors to the user
            try
            {
                if (!deviceToSetup.setNetworkKey(0, USER_NETWORK_KEY, 500))
                {
//                    threadSafePrintLine("Network Key set to ... well, you know,  on net 0.", textBox_Display);
//                else
                    throw new Exception("Channel assignment operation failed.");
                }


                //To access an ANTChannel on a paticular device we need to get the channel from the device
                //Once again, this ensures you have a valid object associated with a real-world ANTChannel
                //ie: You can only get channels that actually exist
                ANT_Channel channel0 = deviceToSetup.getChannel(0);

                //Almost all functions in the library have two overloads, one with a response wait time and one without
                //If you give a wait time, you can check the return value for success or failure of the command, however
                //the wait time version is blocking. 500ms is usually a safe value to ensure you wait long enough for any response.
                //But with no wait time, the command is simply sent and you have to monitor the device response for success or failure.

                //To setup channels for communication there are three mandatory operations assign, setID, and Open
                //Various other settings such as message period and network key affect communication
                //between two channels as well, see the documentation for further details on these functions.

                //So, first we assign the channel, we have already been passed the channelType which is an enum that has various flags
                //If we were doing something more advanced we could use a bitwise or ie:base|adv1|adv2 here too
                //We also use net 0 which has the public network key by default
                if (!channel0.assignChannel(channelType, 0, 500))
                {
//                    threadSafePrintLine("Ch assigned to " + channelType + " on net 0.", textBox_Display);
//                else
                    throw new Exception("Channel assignment operation failed.");
                }

                //Next we have to set the channel id. Slaves will only communicate with a master device that
                //has the same id unless one or more of the id parameters are set to a wild card 0. If wild cards are included
                //the slave will search until it finds a broadcast that matches all the non-wild card parameters in the id.
                //For now we pick an arbitrary id so that we can ensure we match between the two devices.
                //The pairing bit ensures on a search that you only pair with devices that also are requesting
                //pairing, but we don't need it here so we set it to false
                if (!channel0.setChannelID(USER_DEVICENUM, false, USER_DEVICETYPE, USER_TRANSTYPE, 500))
                {
//                    threadSafePrintLine("Set channel ID to " + USER_DEVICENUM + " " + USER_DEVICETYPE + " " + USER_TRANSTYPE, textBox_Display);
//                else
                    throw new Exception("Set Channel ID operation failed.");
                }

                //Setting the channel period isn't mandatory, but we set it slower than the default period so messages aren't coming so fast
                //The period parameter is divided by 32768 to set the period of a message in seconds. So here, 16384/32768 = 1/2 sec/msg = 2Hz
                if (!channel0.setChannelPeriod(USER_CHANNELPERIOD, 500))
                {
//                    threadSafePrintLine("Message Period set to " + USER_CHANNELPERIOD + "/32768 seconds per message", textBox_Display);
//                else
                    throw new Exception("Set Channel Period Op Faildd.");
                }

                if (!channel0.setChannelFreq(USER_RADIOFREQ, 500))
                {
//                    threadSafePrintLine("Message Radio Freq set to +" + USER_RADIOFREQ, textBox_Display);
//                else
                    throw new Exception("Set Radio Freq failed.");
                }

                if (!deviceToSetup.enableRxExtendedMessages(true, 500))
                {
//                    threadSafePrintLine("Requesting Extended Messages", textBox_Display);
//                else
                    throw new Exception("Extenned Message Request Failed.");
                }



                //Now we open the channel
                if (!deviceToSetup.openRxScanMode(500))
                {
//                    threadSafePrintLine("Opened Device in Scan mode" + Environment.NewLine, textBox_Display);
//                else
                    throw new Exception("Channel Open operation failed.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Setup and Open Failed. " + ex.Message + Environment.NewLine);
            }
        }
コード例 #8
0
ファイル: AntReader.cs プロジェクト: oszust002/MgrGame
    private void InitAnt()
    {
        try
        {
            String path = Application.dataPath + "/Plugins";
            ANT_Common.CustomDllSearchPath = Path.GetFullPath(path);
            _device = new ANT_Device();
            _device.deviceResponse += DeviceResponse;

            _channel = _device.getChannel(userAntChannel);
            _channel.channelResponse += ChannelResponse;

            System.Threading.Thread.Sleep(500);

            if (_device.setNetworkKey(USER_NETWORK_NUM, USER_NETWORK_KEY, 500))
            {
                Debug.Log("Network key set");
            }
            else
            {
                throw new Exception("Error configuring network key");
            }

            if (!_channel.assignChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00, USER_NETWORK_NUM,
                                        500))
            {
                throw new Exception("Error assigning channel");
            }

            if (_channel.setChannelID(userDeviceNum, false, userDeviceType, userTransmissionType, 500)
                ) // Not using pairing bit
            {
                Debug.Log("Channel ID set");
            }
            else
            {
                throw new Exception("Error configuring Channel ID");
            }


            if (_channel.setChannelFreq(userUserRadioFreq, 500))
            {
                Debug.Log("Radio Frequency set");
            }
            else
            {
                throw new Exception("Error configuring Radio Frequency");
            }

            Debug.Log("Setting Channel Period...");
            if (_channel.setChannelPeriod(userChannelPeriod, 500))
            {
                Debug.Log("Channel Period set");
            }
            else
            {
                throw new Exception("Error configuring Channel Period");
            }

            if (!_channel.openChannel(500))
            {
                throw new Exception("Error during opening channel");
            }

            _device.enableRxExtendedMessages(true);
        }
        catch (Exception e)
        {
            if (_device == null)
            {
                throw new Exception("Could not connect to any ANT device\nDetails:\n" + e);
            }

            throw new Exception("Error connecting to ANT: " + e.Message);
        }
    }