//初始化串口参数及连接串口 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); } }
//初始化数据库参数及连接 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); }
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("获取参数失败!"); } }
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()); }