예제 #1
0
 private void ShowMessage(MessageType type, string str)
 {
     StatusBar.DisplayMessage(type, str);
 }
예제 #2
0
        private async void btnConnect_Click(object sender, EventArgs e)
        {
            if (VsmdController.GetVsmdController().IsInitialized())
            {
                VsmdController.GetVsmdController().Dispose();
                PumpController.GetPumpController().Dispose();
                UpdateControlState();
                return;
            }

            if (m_isConnecting)
            {
                return;
            }

            if (cmbPort.SelectedItem == null)
            {
                StatusBar.DisplayMessage(VsmdWorkstation.Controls.MessageType.Error, "电机端口不能为空!");
                return;
            }
            string vsmdPort = cmbPort.SelectedItem.ToString();

            bool       pumpExist = PumpController.GetPumpController().PumpExist;
            InitResult pumpRet   = new InitResult();

            pumpRet.IsSuccess = true;
            pumpRet.Message   = "";
            if (pumpExist)
            {
                if (cmbPumpPort.SelectedItem == null)
                {
                    StatusBar.DisplayMessage(VsmdWorkstation.Controls.MessageType.Error, "蠕动泵端口不能为空!");
                    return;
                }
                string pumpPort = cmbPumpPort.SelectedItem.ToString();
                if (vsmdPort == pumpPort)
                {
                    StatusBar.DisplayMessage(VsmdWorkstation.Controls.MessageType.Error, "电机端口与蠕动泵端口不能相同!");
                    return;
                }
                pumpRet = PumpController.GetPumpController().Init(pumpPort);
                if (pumpRet.IsSuccess)
                {
                    Preference.GetInstace().PumpPort = pumpPort;
                }
                Preference.GetInstace().Save();
            }


            int baudrate = int.Parse(cmbBaudrate.SelectedItem.ToString());

            m_isConnecting = true;
            InitResult vsmdRet = await VsmdController.GetVsmdController().Init(vsmdPort, baudrate);

            if (m_initCB != null)
            {
                InitResult connectRet = new InitResult();
                connectRet.IsSuccess = vsmdRet.IsSuccess && pumpRet.IsSuccess;
                connectRet.Message   = vsmdRet.IsSuccess ? pumpRet.Message : vsmdRet.Message;
                m_initCB(connectRet);
                m_isConnecting = false;
                //m_initCB = null;
            }
            if (vsmdRet.IsSuccess && pumpRet.IsSuccess)
            {
                Preference.GetInstace().VsmdPort = vsmdPort;
                GoHome();
                this.Close();
            }
        }