Example #1
0
        private void btnSetRunParam_Click(object sender, EventArgs e)
        {
            Global.nRestFlag = int.Parse(comboRestFlag.Text);
            Global.dataCount = int.Parse(comboDataCount.Text);
            Global.logOpen   = comboLogOpen.SelectedIndex;
            IniHelper.SetINIValue(iniPath, "main", "restflag", Global.nRestFlag.ToString());
            IniHelper.SetINIValue(iniPath, "main", "datacount", Global.dataCount.ToString());
            IniHelper.SetINIValue(iniPath, "main", "logopen", Global.logOpen.ToString());

            try
            {
                Global.socketPort = int.Parse(textSocketPort.Text.Trim());
                Global.socketHelper.Close();
                Thread.Sleep(100);
                Global.socketHelper = new SocketHelper("127.0.0.1", Global.socketPort);
                if (Global.socketHelper.Run())
                {
                    IniHelper.SetINIValue(iniPath, "main", "socketport", Global.socketPort.ToString());
                    MessageBox.Show("参数设置成功,网络服务已重新启动!");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("网络服务端口有误,请填写大于1024整数!");
            }
        }
Example #2
0
 //初始化串口参数及连接串口
 private bool InitComm()
 {
     //SerialPort comm = new SerialPort();
     Global.comm.PortName  = IniHelper.GetINIValue(iniPath, "comm", "port");
     Global.comm.BaudRate  = int.Parse(IniHelper.GetINIValue(iniPath, "comm", "bps"));
     Global.comm.Parity    = (Parity)Enum.Parse(typeof(Parity), IniHelper.GetINIValue(iniPath, "comm", "parity"));
     Global.comm.RtsEnable = false;
     Global.commHelper     = new CommHelper();
     if (Global.commHelper.comOpen(Global.comm))
     {
         return(true);
     }
     else
     {
         MessageBox.Show("串口打开失败!");
         return(false);
     }
 }
Example #3
0
 private void btnSetComm_Click(object sender, EventArgs e)
 {
     Global.commHelper.comClose();
     Global.comm.PortName = comboComm.Text;
     Global.comm.BaudRate = int.Parse(comboBPS.Text);
     Global.comm.Parity   = (Parity)Enum.Parse(typeof(Parity), comboParity.SelectedIndex.ToString());
     if (Global.commHelper.comOpen(Global.comm))
     {
         IniHelper.SetINIValue(iniPath, "comm", "port", Global.comm.PortName);
         IniHelper.SetINIValue(iniPath, "comm", "bps", Global.comm.BaudRate.ToString());
         IniHelper.SetINIValue(iniPath, "comm", "parity", ((int)Global.comm.Parity).ToString());
         MessageBox.Show("串口参数设置成功");
     }
     else
     {
         MessageBox.Show("串口设置失败!");
     }
 }
Example #4
0
 //初始化数据库参数及连接
 private bool InitDatabase()
 {
     try
     {
         DBInfo info = new DBInfo();
         info.type          = IniHelper.GetINIValue(iniPath, "database", "type");
         info.ip            = IniHelper.GetINIValue(iniPath, "database", "ip");
         info.dbname        = IniHelper.GetINIValue(iniPath, "database", "name");
         info.username      = IniHelper.GetINIValue(iniPath, "database", "username");
         info.password      = IniHelper.GetINIValue(iniPath, "database", "password");
         info.port          = int.Parse(IniHelper.GetINIValue(iniPath, "database", "port"));
         Global.mysqlHelper = new MysqlHelper(info);
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("初始化数据库失败!");
         return(false);
     }
     return(true);
 }
Example #5
0
 private void InitMainParam()
 {
     try
     {
         Global.stationAddr     = byte.Parse(IniHelper.GetINIValue(iniPath, "plc", "address"));
         Global.offset          = int.Parse(IniHelper.GetINIValue(iniPath, "plc", "offset"));
         Global.pinOffset       = int.Parse(IniHelper.GetINIValue(iniPath, "plc", "pinoffset"));
         Global.runStatusOffset = int.Parse(IniHelper.GetINIValue(iniPath, "plc", "statusoffset"));
         Global.writeCmd        = byte.Parse(IniHelper.GetINIValue(iniPath, "plc", "writecmd"));
         Global.readCmd         = byte.Parse(IniHelper.GetINIValue(iniPath, "plc", "readcmd"));
         Global.alertOffset     = int.Parse(IniHelper.GetINIValue(iniPath, "plc", "alertoffset"));
         Global.nRestFlag       = int.Parse(IniHelper.GetINIValue(iniPath, "main", "restflag"));
         Global.logOpen         = int.Parse(IniHelper.GetINIValue(iniPath, "main", "logopen"));
         Global.timeOut         = int.Parse(IniHelper.GetINIValue(iniPath, "main", "timeout"));
         Global.dataCount       = int.Parse(IniHelper.GetINIValue(iniPath, "main", "datacount"));
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("获取参数失败!");
     }
 }
Example #6
0
 private bool InitSocket()
 {
     Global.socketPort   = int.Parse(IniHelper.GetINIValue(iniPath, "main", "socketport"));
     Global.socketHelper = new SocketHelper("127.0.0.1", Global.socketPort);
     return(Global.socketHelper.Run());
 }