Exemple #1
0
        //初始化串口
        public bool Init_SerialPort()
        {
            SerialConfigSection SC = GlobalCofigData.SerialConfig;

            ColseSerialPort();
            try
            {
                m_IsTryToClosePort  = false;
                Tp_ConnectState     = true;
                SralPrt.BaudRate    = 9600;         // SC.Braudrate;
                SralPrt.DataBits    = 8;            // SC.DataBites;
                SralPrt.StopBits    = StopBits.One; //(System.IO.Ports.StopBits)SC.StopBit;
                SralPrt.PortName    = SC.PortName;
                SralPrt.Parity      = System.IO.Ports.Parity.None;
                SralPrt.ReadTimeout = 1000;
                SralPrt.RtsEnable   = true;
                SralPrt.DtrEnable   = true;
                if (GlobalCofigData.SystemConfig.ControlType == ControlTypes.RS232)
                {
                    SralPrt.Open();
                }
                return(true);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("打开端口错误");
                Tp_ConnectState = false;
                return(false);
            }
        }
Exemple #2
0
        private void ReadConfigure()
        {
            try
            {
                ExeConfigurationFileMap file = new ExeConfigurationFileMap();
                file.ExeConfigFilename = Application.StartupPath + @"\Preferences.config";
                GlobalCofigData.Config = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);



                if (GlobalCofigData.Config.Sections["SystemConfig"] == null)
                {
                    SystemConfigSection customSection = new SystemConfigSection();
                    GlobalCofigData.Config.Sections.Add("SystemConfig", customSection);
                    customSection.SectionInformation.ForceSave = true;
                    GlobalCofigData.Config.Save(ConfigurationSaveMode.Full);
                }
                GlobalCofigData.SystemConfig = GlobalCofigData.Config.Sections["SystemConfig"] as SystemConfigSection;

                if (GlobalCofigData.Config.Sections["SerialConfig"] == null)
                {
                    SerialConfigSection customSection = new SerialConfigSection();
                    GlobalCofigData.Config.Sections.Add("SerialConfig", customSection);
                    customSection.SectionInformation.ForceSave = true;
                    GlobalCofigData.Config.Save(ConfigurationSaveMode.Full);
                }
                GlobalCofigData.SerialConfig = GlobalCofigData.Config.Sections["SerialConfig"] as SerialConfigSection;



                GlobalCofigData.MicroControllorPreferences = HexStringToByte(GlobalCofigData.SystemConfig.MicroControllorPreferences);
                GlobalCofigData.SystemConfig.PassWord      = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\Software\Sundy\SDAF", @"PassWord", "");
                if (GlobalCofigData.SystemConfig.PassWord == null)
                {
                    GlobalCofigData.SystemConfig.PassWord = "";
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString(), Properties.Resources.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }