示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                controler.config.comCd = Convert.ToInt32(tbComCd.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("请输入正确格式的串口CD");
                return;
            }

            try
            {
                controler.config.pmCd = Convert.ToInt32(tbPmCd.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("请输入正确格式的产品CD");
                return;
            }

            try
            {
                controler.config.readCodeCd = Convert.ToInt32(tbReadCodeCd.Text);
                if (controler.config.readCodeCd < 200)
                {
                    MessageBox.Show("读码延时必须大于等于200");
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("请输入正确格式的读码延时");
                return;
            }

            try
            {
                //controler.config.isDebug = cbDebug.Checked;
                controler.config.comEndStr = tbEndStr.Text;
                if (controler.config.comEndStr == string.Empty)
                {
                    MessageBox.Show("请输入串口结束符");
                    return;
                }

                controler.CreateDirectoryEx(Common.configFilePath);
                ZazaniaoDll.WritePrivateProfileString("SYS", "isDebug", Convert.ToString(controler.config.isDebug), Common.configFilePath);

                ZazaniaoDll.WritePrivateProfileString("SYS", "comCd", Convert.ToString(controler.config.comCd), Common.configFilePath);
                ZazaniaoDll.WritePrivateProfileString("SYS", "comEndStr", Convert.ToString(controler.config.comEndStr), Common.configFilePath);
                ZazaniaoDll.WritePrivateProfileString("SYS", "pmCd", Convert.ToString(controler.config.pmCd), Common.configFilePath);
                Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("保存异常");
                controler.log.LogErr(ex);
            }
        }
示例#2
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                //传递串口参数
                //串口号
                controler.config.m_iComPort = Convert.ToInt32(txPortName.Text);
                //波特率
                controler.config.m_iComBaudRate = Convert.ToInt32(txBaudRate.Text);
                //数据位
                controler.config.m_iComDataBits = Convert.ToInt32(txDataBits.Text);
                //校验位
                switch (cbParity.SelectedIndex)
                {
                case 0:
                    controler.config.m_iComParity = "None";
                    break;

                case 1:
                    controler.config.m_iComParity = "Odd";
                    break;

                case 2:
                    controler.config.m_iComParity = "Even";
                    break;

                case 3:
                    controler.config.m_iComParity = "Mark";
                    break;

                case 4:
                    controler.config.m_iComParity = "Space";
                    break;
                }
                //停止位
                switch (cbStopBits.SelectedIndex)
                {
                case 0:
                    controler.config.m_iComStopBits = "None";
                    break;

                case 1:
                    controler.config.m_iComStopBits = "One";
                    break;

                case 2:
                    controler.config.m_iComStopBits = "Two";
                    break;

                case 3:
                    controler.config.m_iComStopBits = "OnePointFive";
                    break;
                }
                controler.CreateDirectoryEx(Common.configFilePath);
                //保存串口参数到ini文件
                ZazaniaoDll.WritePrivateProfileString("COM", "m_iComPort", Convert.ToString(controler.config.m_iComPort), Common.configFilePath);
                ZazaniaoDll.WritePrivateProfileString("COM", "m_iComBaudRate", Convert.ToString(controler.config.m_iComBaudRate), Common.configFilePath);
                ZazaniaoDll.WritePrivateProfileString("COM", "m_iComDataBits", Convert.ToString(controler.config.m_iComDataBits), Common.configFilePath);
                ZazaniaoDll.WritePrivateProfileString("COM", "m_iComParity", controler.config.m_iComParity, Common.configFilePath);
                ZazaniaoDll.WritePrivateProfileString("COM", "m_iComStopBits", controler.config.m_iComStopBits, Common.configFilePath);

                Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("保存出现异常");
                controler.log.LogErr(ex);
            }
        }