예제 #1
0
        /// <summary>
        /// Scan for devices using a USB Belt Clip Radio
        /// </summary>
        /// <param name="iChannel">The channel to scan.</param>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //  02/25/08 RCG 1.50.10        Created
        //  04/09/09 AF  2.20.00        Added code to distinguish between an Itron ZBCR
        //                              and a Telegesis dongle
        //  09/18/15 jrf 4.21.04 616082 Modified to send a beacon burst and encapsulated storing found networks
        //                              in a new method.
        private void ScanUsingUSBBeltClipRadio(int iChannel)
        {
            Radio BeltClipRadio = new BeltClipRadio();

            ZigbeeNetwork[] ZigBeeNetworks = null;
            ZigbeeResult    Result         = ZigbeeResult.ERROR;

            if (m_ScanningRadio != null && iChannel == SCAN_CHANNELS[0])
            {
                if (ZigBeeRadioToken.ZigBeeRadioType.USBRadio == m_ScanningRadio.RadioType)
                {
                    ((BeltClipRadio)BeltClipRadio).RadioManufacturer = Itron.Metering.Zigbee.BeltClipRadio.RadioMfg.ItronZBCR;
                }
                else
                {
                    ((BeltClipRadio)BeltClipRadio).RadioManufacturer = Itron.Metering.Zigbee.BeltClipRadio.RadioMfg.TelegesisDongle;
                }

                BeltClipRadio.OpenPort(m_ScanningRadio.RadioIdentifier);

                if (BeltClipRadio.IsOpen == true)
                {
                    uint BeaconChannels = 0;

                    WriteLog(Logger.LoggingLevel.Minimal, "\tBeacon Channels: ");
                    for (int iIndex = 0; iIndex < SCAN_CHANNELS.Length; iIndex++)
                    {
                        BeaconChannels |= (uint)(0x1 << SCAN_CHANNELS[iIndex]);
                        WriteLog(Logger.LoggingLevel.Minimal, "\t\t Channel " + (SCAN_CHANNELS[iIndex]).ToString(CultureInfo.InvariantCulture));
                    }

                    ZigBeeNetworks = BeltClipRadio.SendBeaconBurst(BeaconChannels);

                    //Store off networks found during burst.
                    StoreZigBeeNetworks(ZigBeeNetworks);

                    for (int iIndex = 0; iIndex < SCAN_CHANNELS.Length; iIndex++)
                    {
                        Result = BeltClipRadio.FindNetworks(BeaconChannels, out ZigBeeNetworks, true);

                        if (Result == ZigbeeResult.SUCCESS)
                        {
                            StoreZigBeeNetworks(ZigBeeNetworks);
                        }
                    }
                }

                BeltClipRadio.ClosePort();
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the list of USB Belt Clip Radios that are currently connected to the computer.
        /// </summary>
        /// <returns>The list of USB Belt Clip Radios</returns>
        //  Revision History
        //  MM/DD/YY Who Version ID Issue# Description
        //  -------- --- ------- -- ------ -------------------------------------------
        //  02/25/08 RCG 1.50.10           Created
        //  04/20/17 jrf 4.72.00 WR 573799 Added code to verify Beltclip radio is indeed a Beltclip radio.
        private List <ZigBeeRadioToken> GetUSBRadioList()
        {
            List <ZigBeeRadioToken> RadioList = new List <ZigBeeRadioToken>();

            // Set up the Query to WMI Win32_PnPEntity
            SelectQuery Query = new SelectQuery("Win32_PnPEntity");
            ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Query);

            // Check the available objects to see if any IADongles are present.
            foreach (ManagementObject Object in Searcher.Get())
            {
                // The DeviceID has three parts separated by '\' so we need to break it down to get the device address
                string[] strSeparator = { @"\" };
                string[] DeviceID     = Object["DeviceID"].ToString().Split(strSeparator, StringSplitOptions.None);

                // Find the USB Radio by checking against the VID and PID
                if (DeviceID[0] == "FTDIBUS" && DeviceID[1].Contains(BC_USB_RADIO_ID))
                {
                    // The COM Port is in the name of the entry we are looking for so we need to parse it out.
                    string strRadioName = Object["Name"].ToString();
                    int    iStartIndex  = strRadioName.IndexOf('(');
                    int    iStopIndex   = strRadioName.IndexOf(')');

                    // Make sure the indices are valid so we can get the correct port name. Without the port we can't really use the radio
                    if (iStartIndex >= 0 && iStartIndex < strRadioName.Length && iStopIndex > iStartIndex && iStopIndex < strRadioName.Length)
                    {
                        BeltClipRadio    BeltClipRadio = new BeltClipRadio();
                        ZigBeeRadioToken NewUSBRadio   = new ZigBeeRadioToken(ZigBeeRadioToken.ZigBeeRadioType.USBRadio, strRadioName.Substring(iStartIndex + 1, iStopIndex - iStartIndex - 1));

                        //We are having non radio devices getting flagged as beltclip radios.
                        //So let's try to connect to radio to rule out false positives.
                        try
                        {
                            BeltClipRadio.OpenPort(NewUSBRadio.RadioIdentifier);

                            if (BeltClipRadio.IsOpen == true)
                            {
                                if (BeltClipRadio.C177App.IsConnected)
                                {
                                    //We connected so we know it's good.
                                    RadioList.Add(NewUSBRadio);
                                }
                            }
                        }
                        catch { /*Ignore exception*/ }
                        finally
                        {
                            BeltClipRadio.ClosePort();
                        }
                    }
                }
                else if (DeviceID[0] == "USB" && DeviceID[1].Contains(TELEGESIS_RADIO_ID))
                {
                    // The COM Port is in the name of the entry we are looking for so we need to parse it out.
                    string strRadioName = Object["Name"].ToString();
                    int    iStartIndex  = strRadioName.IndexOf('(');
                    int    iStopIndex   = strRadioName.IndexOf(')');

                    // Make sure the indices are valid so we can get the correct port name. Without the port we can't really use the radio
                    if (iStartIndex >= 0 && iStartIndex < strRadioName.Length && iStopIndex > iStartIndex && iStopIndex < strRadioName.Length)
                    {
                        RadioList.Add(new ZigBeeRadioToken(ZigBeeRadioToken.ZigBeeRadioType.TelegesisRadio, strRadioName.Substring(iStartIndex + 1, iStopIndex - iStartIndex - 1)));
                    }
                }
            }

            return(RadioList);
        }