コード例 #1
0
ファイル: FrmCalibration.cs プロジェクト: yxksys/HFM
 /// <summary>
 /// 开启串口封装的方法
 /// </summary>
 private void OpenPort()
 {
     //从配置文件获得当前串口配置
     if (_commPort.Opened)
     {
         _commPort.Close();
     }
     _commPort.GetCommPortSet("commportSet");
     //打开串口
     try
     {
         _commPort.Open();
         if (_commPort.Opened)
         {
             Tools.FormBottomPortStatus = true;
         }
         else
         {
             Tools.FormBottomPortStatus = false;
         }
     }
     catch
     {
         _tools.PrompMessage(1);
     }
 }
コード例 #2
0
        /// <summary>
        /// 窗体关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_FormClosed(object sender, FormClosedEventArgs e)
        {
            try
            {
                CommPort com = CommPort.Instance;
                if (com.IsOpen == true)
                {
                    com.Close();
                }

                UserInfo objUserInfo = UserInfo.Instance;
                db.dbMrg.AddAlertInfo("01", "01", objUserInfo.getUserName(), DateTime.Now.ToString(), "01", "关闭窗口");
                if (m_objAlertMrg != null)
                {
                    m_objAlertMrg.DisposeRes();
                }
            }
            catch (Exception ex)
            {
                utils.loghelp.log.Error(ex.Message, ex);
                MessageBox.Show("异常:" + ex.ToString(), "提示");
            }
            finally
            {
                System.Environment.Exit(0);
            }
        }
コード例 #3
0
        /// <summary>
        /// 关闭串口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonClose_Click(object sender, EventArgs e)
        {
            try
            {
                buttonOpen.Enabled        = true;
                comboBoxPortName.Enabled  = true;
                comboBoxBaudRate.Enabled  = true;
                comboBoxDataBits.Enabled  = true;
                comboBoxParity.Enabled    = true;
                comboBoxStopBits.Enabled  = true;
                comboBoxHandshake.Enabled = true;
                CommPort com = CommPort.Instance;



                if (com.IsOpen == false)
                {
                    MessageBox.Show("串口没被打开", "提示");
                }
                if (com.IsOpen == true)
                {
                    com.Close();
                }
            }
            catch (Exception ex)
            {
                LogClass.WriteLogFile("Exception:" + ex.ToString());
            }
        }
コード例 #4
0
 /// <summary>
 /// 打开
 /// </summary>
 public void Open()
 {
     if (_Commport.PortOpened)
     {
         _Commport.Close();
     }
     _Commport.Open();
     if (_Commport.PortOpened)
     {
         _Commport.OnDataArrivedEvent -= new DataArrivedDelegate(Commport_OnDataArrivedEvent);
         _Commport.OnDataArrivedEvent += new DataArrivedDelegate(Commport_OnDataArrivedEvent);
     }
     else
     {
         throw new Exception("串口打开失败");
     }
 }
コード例 #5
0
ファイル: ComConnector.cs プロジェクト: zhangjianqi/RemotePLC
 public override bool Connect()
 {
     try
     {
         if (_vcom.IsOpen)
         {
             _vcom.Close();
         }
         _vcom.Open(_connectionInfo.VComName4Socket);
     }
     catch (Exception e)
     {
         Logger.Error(e.ToString());
         return(false);
     }
     return(true);
 }
コード例 #6
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (controlThread != null)
     {
         stop = true;
         controlThread.Join();
     }
     cp.Close();
 }
コード例 #7
0
        // runs sucking data out of the comm port and into the recv buffer.
        // sort of a hack but needs to be polling because ComEmulDrv ports do not
        // seem to work w/ events.
        //  this thread is now somewhat misnamed as it handles both reading and writing
        //  Read and write need to be run on the same thread as Windows does not seem to be
        // able to handle read on one thread and write on another without deadlocking from time
        // to time.
        // not a big problem .. we set the comm port to not block and then alternate reading and
        // writing data from the port.
        private void RecvThread()
        {
            byte[] recv_buf = new byte[100];              // 20 bytes should be enough
            byte[] xmit_buf = new byte[100];
            int    num_read;
            uint   num_to_write;
            int    num_written;

#if DEBUG
            Console.WriteLine("SDRSerialPort.RecvThread alive and well");
#endif
            while (keepRecvThreadRunning)
            {
                try
                {
                    num_read = commPort.Read(recv_buf, 100);                     // fixme -- error checking
                    // Console.WriteLine("numread=" + num_read);
                    if (num_read > 0)
                    {
                        recvBuf.put(recv_buf, (uint)num_read);
                    }
                    num_to_write = xmitBuf.get(xmit_buf, 100);
                    if (num_to_write > 0)
                    {
                        num_written = commPort.Write(xmit_buf, (int)num_to_write);
                    }
                    if (keepRecvThreadRunning && !close_pending)
                    {
                        xmitBuf.waitForData(recvThreadPollingInterval);
                    }
                    // Thread.Sleep(recvThreadPollingInterval);
                }
                catch (ThreadInterruptedException) {}
            }
            if (close_pending)
            {
                commPort.Close();
            }
#if DEBUG
            Console.WriteLine("SDRSerialPort.RecvThread dies");
#endif
        }
コード例 #8
0
 private void Disconnect()
 {
     if (DisconnectButton.Enabled)
     {
         try
         {
             if (CommPort != null && CommPort.IsOpen)
             {
                 CommPort.Close();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Disconnect Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
         {
             CommPort = null;
         }
         udpCommunicator.Disconnect();
     }
 }
コード例 #9
0
        public FrmHelp()
        {
            InitializeComponent();
            //系统参数对象
            Components.SystemParameter systemParameter = new Components.SystemParameter().GetParameter();
            //工厂参数对象(包含软件仪器名称)
            FactoryParameter factoryParameter = new FactoryParameter().GetParameter();

            //从配置文件获得当前串口配置
            if (_commPort.Opened == true)
            {
                _commPort.Close();
            }



            if (systemParameter.IsEnglish == false)
            {
                //仪器名称
                LblName.Text = "仪器名称:" + factoryParameter.SoftName;
                //软件版本
                LblVersions.Text = "软件版本:" + "V1.0";
                //联系方式
                LblNumber.Text = "联系方式:" + "0351-2202150  2203549";
                //版权所有
                LblCopyright.Text = "版权所有(C) 山西中辐核仪器有限责任公司";
            }
            else//英文
            {
                //仪器名称
                LblName.Text = "Model:" + factoryParameter.SoftName;
                //软件版本
                LblVersions.Text = "Version:" + "V1.0";
                //联系方式
                LblNumber.Text = "Tel:" + "0351-2202150  2203549";
                //版权所有
                LblCopyright.Text = "Copyright (c) Shanxi Zhongfu Nuclear Instruments Co., Ltd";
            }
        }
コード例 #10
0
ファイル: ProtocolController.cs プロジェクト: radu-v/mppt-cli
        public bool Open()
        {
            Trace.Assert(CommPort != null);
            try
            {
                if (CommPort.IsOpen)
                {
                    CommPort.Close();
                }

                logger.Verbose($"Protocol.Open:{GetCommPortSettings()}");
                Trace.Assert(!CommPort.IsOpen);
                CommPort.Open();
                logger.Verbose($"- {(CommPort.IsOpen ? "OPEN" : "NOT OPENED")}");
                SendCommand("ECHO=OFF");
            }
            catch (Exception exception)
            {
                logger.Error($"Could Not Open {GetCommPortSettings()} \n{exception.Message}\nPlease Check Comm Settings.");
            }

            return(CommPort.IsOpen);
        }
コード例 #11
0
        /// <summary>
        ///     Establishes a link with the instrument
        /// </summary>
        protected override async Task ConnectToInstrument()
        {
            await WakeUpInstrument();

            if (IsAwake)
            {
                var response = await ExecuteCommand(Commands.SignOn(InstrumentType));

                if (response.IsSuccess)
                {
                    IsConnected = true;
                    Log.Info($"[{CommPort.Name}] Connected to {InstrumentType}!");
                }
                else
                {
                    if (response.ResponseCode == ResponseCode.FramingError)
                    {
                        await CommPort.Close();
                    }

                    throw new Exception($"Error response {response.ResponseCode}");
                }
            }
        }
コード例 #12
0
        private void FrmTestHardware_Load(object sender, EventArgs e)
        {
            #region 中英文转换

            if (_isEnglish)
            {
                Text                      = "Hardware Checking"; //硬件检测
                LblLHP.Text               = "LHP";               //左手心
                LblLHB.Text               = "LHB";               //左手背
                LblRHP.Text               = "RHP";               //右手心
                LblRHB.Text               = "RHB";               //右手背
                LblLF.Text                = "LF";                //左脚
                LblRF.Text                = "RF";                //右脚
                LblHighVoltage.Text       = "High Voltage";      //探头高压
                Lblαcountrate.Text        = "αcount rate";       //α计数率
                LblαTotalcnt.Text         = "αTotal cnt";        //α总计数
                Lblβcountrate.Text        = "βcount rate";       //β计数率
                LblβTotalcnt.Text         = "βTotal cnt";        //β总计数
                LblStatus.Text            = "Status";            //工作状态
                LblV.Text                 = "V";
                LblAlphacps.Text          = "cps";
                LblAlphacnt.Text          = "cnt";
                LblBetacps.Text           = "cps";
                LblBetacnt.Text           = "cnt";
                GrpFrisker.Text           = "Frisker";             //衣物探头
                LblFriskercount.Text      = "Count rate";          //计数
                GrpSensorstate.Text       = "Sensor state";        //红外状态
                LblFriskerState.Text      = "Frisker";             //衣物
                LblRHandState.Text        = "RHand";               //右手
                LblLHandState.Text        = "LHand";               //左手
                GrpDetectorSelfTest.Text  = "Detector Self-Test";  //探头自检
                BtnAlphaCheck.Text        = "α";                   //α自检
                BtnBetaCheck.Text         = "β";                   //β自检
                GrpSelfTestParameter.Text = "Self-Test Parameter"; //自检参数
                BtnSelfCheck.Text         = "Run";                 //自检
                CmbControl.Text           = "L";
                CmbPulse.Text             = "L";
                LblControl.Text           = "Control";    //控制
                LblPWidth.Text            = "P Width";    //脉宽
                LblPulse.Text             = "Pulse";      //脉冲
                LblSelfcount.Text         = "Count rate"; //计数
            }

            #endregion 中英文转换

            //初始化运行状态为默认状态
            _platformState = HardwarePlatformState.Default;
            //初始化测量时间为系统参数时间
            _measuringTime = _sqltime + 1;

            #region 开启端口

            //从配置文件获得当前串口配置
            if (_commPort.Opened == true)
            {
                _commPort.Close();
            }

            _commPort.GetCommPortSet("commportSet");
            //打开串口
            try
            {
                _commPort.Open();
                if (_commPort.Opened)
                {
                    Tools.FormBottomPortStatus = true;
                }
                else
                {
                    Tools.FormBottomPortStatus = false;
                }
            }
            catch
            {
                if (_isEnglish == true)
                {
                    MessageBox.Show("Port open error! Please check whether the communication is normal.");
                    //return;
                }
                else
                {
                    MessageBox.Show("端口打开错误!请检查通讯是否正常。");
                    //return;
                }
            }

            #endregion 开启端口

            //获得通道信息
            Channel channel = new Channel();
            channelS = channel.GetChannel();
            if (bkWorkerReceiveData.IsBusy == false)
            {
                //开启异步线程
                bkWorkerReceiveData.RunWorkerAsync();
            }
        }
コード例 #13
0
 public void Close()
 {
     _Commport.Close();
 }
コード例 #14
0
 /// <summary>
 /// 关闭扫瞄枪
 /// </summary>
 public void Close()
 {
     _comm.Close();
 }