private void action_ReqVersion()
        {
            //To request the version we use the requestMessageAndResponse function. To request messages you could
            //also use the requestMessage function, but then you need to monitor the device feedback for the response.
            //The version string is a null terminated ascii string, so we decode it and display it
            threadSafePrintLine("Requesting Device 0 Version", textBox_Display);
            //On failure an exception is thrown so we watch for it
            try
            {
                ANT_Response version = device0.requestMessageAndResponse(ANT_ReferenceLibrary.RequestMessageID.VERSION_0x3E, 500);
                threadSafePrintLine("Device 0 ANT Version: " + new ASCIIEncoding().GetString(version.messageContents, 0, version.messageContents.Length - 1), textBox_Display);
            }
            catch (Exception)
            {
                threadSafePrintLine("Requesting Device 0 Version Timed Out", textBox_Display);
            }

            //if device 1 is open, request its version too
            if (device1 != null)
            {
                threadSafePrintLine("Requesting Device 1 Version", textBox_Display);
                try
                {
                    ANT_Response version = device1.requestMessageAndResponse(ANT_ReferenceLibrary.RequestMessageID.VERSION_0x3E, 500);
                    threadSafePrintLine("Device 1 ANT Version: " + new ASCIIEncoding().GetString(version.messageContents, 0, version.messageContents.Length - 1), textBox_Display);
                }
                catch (Exception)
                {
                    threadSafePrintLine("Requesting Device 1 Version Timed Out", textBox_Display);
                }
            }
        }
예제 #2
0
        void antChannel_channelResponse_FeSearch(ANT_Response response)
        {
            switch ((ANT_ReferenceLibrary.ANTMessageID)response.responseID)
            {
            case ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E:
                AntPlus_Connection newConn = deviceList[searchingDeviceIndex];
                ANT_Response       idResp  = null;
                try
                {
                    idResp = antStick.requestMessageAndResponse(searchChannel.getChannelNum(), ANT_ReferenceLibrary.RequestMessageID.CHANNEL_ID_0x51, 1000);
                }
                catch (Exception)
                {
                    //Don't know what to do if we can't get id...could retry somewhere...
                    break;
                }


                lock (newConn)
                {
                    searchChannel.channelResponse -= antChannel_channelResponse_FeSearch;
                    newConn.dataSource.searchProfile.deviceNumber = (ushort)(idResp.messageContents[1] + ((ushort)idResp.messageContents[2] << 8));     //Save to the search profile so we keep this id after dropouts
                    newConn.connectedChannel = searchChannel;
                    //Note: the low pri search happens before the high pri, so this isn't even doing anything.
                    //newConn.connectedChannel.setChannelSearchTimeout(2, 500); //If we drop, we really want it back soon because it may be in use in a race, but we can't afford to ruin other channels staying in high priority. With the default search waveform, 5s is supposed to give us a really good rate of acquisition
                    newConn.connectedChannel.setLowPrioritySearchTimeout(255, 500);     //Search indefinitely
                    newConn.antChannel_channelResponse_DataFetch(response);
                    newConn.connectedChannel.channelResponse += newConn.antChannel_channelResponse_DataFetch;
                    newConn.setConnStatus(AntPlus_Connection.ConnState.Connected);
                }

                searchChannel = null;       //invalidate this channel as a search channel
                startNextSearch();
                break;

            case ANT_ReferenceLibrary.ANTMessageID.RESPONSE_EVENT_0x40:
                if (response.messageContents[1] == (byte)ANT_ReferenceLibrary.ANTMessageID.EVENT_0x01)
                {
                    //if(response.messageContents[2] == 0x01)  //Search timeout causes close channel, so wait for that
                    if (response.messageContents[2] == (byte)ANT_ReferenceLibrary.ANTEventID.EVENT_CHANNEL_CLOSED_0x07)     //Closed channel
                    {
                        startNextSearch();
                    }
                }
                break;
            }
        }
예제 #3
0
        ////////////////////////////////////////////////////////////////////////////////
        // Start
        //
        // Start the demo program.
        //
        // ucChannelType_:  ANT Channel Type. 0 = Master, 1 = Slave
        //                  If not specified, 2 is passed in as invalid.
        ////////////////////////////////////////////////////////////////////////////////
        static void Start(byte ucChannelType_)
        {
            byte ucChannelType = ucChannelType_;

            bDone         = false;
            bDisplay      = true;
            bBroadcasting = false;

            PrintMenu();

            // If a channel type has not been set at the command line,
            // prompt the user to specify one now
            do
            {
                if (ucChannelType == CHANNEL_TYPE_INVALID)
                {
                    Console.WriteLine("Channel Type? (Master = 0, Slave = 1)");
                    try
                    {
                        ucChannelType = byte.Parse(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        ucChannelType = CHANNEL_TYPE_INVALID;
                    }
                }

                if (ucChannelType == 0)
                {
                    channelType = ANT_ReferenceLibrary.ChannelType.BASE_Master_Transmit_0x10;
                }
                else if (ucChannelType == 1)
                {
                    channelType = ANT_ReferenceLibrary.ChannelType.BASE_Slave_Receive_0x00;
                }
                else
                {
                    ucChannelType = CHANNEL_TYPE_INVALID;
                    Console.WriteLine("Error: Invalid channel type");
                }
            } while (ucChannelType == CHANNEL_TYPE_INVALID);

            try
            {
                ConfigureANT();

                while (!bDone)
                {
                    string command = Console.ReadLine();
                    switch (command)
                    {
                    case "M":
                    case "m":
                    {
                        PrintMenu();
                        break;
                    }

                    case "Q":
                    case "q":
                    {
                        // Quit
                        Console.WriteLine("Closing Channel");
                        bBroadcasting = false;
                        channel0.closeChannel();
                        break;
                    }

                    case "A":
                    case "a":
                    {
                        // Send Acknowledged Data
                        byte[] myTxBuffer = { 1, 2, 3, 4, 5, 6, 7, 8 };
                        channel0.sendAcknowledgedData(myTxBuffer);
                        break;
                    }

                    case "B":
                    case "b":
                    {
                        // Send Burst Data (10 packets)
                        byte[] myTxBuffer = new byte[8 * 10];
                        for (byte i = 0; i < 8 * 10; i++)
                        {
                            myTxBuffer[i] = i;
                        }
                        channel0.sendBurstTransfer(myTxBuffer);
                        break;
                    }

                    case "R":
                    case "r":
                    {
                        // Reset the system and start over the test
                        ConfigureANT();
                        break;
                    }

                    case "C":
                    case "c":
                    {
                        // Request capabilities
                        ANT_DeviceCapabilities devCapab = device0.getDeviceCapabilities(500);
                        Console.Write(devCapab.printCapabilities() + Environment.NewLine);
                        break;
                    }

                    case "V":
                    case "v":
                    {
                        // Request version
                        // As this is not available in all ANT parts, we should not wait for a response, so
                        // we do not specify a timeout
                        // The response - if available - will be processed in DeviceResponse
                        device0.requestMessage(ANT_ReferenceLibrary.RequestMessageID.VERSION_0x3E);
                        break;
                    }

                    case "S":
                    case "s":
                    {
                        // Request channel status
                        ANT_ChannelStatus chStatus = channel0.requestStatus(500);

                        string[] allStatus = { "STATUS_UNASSIGNED_CHANNEL",
                                               "STATUS_ASSIGNED_CHANNEL",
                                               "STATUS_SEARCHING_CHANNEL",
                                               "STATUS_TRACKING_CHANNEL" };
                        Console.WriteLine("STATUS: " + allStatus[(int)chStatus.BasicStatus]);
                        break;
                    }

                    case "I":
                    case "i":
                    {
                        // Request channel ID
                        ANT_Response respChID           = device0.requestMessageAndResponse(ANT_ReferenceLibrary.RequestMessageID.CHANNEL_ID_0x51, 500);
                        ushort       usDeviceNumber     = (ushort)((respChID.messageContents[2] << 8) + respChID.messageContents[1]);
                        byte         ucDeviceType       = respChID.messageContents[3];
                        byte         ucTransmissionType = respChID.messageContents[4];
                        Console.WriteLine("CHANNEL ID: (" + usDeviceNumber.ToString() + "," + ucDeviceType.ToString() + "," + ucTransmissionType.ToString() + ")");
                        break;
                    }

                    case "D":
                    case "d":
                    {
                        bDisplay = !bDisplay;
                        break;
                    }

                    case "U":
                    case "u":
                    {
                        // Print out information about the device we are connected to
                        Console.WriteLine("USB Device Description");

                        // Retrieve info
                        Console.WriteLine(String.Format("   VID: 0x{0:x}", device0.getDeviceUSBVID()));
                        Console.WriteLine(String.Format("   PID: 0x{0:x}", device0.getDeviceUSBPID()));
                        Console.WriteLine(String.Format("   Product Description: {0}", device0.getDeviceUSBInfo().printProductDescription()));
                        Console.WriteLine(String.Format("   Serial String: {0}", device0.getDeviceUSBInfo().printSerialString()));
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                    System.Threading.Thread.Sleep(0);
                }
                // Clean up ANT
                Console.WriteLine("Disconnecting module...");
                ANT_Device.shutdownDeviceInstance(ref device0);  // Close down the device completely and completely shut down all communication
                Console.WriteLine("Demo has completed successfully!");
                return;
            }
            catch (Exception ex)
            {
                throw new Exception("Demo failed: " + ex.Message + Environment.NewLine);
            }
        }
예제 #4
0
        static void Start()
        {
            bDone = false;

            PrintMenu();

            try
            {
                ConfigureANT();

                while (!bDone)
                {
                    string command = Console.ReadLine();
                    switch (command)
                    {
                    case "M":
                    case "m":
                    {
                        PrintMenu();
                        break;
                    }

                    case "Q":
                    case "q":
                    {
                        // Quit
                        Console.WriteLine("Closing Channel");
                        channel0.closeChannel();
                        break;
                    }

                    case "A":
                    case "a":
                    {
                        byte[] myTxBuffer = { 1, 2, 3, 4, 5, 6, 7, 8 };
                        channel0.sendAcknowledgedData(myTxBuffer);
                        break;
                    }

                    case "B":
                    case "b":
                    {
                        byte[] myTxBuffer = new byte[8 * 10];
                        for (byte i = 0; i < 8 * 10; i++)
                        {
                            myTxBuffer[i] = i;
                        }
                        channel0.sendBurstTransfer(myTxBuffer);
                        break;
                    }

                    case "C":
                    case "c":
                    {
                        ANT_DeviceCapabilities devCapab0 = device0.getDeviceCapabilities(500);
                        Console.Write(devCapab0.printCapabilities() + Environment.NewLine);
                        break;
                    }

                    case "V":
                    case "v":
                    {
                        device0.requestMessage(ANT_ReferenceLibrary.RequestMessageID.VERSION_0x3E);
                        break;
                    }

                    case "I":
                    case "i":
                    {
                        ANT_Response respChID0           = device0.requestMessageAndResponse(ANT_ReferenceLibrary.RequestMessageID.CHANNEL_ID_0x51, 500);
                        ushort       usDeviceNumber0     = (ushort)((respChID0.messageContents[2] << 8) + respChID0.messageContents[1]);
                        byte         ucDeviceType0       = respChID0.messageContents[3];
                        byte         ucTransmissionType0 = respChID0.messageContents[4];
                        Console.WriteLine("CHANNEL ID: (" + usDeviceNumber0.ToString() + "," + ucDeviceType0.ToString() + "," + ucTransmissionType0.ToString() + ")");
                        ANT_Response respChID1           = device0.requestMessageAndResponse(ANT_ReferenceLibrary.RequestMessageID.CHANNEL_ID_0x51, 500);
                        ushort       usDeviceNumber1     = (ushort)((respChID1.messageContents[2] << 8) + respChID1.messageContents[1]);
                        byte         ucDeviceType1       = respChID1.messageContents[3];
                        byte         ucTransmissionType1 = respChID1.messageContents[4];
                        Console.WriteLine("CHANNEL ID: (" + usDeviceNumber1.ToString() + "," + ucDeviceType1.ToString() + "," + ucTransmissionType1.ToString() + ")");
                        break;
                    }

                    case "U":
                    case "u":
                    {
                        Console.WriteLine("USB Device Description");
                        Console.WriteLine(String.Format("   VID: 0x{0:x}", device0.getDeviceUSBVID()));
                        Console.WriteLine(String.Format("   PID: 0x{0:x}", device0.getDeviceUSBPID()));
                        Console.WriteLine(String.Format("   Product Description: {0}", device0.getDeviceUSBInfo().printProductDescription()));
                        Console.WriteLine(String.Format("   Serial String: {0}", device0.getDeviceUSBInfo().printSerialString()));
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                    System.Threading.Thread.Sleep(0);
                }
                Console.WriteLine("Disconnecting module...");
                ANT_Device.shutdownDeviceInstance(ref device0);
                return;
            }
            catch (Exception ex)
            {
                throw new Exception("Demo failed: " + ex.Message + Environment.NewLine);
            }
        }