예제 #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            ANT_Device usbAntDevice = new ANT_Device();
            usbAntDevice.ResetSystem();             // Soft reset
            System.Threading.Thread.Sleep(500);    // Delay 500ms after a reset
            usbAntDevice.setNetworkKey(0, AntDevice.AntNetworkKey, 500);
            var receiver = new AntHRreceiver(usbAntDevice);
            Application.Run(new HRreportForm(receiver));
        }
예제 #2
0
파일: Device.cs 프로젝트: Cycli/Cycli
        ////////////////////////////////////////////////////////////////////////////////
        // Init
        //
        // Initialize demo parameters.
        //
        ////////////////////////////////////////////////////////////////////////////////
        public void Initialise()
        {
            try
            {
                Console.WriteLine("Attempting to connect to an ANT USB device...");
                device0 = new ANT_Device();   // Create a device instance using the automatic constructor (automatic detection of USB device number and baud rate)
                device0.deviceResponse += new ANT_Device.dDeviceResponseHandler(DeviceResponse);    // Add device response function to receive protocol event messages
                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);
                }
            }
            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(USER_NETWORK_KEY[0]);
        }
예제 #3
0
        private bool OpenGarmin2()
        {

            //Initialise the ANT library and connect to ANT module
            if (device != null)
            {
                ANT_Device.shutdownDeviceInstance(ref device);
                device = null;
            }

            device = new ANT_Device();         

            if (device == null)
            {
                MessageBox.Show("Error initialising ANT module. Ensure the Garmin ANT agent is not running.");
                return false;
            }
            device.ResetSystem();

            channel = device.getChannel(0);
            
            //Reset wireless transceiver
            device.ResetSystem();
            Thread.Sleep(50);

            //Pass the callback functions to the ANT_DLL library
            device.deviceResponse += new ANT_Device.DeviceResponseHandler(DeviceResponse);
            channel.channelResponse += new ANT_Channel.ChannelResponseHandler(ChannelResponse);

            //Set network key for Garmin HRM
            //The garmin HRM key is "B9A521FBBD72C345"
            byte[] GarminKey = { 0xb9, 0xa5, 0x21, 0xfb, 0xbd, 0x72, 0xc3, 0x45 };
            device.setNetworkKey(0, GarminKey);
            Thread.Sleep(50);

            //Assign the channel
            //Receive on channel 0, network #0
            channel.assignChannel(ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00, 0);

            //Congifure Channel ID - set up which devices to transmit-receive data from
            //Set to receive from any device it finds
            ushort device_id = ushort.Parse(txtDeviceID.Text);
            channel.setChannelID((ushort)device_id, false, 0, 0);
            Thread.Sleep(50);

            //Set the receiver search timeout limit
            channel.setChannelSearchTimeout(0xff);
            Thread.Sleep(50);

            //Set the messaging period (corresponding to the max number of messages per second)
            //Messaging period for Garmin HRM is 0x1f86
            channel.setChannelPeriod(0x1f86);
            Thread.Sleep(50);

            //Set the radio frequency corresponding to the Garmin watch (frequency 0x39)
            channel.setChannelFreq(0x39);
            Thread.Sleep(50);

            //Open the channel to receive data !
            channel.openChannel();

            return true;
        }