Exemplo n.º 1
0
        void PlayAudio(byte[] bytes, int TakeTime)
        {
            Mediator.isBusy = true;
            var stethoscopeArr = StethoscopeManager.StethoscopeList.Where(s => s.Name == StetName);

            if (!stethoscopeArr.Any())
            {
                MessageBox.Show("目前没有检测到听诊器,请检测设备设置!");
                return;
            }
            var stethoscope = stethoscopeArr.First();

            if (!stethoscope.IsConnected)
            {
                MessageBox.Show(string.Format("听诊器 {0} 尚未连接!", stethoscope.Name));
                return;
            }
            var formProcessBar = new FrmProcessBar(true)
            {
                ProgressBarStyle    = ProgressBarStyle.Continuous,
                ProgressBarMaxValue = TakeTime,
                BtnText             = "停止播放"
            };
            Thread pairThread = new Thread(() =>
            {
                formProcessBar.TimerCallBackEvent += () =>
                {
                    if (this.IsHandleCreated && !this.Disposing && !this.IsDisposed)
                    {
                        Invoke(new MethodInvoker(delegate()
                        {
                            formProcessBar.Title = string.Format("音频播放中... {0} 秒", formProcessBar.Times);
                            if (formProcessBar.Times <= formProcessBar.ProgressBarMaxValue)
                            {
                                formProcessBar.ProgressBarValue = formProcessBar.Times;
                            }
                            else
                            {
                                formProcessBar.Close();
                            }
                        }));
                    }
                };
                stethoscope.StartAudioOutput();
                stethoscope.AudioOutputStream.Write(bytes, 0, bytes.Length);
            });

            pairThread.Start();
            formProcessBar.ShowDialog();
            formProcessBar.TimerEnable = false;
            stethoscope.StopAudioOutput();
            Mediator.isBusy = false;
        }
Exemplo n.º 2
0
        public void HandleMessage(RemoteStartAudioOutputCode message)
        {
            if (this.IsDisposed || this.Disposing)
            {
                return;
            }
            if (message.Guid != this.Guid)
            {
                return;
            }
            this.Invoke(new MethodInvoker(() =>
            {
                var rows = this.DgvTable.Select("MAC='" + Setting.authorizationInfo.MachineCode + "'");

                foreach (DataRow row in rows)
                {
                    var stetName = row["StetName"] + "";
                    Mediator.ShowMsg(string.Format("远程听诊开始接收数据,编号为{0}", this.Guid));
                    var stethoscopeArr = StethoscopeManager.StethoscopeList.Where(s => s.Name == stetName);
                    if (!stethoscopeArr.Any())
                    {
                        throw new Exception("目前没有检测到听诊器,请检测设备设置!");
                    }
                    var stethoscope = stethoscopeArr.First();
                    if (!stethoscope.IsConnected)
                    {
                        Mediator.ShowMsg(string.Format("听诊器 {0} 尚未连接", stethoscope.Name));
                        return;
                    }
                    else
                    {
                        stethoscope.StartAudioOutput();
                    }
                }
            }));
            //本机远程
            if (message.SrcMac == Setting.authorizationInfo.MachineCode)
            {
                return;
            }
            // Mediator.isBusy = true;
            Thread thread = new Thread(() =>
            {
                this.Invoke(new MethodInvoker(() =>
                {
                    var formProcessBar = new FrmProcessBar(true)
                    {
                        BtnText          = "停止远程",
                        CancelBtnVisible = true
                    };
                    OnReceivedEvent += ((b) =>
                    {
                        if (!b)
                        {
                            this.Invoke(new MethodInvoker(() =>
                            {
                                if (!formProcessBar.IsDisposed)
                                {
                                    formProcessBar.Close();
                                }
                            }));
                        }
                    });
                    formProcessBar.OnActiveClose += () =>
                    {
                        this.Invoke(new MethodInvoker(() =>
                        {
                            var rows = this.DgvTable.Select("MAC='" + Setting.authorizationInfo.MachineCode + "'");
                            foreach (DataRow row in rows)
                            {
                                var stetName       = row["StetName"] + "";
                                var stethoscopeArr = StethoscopeManager.StethoscopeList.Where(s => s.Name == stetName);
                                if (!stethoscopeArr.Any())
                                {
                                    throw new Exception("目前没有检测到听诊器,请检测设备设置!");
                                }
                                var stethoscope = stethoscopeArr.First();
                                if (!stethoscope.IsConnected)
                                {
                                    Mediator.ShowMsg(string.Format("听诊器 {0} 尚未连接", stethoscope.Name));
                                    return;
                                }
                                else
                                {
                                    stethoscope.StopAudioOutput();
                                }
                            }
                            Mediator.ShowMsg(string.Format("主动退出听诊器,编号为{0}", this.Guid));
                            this.Close();
                        }));
                    };
                    formProcessBar.TimerCallBackEvent += () =>
                    {
                        Invoke(new MethodInvoker(() =>
                        {
                            formProcessBar.Title = string.Format("远程教学中... {0} 秒", formProcessBar.Times);
                        }));
                    };
                    formProcessBar.ShowDialog();
                }));
            });

            thread.Start();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 开始会诊
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAuscultate_Click(object sender, EventArgs e)
        {
            if (this.DgvTable.Rows.Count == 0)
            {
                MessageBox.Show(string.Format("目前尚未有听诊器加入..."));
                return;
            }
            var stethoscopeArr = StethoscopeManager.StethoscopeList.Where(s => s.Name == this.ucTextBoxEx1.Text);

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

            if (!stethoscope.IsConnected)
            {
                Mediator.ShowMsg(string.Format("听诊器 {0} 尚未连接", stethoscope.Name));
                return;
            }
            //Send Start To Remote
            foreach (var code in listRemoteStartAudioOutputCode())
            {
                var bytes = ProtocalData.Utilities.SerializaHelper.Serialize(code);
                Mediator.SuperSocket.Send(bytes);
            }
            var listRemoteAudioCode = ListRemoteAudioCode();

            Thread.Sleep(500);
            var formProcessBar = new FrmProcessBar(true)
            {
                BtnText = "停止远程"
            };
            Thread pairThread = new Thread(() =>
            {
                formProcessBar.TimerCallBackEvent += () =>
                {
                    Invoke(new MethodInvoker(delegate()
                    {
                        formProcessBar.Title = string.Format("远程教学中... {0} 秒", formProcessBar.Times);
                    }));
                };
                stethoscope.StartAudioInput();
                Mediator.ShowMsg(string.Format("听诊器 {0} 开始远程教学...", stethoscope.Name));
                // Stream audio from the stethoscope to the computer.
                while (formProcessBar.DialogResult != System.Windows.Forms.DialogResult.Cancel &&
                       dgvRemote.Rows.Count > 0)
                {
                    byte[] packet = new byte[128];
                    int bytesRead = stethoscope.AudioInputStream.Read(packet, 0, packet.Length);
                    //Send to Remote
                    if (bytesRead <= 0)
                    {
                        Thread.Sleep(100);
                        continue;
                    }
                    //Invoke(new MethodInvoker(() =>
                    //{
                    foreach (var code in listRemoteAudioCode)
                    {
                        code.AudioData = packet.Take(bytesRead).ToArray();
                        var bytes      = ProtocalData.Utilities.SerializaHelper.Serialize(code);
                        Mediator.SuperSocket.Send(bytes);
                    }
                    Thread.Sleep(1);
                    //}));
                }
                Mediator.ShowMsg(string.Format("听诊器 {0} 远程听诊完毕,时长 {1} 秒", stethoscope.Name, formProcessBar.Times));
                Invoke(new MethodInvoker(delegate()
                {
                    formProcessBar.Close();
                }));
            });

            pairThread.Start();

            //开始了
            string sql = "update RemoteAuscultate set Status =1 where GUID={0}";

            using (OperationContextScope scope = new OperationContextScope(Mediator.remoteService.InnerChannel))
            {
                MessageHeader header = MessageHeader.CreateHeader("SN", "http://tempuri.org", Setting.authorizationInfo.AuthorizationNum);
                OperationContext.Current.OutgoingMessageHeaders.Add(header);
                header = MessageHeader.CreateHeader("MAC", "http://tempuri.org", Setting.authorizationInfo.MachineCode);
                OperationContext.Current.OutgoingMessageHeaders.Add(header);
                Mediator.remoteService.ExecuteNonQuery(sql, new string[] { this.Guid });
            }
            formProcessBar.ShowDialog();
            formProcessBar.TimerEnable = false;
            stethoscope.StopAudioInput();
            //Send Over To Remote
            foreach (var code in listRemoteStopAudioOutputCode())
            {
                var bytes = ProtocalData.Utilities.SerializaHelper.Serialize(code);
                Mediator.SuperSocket.Send(bytes);
            }
            Mediator.ShowMsg("远程听诊完毕...");
        }
Exemplo n.º 4
0
        void PlayAudio(string filePath, int TakeTime)
        {
            if (!File.Exists(filePath))
            {
                MessageBox.Show(string.Format("音频文件{0}不存在...", Path.GetFileName(filePath)));
                return;
            }
            Mediator.isBusy = true;
            //var stethoscopeArr = StethoscopeManager.StethoscopeList.Where(s => s.Name == StetName);
            var stethoscopeArr = StethoscopeManager.StethoscopeList.Where(s => s.IsConnected);

            if (!stethoscopeArr.Any())
            {
                throw new Exception("目前没有检测到听诊器,请检测设备设置!");
            }
            //var stethoscope = stethoscopeArr.First();
            //if (!stethoscope.IsConnected)
            //{
            //    MessageBox.Show(string.Format("听诊器 {0} 尚未连接!", stethoscope.Name));
            //    return;
            //}
            Mediator.ShowMsg("开始播放文件..." + Path.GetFileName(filePath));
            var formProcessBar = new FrmProcessBar(true)
            {
                ProgressBarStyle    = ProgressBarStyle.Continuous,
                ProgressBarMaxValue = TakeTime,
                BtnText             = "停止播放"
            };
            Thread pairThread = new Thread(() =>
            {
                formProcessBar.TimerCallBackEvent += () =>
                {
                    if (this.IsHandleCreated && !this.Disposing && !this.IsDisposed)
                    {
                        Invoke(new MethodInvoker(delegate()
                        {
                            formProcessBar.Title = string.Format("音频播放中... {0} 秒", formProcessBar.Times);
                            if (formProcessBar.Times <= formProcessBar.ProgressBarMaxValue)
                            {
                                formProcessBar.ProgressBarValue = formProcessBar.Times;
                            }
                            else
                            {
                                formProcessBar.Close();
                            }
                        }));
                    }
                };
                var bytes = File.ReadAllBytes(filePath);
                foreach (var stethoscope in stethoscopeArr)
                {
                    stethoscope.StartAudioOutput();
                    stethoscope.AudioOutputStream.Write(bytes, 0, bytes.Length);
                }
            });

            pairThread.Start();
            formProcessBar.ShowDialog();
            formProcessBar.TimerEnable = false;
            foreach (var stethoscope in stethoscopeArr)
            {
                stethoscope.StopAudioOutput();
            }
            Mediator.ShowMsg("播放文件完毕..." + Path.GetFileName(filePath));
            Mediator.WriteLog(this.Name, string.Format("文件 {0} 播放成功...", Path.GetFileName(filePath)));
            Mediator.isBusy = false;
        }