Пример #1
0
        bool OpenStethoscope(string stethoscopeName)
        {
            var stethoscopes = StethoscopeManager.StethoscopeList.Where(s => s.Name == stethoscopeName);

            if (!stethoscopes.Any())
            {
                return(false);
            }
            var stethoscope    = stethoscopes.First();
            var formProcessBar = new FrmProcessBar(false, string.Format("正在开启设备{0}连接!", stethoscopeName))
            {
                CancelBtnVisible = false
            };;
            Thread pairThread = new Thread(() =>
            {
                try
                {
                    if (!stethoscope.IsConnected)
                    {
                        stethoscope.Connect();
                        ShowMsg(string.Format("听诊器 {0} 连接成功...", stethoscopeName), false);

                        if (OnSetehoscopeConnect != null)
                        {
                            OnSetehoscopeConnect();
                        }
                        Current = stethoscope;
                        //Mediator.ShowMsg(string.Format("听诊器{0}连接成功", stethoscope.Name));
                    }
                }
                catch (Exception ex)
                {
                    ShowMsg(string.Format("听诊器 {0} 连接失败...", stethoscopeName));
                }
                finally
                {
                    Invoke(new MethodInvoker(() =>
                    {
                        formProcessBar.Close();
                    }));
                }
            });

            pairThread.Start();
            formProcessBar.ShowDialog();
            return(stethoscope.IsConnected);
        }
        // Connect to the stethoscope targetStethoscope 
        public string ConnectToTargetStethoscope()
        {
            // only do anything if there is a stethoscope object to try connecting to...
            if (null != targetStethoscope)
            {
                // Try connecting to the stethoscope
                try
                {
                    targetStethoscope.Connect();
                    stethoscope = targetStethoscope;
                    //_audioFilter = stethoscope.Filter;
                    // Return the SN of the connected stethoscope
                    Console.WriteLine("Connected to " + stethoscope.SerialNumber);
                    return targetStethoscope.SerialNumber;
                }
                catch
                {
                    Console.WriteLine("Failed to connect to stethoscope (Serial number " + targetStethoscope.SerialNumber + ")!");
                    return ""; // could put a more useful error here
                }

            }
            else
            {
                Console.WriteLine("Stethoscope not found!");
                return ""; // could put a more useful error here
            }
        }
 public void Disconnect()
 {
     lock (this)
     {
         if (null != stethoscope)
         {
             Console.WriteLine("Disconnecting!");
             stethoscope.Disconnect();
             stethoscope = null;
         }
         else
         {
             Console.WriteLine("Not connected!");
         }
     }
 }
        public string Connect()
        {
            lock (this)
            {
                // Connect to the first available stethoscope
                IList<Stethoscope> availableStethoscopes = GetAvailableStethoscopes();
                targetStethoscope = availableStethoscopes.First<Stethoscope>();

                Console.WriteLine("Connecting to SN " + targetStethoscope.SerialNumber);

                return ConnectToTargetStethoscope();
            }
        }