private void updateUI() { try { List <Node> nodeList = NodeMgr.getNodeList(); for (int index = 0; index < nodeList.Count; index++) { this.dataGridView1.Rows[index].Cells[0].Value = nodeList[index]._id; this.dataGridView1.Rows[index].Cells[1].Value = nodeList[index]._name; this.dataGridView1.Rows[index].Cells[2].Value = nodeList[index]._port; this.dataGridView1.Rows[index].Cells[3].Value = nodeList[index]._typeStr; this.dataGridView1.Rows[index].Cells[4].Value = nodeList[index]._status; if (nodeList[index]._isRunning == true) { this.dataGridView1.Rows[index].Cells[4].Style.BackColor = Color.DeepSkyBlue; } else { this.dataGridView1.Rows[index].Cells[4].Style.BackColor = Color.White; } } } catch { } }
private void readConfigFile() { if (MAppConfig.InitFromFile()) { string defaultCfgFile = MAppConfig.getValueByName("defaultCfgFile"); string defaultPLCCfgFile = MAppConfig.getValueByName("defaultPLCCfgFile"); string configDirStr = MAppConfig.getValueByName("defaultCfgDir"); string fileName = configDirStr + "/" + defaultCfgFile; //PLC服务器配置 string plcFileName = configDirStr + "/" + defaultPLCCfgFile; if (!String.IsNullOrEmpty(fileName)) { if (!NodeMgr.init(fileName))// { MessageBox.Show(fileName + "模型解析失败!检查配置文件", "出错了", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (!String.IsNullOrEmpty(plcFileName)) { if (!Modbus.PLCNodeMgr.init(plcFileName))// { MessageBox.Show(plcFileName + " PLC服务器配置解析失败!检查配置文件", "出错了", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void button4_Click(object sender, EventArgs e) { //JoinStockServer(); for (int i = 0; i < 10; i++) { NodeMgr.TestServer(); } }
private void ServerMainForm_FormClosing(object sender, FormClosingEventArgs e) { DialogResult result = MessageBox.Show("是否要退出程序?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.Cancel) { e.Cancel = true; return; } NodeMgr.stopAll(); }
private void initUI() { dataGridView1.Rows.Clear(); List <Node> nodeList = NodeMgr.getNodeList(); foreach (Node node in nodeList) { int index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = node._id; this.dataGridView1.Rows[index].Cells[1].Value = node._name; this.dataGridView1.Rows[index].Cells[2].Value = node._port; this.dataGridView1.Rows[index].Cells[4].Value = node._status; } }
private void button1_Click(object sender, EventArgs e) { try { if (dataGridView1.SelectedRows.Count <= 0) { return; } foreach (DataGridViewRow Row in dataGridView1.SelectedRows) { string selectIdStr = Row.Cells[0].Value.ToString();//查找第0列 int id = int.Parse(selectIdStr); NodeMgr.stopNode(id); } } catch (Exception ex) { } }
private void button_stop_Click(object sender, EventArgs e) { NodeMgr.stopAll(); }