コード例 #1
0
ファイル: ZigBeeRadioService.cs プロジェクト: lenloe1/Stuff
        /// <summary>
        /// Releases the specified radio back to the radio management service.
        /// </summary>
        /// <param name="Radio">The radio object to be released.</param>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //  02/01/08 RCG 1.00           Created

        public void ReleaseZigBeeRadio(ZigBeeRadioToken Radio)
        {
            bool bRadioRemoved = false;

            if (Radio != null)
            {
                // Due to the nature of WCF we need to compare the identifiers to find the radio
                // references will not be the same across processes.
                foreach (ZigBeeRadioToken RadioToken in m_RadiosInUse)
                {
                    if (RadioToken.RadioType == Radio.RadioType &&
                        RadioToken.RadioIdentifier == Radio.RadioIdentifier)
                    {
                        bRadioRemoved = true;
                        m_RadiosInUse.Remove(RadioToken);
                        break;
                    }
                }

                if (bRadioRemoved)
                {
                    // We removed the radio from the list of radios in use so we can add it back to the available
                    m_AvailableRadios.Add(Radio);
                    Radio.Status = ZigBeeRadioToken.ZigBeeRadioStatus.Available;

                    WriteLog(Logger.LoggingLevel.Minimal, "Radio Released: " + Radio.RadioIdentifier);
                }
            }
        }
コード例 #2
0
ファイル: ZigBeeRadioService.cs プロジェクト: lenloe1/Stuff
        /// <summary>
        /// Requests a radio from the radio management service.
        /// </summary>
        /// <returns>A token to a ZigBee radio or null if no radios are available.</returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //  02/01/08 RCG 1.00           Created
        //  08/25/09 AF  2.21.03 138987 Increased the timeout for the semaphore

        public ZigBeeRadioToken RequestZigBeeRadio()
        {
            ZigBeeRadioToken SelectedRadio = null;

            if (m_AvailableRadios.Count > 1)
            {
                // Get the first radio that is not scanning
                foreach (ZigBeeRadioToken RadioToken in m_AvailableRadios)
                {
                    if (m_ScanningRadio != RadioToken)
                    {
                        SelectedRadio = RadioToken;
                        break;
                    }
                }

                if (SelectedRadio != null)
                {
                    m_AvailableRadios.Remove(SelectedRadio);
                    SelectedRadio.Status = ZigBeeRadioToken.ZigBeeRadioStatus.InUse;
                    m_RadiosInUse.Add(SelectedRadio);
                }
            }
            else if (m_AvailableRadios.Count == 1)
            {
                // This must mean that the only radio available is currently scanning so we need to
                // wait for scanning to complete to continue. We need to limit the wait time so we
                // don't lock up the calling application.
                if (m_ScanningRadioSemaphore.WaitOne(200, false) == true)
                {
                    SelectedRadio   = m_AvailableRadios[0];
                    m_ScanningRadio = null;

                    m_AvailableRadios.Remove(SelectedRadio);
                    SelectedRadio.Status = ZigBeeRadioToken.ZigBeeRadioStatus.InUse;
                    m_RadiosInUse.Add(SelectedRadio);

                    m_ScanningRadioSemaphore.Release();
                }
            }

            if (SelectedRadio != null)
            {
                WriteLog(Logger.LoggingLevel.Minimal, "Radio request succeeded: " + SelectedRadio.RadioIdentifier);
            }
            else if (m_AvailableRadios.Count > 0)
            {
                WriteLog(Logger.LoggingLevel.Minimal, "Radio request failed: Semaphore timeout");
            }
            else
            {
                WriteLog(Logger.LoggingLevel.Minimal, "Radio request failed: No available radios");
            }

            return(SelectedRadio);
        }
コード例 #3
0
ファイル: ZigBeeRadioChannel.cs プロジェクト: lenloe1/Stuff
        /// <summary>
        /// Requests a radio from the host.
        /// </summary>
        /// <returns>Null if no radio is available or a token to an available radio.</returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //  02/14/08 RCG 1.00           Created

        public ZigBeeRadioToken RequestZigBeeRadio()
        {
            ZigBeeRadioToken Radio = null;

            for (int iRetries = 0; iRetries < 40; iRetries++)
            {
                Radio = base.Channel.RequestZigBeeRadio();

                if (Radio != null)
                {
                    // We have a radio so we are done
                    break;
                }
                else
                {
                    Thread.Sleep(800);
                }
            }

            return(Radio);
        }
コード例 #4
0
ファイル: ZigBeeRadioService.cs プロジェクト: lenloe1/Stuff
        /// <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);
        }
コード例 #5
0
ファイル: ZigBeeRadioChannel.cs プロジェクト: lenloe1/Stuff
        /// <summary>
        /// Releases the specified radio back to the host.
        /// </summary>
        /// <param name="Radio">The radio token to release.</param>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ -------------------------------------------
        //  02/14/08 RCG 1.00           Created

        public void ReleaseZigBeeRadio(ZigBeeRadioToken Radio)
        {
            base.Channel.ReleaseZigBeeRadio(Radio);
        }