예제 #1
0
        bool CloseStethoscope(string stethoscopeName)
        {
            var stethoscopes = StethoscopeManager.StethoscopeList.Where(s => s.Name == stethoscopeName);

            if (stethoscopes.Count() == 0)
            {
                return(false);
            }
            var stethoscope = stethoscopes.First();

            var formProcessBar = new FrmProcessBar(false, string.Format("正在断设备 {0} 连接!", stethoscopeName))
            {
                CancelBtnVisible = false
            };
            Thread pairThread = new Thread(() =>
            {
                //var _stethoscope = obj as Stethoscope;
                try
                {
                    if (stethoscope.IsConnected)
                    {
                        stethoscope.Disconnected += (s, arg) =>
                        {
                            Invoke(new MethodInvoker(() =>
                            {
                                formProcessBar.Close();
                            }));
                        };
                        stethoscope.Disconnect();
                        Mediator.ShowMsg(string.Format("听诊器{0}断开成功", stethoscope.Name));
                    }
                }
                catch (Exception ex)
                {
                    Mediator.ShowMsg(string.Format("听诊器{0}断开失败", stethoscope.Name));
                    //好像从来没有进来过
                }
                finally
                {
                    Invoke(new MethodInvoker(delegate()
                    {
                        formProcessBar.Close();
                    }));
                }
            });

            pairThread.Start();
            formProcessBar.ShowDialog();
            return(stethoscope.IsConnected);
        }
예제 #2
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);
        }
예제 #3
0
        bool OpenStethoscope(string stethoscopeName)
        {
            var stethoscopes = StethoscopeManager.StethoscopeList.Where(s => s.Name == stethoscopeName);

            if (stethoscopes.Count() == 0)
            {
                return(false);
            }
            var stethoscope    = stethoscopes.First();
            var formProcessBar = new FrmProcessBar(false, string.Format("正在开启设备{0}连接!", stethoscopeName))
            {
                CancelBtnVisible = false
            };;
            Thread pairThread = new Thread(() =>
            {
                //var _stethoscope = obj as Stethoscope;
                try
                {
                    if (!stethoscope.IsConnected)
                    {
                        stethoscope.Connect();
                        Mediator.ShowMsg(string.Format("听诊器{0}连接成功", stethoscope.Name));
                    }
                }
                catch (Exception ex)
                {
                    Mediator.ShowMsg(string.Format("听诊器{0}连接失败", stethoscope.Name));
                    //MessageBox.Show("听诊器连接失败,请确认听诊器是否开启了蓝牙连接状态!");
                    Mediator.ShowMsg("听诊器连接失败,请确认听诊器是否开启了蓝牙连接状态!");
                }
                finally
                {
                    Invoke(new MethodInvoker(delegate()
                    {
                        formProcessBar.Close();
                    }));
                }
            });

            pairThread.Start();
            formProcessBar.ShowDialog();
            return(stethoscope.IsConnected);
        }
예제 #4
0
        bool CloseStethoscope(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.Disconnect();
                        ShowMsg(string.Format("听诊器 {0} 断开连接...", stethoscopeName), false);
                    }
                }
                catch (Exception ex)
                {
                    //好像从来没有进来过
                }
                finally
                {
                    Invoke(new MethodInvoker(() =>
                    {
                        formProcessBar.Close();
                    }));
                }
            });

            pairThread.Start();
            formProcessBar.ShowDialog();
            return(stethoscope.IsConnected);
        }
예제 #5
0
        void btnTeach_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cbBoxTZJX.Text))
            {
                MessageBox.Show("请选择一个已连接的听诊器,如果列表为空,请先连接本地听诊器!");
                return;
            }
            var arrRecvStethoscope = GetStethoscope();

            if (arrRecvStethoscope.Where(s => !s.IsConnected).Any())
            {
                MessageBox.Show("设备尚未全部准备就绪!");
                return;
            }
            if (!arrRecvStethoscope.Any())
            {
                MessageBox.Show("请选择听诊器!");
                return;
            }
            //1.判断所有勾选的听诊器处于蓝牙连接成功状态
            //2.开启源听诊设备
            var stethoscopeArr = StethoscopeManager.StethoscopeList.Where(s => s.Name == cbBoxTZJX.Text);

            if (stethoscopeArr.Count() == 0)
            {
                throw new Exception("目前没有检测到听诊器,请检测设备设置!");
            }
            var stethoscope = stethoscopeArr.First();

            if (!stethoscope.IsConnected)
            {
                Mediator.ShowMsg(string.Format("听诊器 {0} 尚未连接", stethoscope.Name));
                MessageBox.Show(string.Format("听诊器 {0} 尚未连接", stethoscope.Name));
                return;
            }
            //var arrRecvStethoscope=ucStetManager1.GetStethoscope().Where(item=>item.IsConnected);
            var formProcessBar = new FrmProcessBar(true)
            {
                BtnText = "停止教学"
            };
            Thread pairThread = new Thread(() =>
            {
                Mediator.isBusy = true;
                formProcessBar.TimerCallBackEvent += () =>
                {
                    Invoke(new MethodInvoker(delegate()
                    {
                        formProcessBar.Title = string.Format("音频教学中... {0} 秒", formProcessBar.Times);
                    }));
                };
                byte[] packet = new byte[128];
                stethoscope.StartAudioInput();
                foreach (var recvStethoscope in arrRecvStethoscope)
                {
                    if (recvStethoscope.IsConnected)
                    {
                        recvStethoscope.StartAudioOutput();
                    }
                }
                Mediator.ShowMsg(string.Format("听诊器 {0} 开始教学...", stethoscope.Name));
                // Stream audio from the stethoscope to the computer.
                while (formProcessBar.DialogResult != System.Windows.Forms.DialogResult.Cancel)
                {
                    int bytesRead = stethoscope.AudioInputStream.Read(packet, 0, packet.Length);
                    foreach (var recvStethoscope in arrRecvStethoscope)
                    {
                        if (recvStethoscope.IsConnected)
                        {
                            recvStethoscope.AudioOutputStream.Write(packet, 0, bytesRead);
                        }
                    }
                }
                Mediator.ShowMsg(string.Format("听诊器 {0} 教学完毕,时长 {1} 秒", stethoscope.Name, formProcessBar.Times));
            });

            pairThread.Start();
            formProcessBar.ShowDialog();
            formProcessBar.TimerEnable = false;
            stethoscope.StopAudioInput();
            foreach (var recvStethoscope in arrRecvStethoscope)
            {
                if (recvStethoscope.IsConnected)
                {
                    recvStethoscope.StopAudioOutput();
                }
            }
            Mediator.ShowMsg("音频教学完毕...");
            Mediator.isBusy = false;
        }