private void timer1_Tick(object sender, EventArgs e) { try { string queryString = string.Empty; string updatestring = string.Empty; queryString = "select SysId from SysArm where IsUse = '1' order by cast(SysId as int) asc"; DataTable dt = CommonlyFunctions.getSchedue(queryString); if (dt.Rows.Count > 0) { updatestring = "update SysOneLoad set LightingMin = (LightingMin + 1) where IsUse ='1' and LoadStatus='1' and ("; if (dt.Rows.Count == 1) { updatestring += " ArmId = '" + dt.Rows[0][0].ToString() + "')"; } else { for (int i = 0; i < dt.Rows.Count - 1; i++) { updatestring += " ArmId = '" + dt.Rows[i][0].ToString() + "' or "; } updatestring += " ArmId = '" + dt.Rows[dt.Rows.Count - 1][0].ToString() + "')"; } CommonlyFunctions.UpdateLightTime(updatestring); } } catch (Exception ex) { CommonlyFunctions.insertlog(Guid.NewGuid().ToString(), "-", "0", "更新OPIU点灯时间异常", DateTime.Now, "-", "-", ex.Message.ToString()); } }
private void PingOpiu() { while (true) { if (dt.Rows.Count > 0) { try { Ping ping = new Ping(); for (int i = 0; i < dt.Rows.Count; i++) { string ip = dt.Rows[i][1].ToString(); string armname = dt.Rows[i][2].ToString(); PingReply pingReply = ping.Send(ip); if (pingReply.Status == IPStatus.Success) { if (this.IsHandleCreated) { this.Invoke((MethodInvoker) delegate { this.barStaticItemStatus.Caption = armname + "信号正常"; this.barStaticItemStatus.ItemAppearance.Normal.ForeColor = Color.LawnGreen; }); } } else { if (this.IsHandleCreated) { this.Invoke((MethodInvoker) delegate { this.barStaticItemStatus.Caption = armname + "信号异常"; this.barStaticItemStatus.ItemAppearance.Normal.ForeColor = Color.Red; }); } } Thread.Sleep(3000); } } catch (Exception ex) { CommonlyFunctions.insertlog(Guid.NewGuid().ToString(), "-", "0", "匹配OPIU连接状态异常", DateTime.Now, "-", "-", ex.Message.ToString()); } } Thread.Sleep(10); } }
private void FormMain_Load(object sender, EventArgs e) { try { // 软件发布的时候放开这段被注释的代码 //if (Properties.Settings.Default.AutoRun) //{ // auto_run(); //} //else //{ // cancel_autorun(); //} //this.Text = Properties.Settings.Default.SoftwareTitle; // 空窗体 //dlgNull.Show(); //dlgNull.TopLevel = false; //dlgNull.Parent = panelMain; //dlgNull.Dock = DockStyle.Fill; //panelMain.Controls.Add(dlgNull); // 地图设定 dlgMapSetting.Show(); dlgMapSetting.TopLevel = false; dlgMapSetting.Parent = panelMain; dlgMapSetting.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgMapSetting); // 地图监视 dlgMapMonitor.Show(); dlgMapMonitor.TopLevel = false; dlgMapMonitor.Parent = panelMain; dlgMapMonitor.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgMapMonitor); // 系统日志 dlgSystemLog.Show(); dlgSystemLog.TopLevel = false; dlgSystemLog.Parent = panelMain; dlgSystemLog.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgSystemLog); // OPIU连接设定 dlgOpuiSetting.Show(); dlgOpuiSetting.TopLevel = false; dlgOpuiSetting.Parent = panelMain; dlgOpuiSetting.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgOpuiSetting); // 负载单个设定 dlgSingleSetting.Show(); dlgSingleSetting.TopLevel = false; dlgSingleSetting.Parent = panelMain; dlgSingleSetting.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgSingleSetting); // 负载群组设定 dlgGroupSetting.Show(); dlgGroupSetting.TopLevel = false; dlgGroupSetting.Parent = panelMain; dlgGroupSetting.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgGroupSetting); // 负载模式设定 dlgModelSetting.Show(); dlgModelSetting.TopLevel = false; dlgModelSetting.Parent = panelMain; dlgModelSetting.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgModelSetting); // 日程设定 dlgSchedueSetting.Show(); dlgSchedueSetting.TopLevel = false; dlgSchedueSetting.Parent = panelMain; dlgSchedueSetting.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgSchedueSetting); // 单个监视 dlgSingleMonitor.Show(); dlgSingleMonitor.TopLevel = false; dlgSingleMonitor.Parent = panelMain; dlgSingleMonitor.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgSingleMonitor); // 群组监视 dlgGroupMonitor.Show(); dlgGroupMonitor.TopLevel = false; dlgGroupMonitor.Parent = panelMain; dlgGroupMonitor.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgGroupMonitor); // 模式监视 dlgModelMonitor.Show(); dlgModelMonitor.TopLevel = false; dlgModelMonitor.Parent = panelMain; dlgModelMonitor.Dock = DockStyle.Fill; panelMain.Controls.Add(dlgModelMonitor); //// 程序刚启动的时候显示空白窗体 //panelMain.Controls.SetChildIndex(dlgNull, 0); panelMain.Controls.SetChildIndex(dlgMapMonitor, 0); this.Text = Properties.Settings.Default.SoftwareTitle + " — 地图监视"; if (CommonlyFunctions.LoginUserType == true) { ribbonSetting.Visible = true; ribbonControlMain.SelectedPage = ribbonMain; } else { ribbonSetting.Visible = false; ribbonControlMain.SelectedPage = ribbonMain; } startTime = DateTime.Now; timerRun.Enabled = true; timerRun.Start(); SplashScreenManager.CloseForm(); } catch (Exception ex) { CommonlyFunctions.insertlog(Guid.NewGuid().ToString(), "-", "0", "软件开启加载窗体异常", DateTime.Now, "-", "-", ex.Message.ToString()); } }
private void match(object i) { string armid = "-"; try { int[] status = new int[455]; //List<string> updatestrings = new List<string> { }; int row = (int)i; string ip = dt.Rows[row][1].ToString(); armid = dt.Rows[row][0].ToString(); ModbusTcpHelper mt = new ModbusTcpHelper(ip, 502); mt.Connect(); if (mt.GetConnect()) { byte[] return_bytes; mt.discover_loopandgroup(); while (true) { Thread.Sleep(10); if (mt.GetReturnData() != null) { return_bytes = mt.GetReturnData(); break; } } if (return_bytes.Length == 57) { byte[] loop_bytes = new byte[48]; for (int j = 0; j < loop_bytes.Length; j++) { if (j < 47) { loop_bytes[j] = return_bytes[j + 9]; string temp = Convert.ToString(loop_bytes[j], 2); char[] bin = stringtobin(temp); for (int k = 0; k < 8; k++) { status[8 * j + k] = Convert.ToInt32(bin[7 - k].ToString()); } } else if (j == 47) { loop_bytes[j] = return_bytes[j + 9]; string temp = Convert.ToString(loop_bytes[j], 2); char[] bin = stringtobin(temp); for (int k = 0; k < 7; k++) { status[8 * j + k] = Convert.ToInt32(bin[7 - k].ToString()); } } } } } mt.disconnect(); Thread.Sleep(50); ModbusTcpHelper mt_model = new ModbusTcpHelper(ip, 502); mt_model.Connect(); if (mt_model.GetConnect()) { byte[] return_bytes_model; mt_model.discover_model(); while (true) { Thread.Sleep(10); if (mt_model.GetReturnData() != null) { return_bytes_model = mt_model.GetReturnData(); break; } } if (return_bytes_model.Length == 18) { byte[] model_bytes = new byte[9]; for (int j = 0; j < model_bytes.Length; j++) { model_bytes[j] = return_bytes_model[j + 9]; string temp = Convert.ToString(model_bytes[j], 2); char[] bin = stringtobin(temp); for (int k = 0; k < 8; k++) { status[8 * j + k + 383] = Convert.ToInt32(bin[7 - k].ToString()); } } } } CommonlyFunctions.ExecuteSqlTran(armid, status); } catch (Exception ex) { CommonlyFunctions.insertlog(Guid.NewGuid().ToString(), armid, "0", "匹配OPIU寄存器状态异常", DateTime.Now, "-", "-", ex.Message.ToString()); } }