示例#1
0
        private void ConnectVsmd_Load(object sender, EventArgs e)
        {
            cmbPort.Items.AddRange(SerialPort.GetPortNames());
            cmbPumpPort.Items.AddRange(SerialPort.GetPortNames());
            bool pumpExist = PumpController.GetPumpController().PumpExist;

            if (VsmdController.GetVsmdController().IsInitialized())
            {
                //lblCurInfo.Text = VsmdController.GetVsmdController().GetPort() + ", " + VsmdController.GetVsmdController().GetBaudrate() + ", " + PumpController.GetPumpController().GetPort();
                int idx = cmbPort.Items.IndexOf(VsmdController.GetVsmdController().GetPort());
                if (idx > -1)
                {
                    cmbPort.SelectedIndex = idx;
                }
                idx = cmbBaudrate.Items.IndexOf(VsmdController.GetVsmdController().GetBaudrate().ToString());
                if (idx > -1)
                {
                    cmbBaudrate.SelectedIndex = idx;
                }


                if (pumpExist)
                {
                    idx = cmbPumpPort.Items.IndexOf(PumpController.GetPumpController().GetPort());
                    if (idx > -1)
                    {
                        cmbPumpPort.SelectedIndex = idx;
                    }
                }

                UpdateControlState();
                return;
            }
            else
            {
                UpdateControlState();
            }

            if (Preference.GetInstace().HasPreference)
            {
                int idx = -1;
                if (Preference.GetInstace().VsmdPort != null)
                {
                    idx = cmbPort.Items.IndexOf(Preference.GetInstace().VsmdPort);
                }

                if (idx > -1)
                {
                    cmbPort.SelectedIndex = idx;
                }
                idx = cmbBaudrate.Items.IndexOf(Preference.GetInstace().Baudrate.ToString());
                if (idx > -1)
                {
                    cmbBaudrate.SelectedIndex = idx;
                }
                if (pumpExist)
                {
                    string pumpPort = Preference.GetInstace().PumpPort;
                    if (pumpPort != null)
                    {
                        idx = cmbPumpPort.Items.IndexOf(Preference.GetInstace().PumpPort);
                        if (idx > -1)
                        {
                            cmbPumpPort.SelectedIndex = idx;
                        }
                    }
                }
            }
            else
            {
                if (cmbPort.Items.Count > 0)
                {
                    cmbPort.SelectedIndex     = 0;
                    cmbPumpPort.SelectedIndex = 0;
                }
                cmbBaudrate.SelectedIndex = 2;
            }
            IsClosed = false;

            if (GeneralSettings.GetInstance().AutoConnect)
            {
                btnConnect.PerformClick();
            }
        }
示例#2
0
        public async Task <InitResult> Init(string port, int baudrate)
        {
            if (m_initialized && port == m_port && baudrate == m_baudrate)
            {
                return(new InitResult()
                {
                    Message = "设备连接成功!", IsSuccess = true
                });
            }

            m_port     = port;
            m_baudrate = baudrate;
            if (m_initialized)
            {
                m_vsmd.closeSerialPort();
            }

            m_vsmd = new VsmdSync();
            bool ret = m_vsmd.openSerialPort(port, baudrate);

            if (!ret)
            {
                return(new InitResult()
                {
                    Message = "打开串口失败!", IsSuccess = false
                });
            }
            m_vsmd.OutputCommandLog    = GeneralSettings.GetInstance().OutputCommandLog;
            m_vsmd.OutputStsCommandLog = GeneralSettings.GetInstance().OutputStsCommandLog;

            List <string> errAxis = new List <string>();

            m_axisX = m_vsmd.createVsmdInfo(1);
            await m_axisX.CheckAxisIsOnline();

            if (m_axisX.isOnline)
            {
                await m_axisX.enable();

                m_axisX.flgAutoUpdate = true;
                await m_axisX.cfg();
            }
            else
            {
                errAxis.Add("X");
            }

            m_axisY = m_vsmd.createVsmdInfo(2);
            await m_axisY.CheckAxisIsOnline();

            if (m_axisY.isOnline)
            {
                await m_axisY.enable();

                m_axisY.flgAutoUpdate = true;
                await m_axisY.cfg();
            }
            else
            {
                errAxis.Add("Y");
            }

            m_axisZ = m_vsmd.createVsmdInfo(3);
            await m_axisZ.CheckAxisIsOnline();

            if (m_axisY.isOnline)
            {
                await m_axisZ.enable();

                m_axisZ.flgAutoUpdate = true;
                m_axisZ.SetMaxWaitTimeForMove(3);
                await m_axisZ.cfg();
            }
            else
            {
                errAxis.Add("Z");
            }

            if (errAxis.Count <= 0)
            {
                m_initialized = true;
            }

            string errMsg = "";

            if (errAxis.Count > 0)
            {
                errMsg = "设备 ";
                for (int i = 0; i < errAxis.Count; i++)
                {
                    if (i > 0)
                    {
                        errMsg += ", ";
                    }
                    errMsg += errAxis[i];
                }
                errMsg += "连接失败!";
            }
            if (!m_initialized)
            {
                m_vsmd.closeSerialPort();
                m_vsmd = null;
            }

            return(new InitResult()
            {
                IsSuccess = m_initialized, Message = errMsg
            });
        }