public void ReadConfig() { SecurityHelper helper = new SecurityHelper(); string strPath = ServerSystemInfo.strPath; try { string key = helper.ReadFile("切换板", "SerialCom", strPath); int num = int.Parse(helper.ReadFile("切换板", "BaudRate", strPath)); string str3 = helper.ReadFile("设故板", "SerialCom", strPath); int num2 = int.Parse(helper.ReadFile("设故板", "BaudRate", strPath)); string str4 = helper.ReadFile("实时数据", "SerialCom", strPath); int num3 = int.Parse(helper.ReadFile("实时数据", "BaudRate", strPath)); SerialComConfig config = new SerialComConfig(1, new KeyValuePair <string, int>(key, num)); config.SerialComConfigChange += new SerialComConfigDelegate(this.SerialComConfigChange_SerialComConfigChange); SerialComConfig config2 = new SerialComConfig(3, new KeyValuePair <string, int>(str3, num2)); config2.SerialComConfigChange += new SerialComConfigDelegate(this.SerialComConfigChange_SerialComConfigChange); SerialComConfig config3 = new SerialComConfig(2, new KeyValuePair <string, int>(str4, num3)); config3.SerialComConfigChange += new SerialComConfigDelegate(this.SerialComConfigChange_SerialComConfigChange); ServerSystemInfo.SerialComInfoList = new List <SerialComConfig> { config, config2, config3 }; } catch { MessageBox.Show("读取配置文件错误"); } }
private void SerialComConfigChange_SerialComConfigChange(int type, object args) { Func <SerialComConfig, bool> predicate = null; KeyValuePair <string, int> keyvalue = (KeyValuePair <string, int>)args; if (type > 0) { if (predicate == null) { predicate = t => t.SerialComInfo.Key == keyvalue.Key; } SerialComConfig config = ServerSystemInfo.SerialComInfoList.Where <SerialComConfig>(predicate).FirstOrDefault <SerialComConfig>(); if (config != null) { switch (config.SerialComType) { case 1: closeMyCom(this.SwitchModuleSM); break; case 2: closeMyCom(SysManager._comm); break; case 3: closeMyCom(this.GetRTDataSM); break; } } } switch (type) { case -3: case 3: closeMyCom(this.GetRTDataSM); this.GetRTDataSM = new SysManager(keyvalue.Key, keyvalue.Value); break; case -2: case 2: closeMyCom(SysManager._comm); SysManager._comm = new Communication(keyvalue.Key, keyvalue.Value); return; case -1: case 1: closeMyCom(this.SwitchModuleSM); this.SwitchModuleSM = new SysManager(keyvalue.Key, keyvalue.Value); return; case 0: break; default: return; } }
private void barLargeButtonItem3_ItemClick(object sender, ItemClickEventArgs e) { if (((this.SwitchModuleSM == null) && (ServerSystemInfo.SerialComInfoList != null)) && (ServerSystemInfo.SerialComInfoList.Count != 0)) { SerialComConfig config = (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 1 select t).FirstOrDefault <SerialComConfig>(); if (config != null) { this.SwitchModuleSM = new SysManager(config.SerialComInfo.Key, config.SerialComInfo.Value); } } if (ServerSystemInfo.ModuleId == ServerSystemInfo.SoftModuleId) { CMessageInfo.ShowMessage("该模块已连接!", "模块切换", 1); if ((this.client != null) && (this.buffer != null)) { PaidComm.SendBack(this.client, this.buffer, 0); } } else if (CheckInfo.PcCheckState) { CMessageInfo.ShowMessage("学生机考核进行中,无法操作!", "模块切换", 1); } else if (CheckInfo.PaidCheckState) { CMessageInfo.ShowMessage("平板用户考核进行中,无法操作!", "模块切换", 1); } else { string msg = string.Empty; if (this.SwitchModuleSM.ConnectModule(int.Parse(this._dr["Id"].ToString()))) { ServerSystemInfo.ModuleName = this._dr["ModuleName"].ToString(); ServerSystemInfo.ModuleIdBuff = int.Parse(this._dr["Id"].ToString()); CMessageInfo.ShowMessage("模块切换成功!", "模块切换", 1); if ((this.client != null) && (this.buffer != null)) { PaidComm.SendBack(this.client, this.buffer, 0); } SysManager.ModuleId = ServerSystemInfo.ModuleId; SysManager.ResetFaultPoint(); msg = string.Format("切换模块[{0}]成功", ServerSystemInfo.ModuleName); } else { CMessageInfo.ShowMessage("模块连接失败,请重试!", "模块切换", 1); msg = string.Format("切换模块[{0}]失败", this._dr["ModuleName"].ToString()); if ((this.client != null) && (this.buffer != null)) { PaidComm.SendBack(this.client, this.buffer, 1); } } this.da.WriteLog(LoginInfo.UserName, msg); } }
private void ConnectOBD() { if (((this.GetRTDataSM == null) && (ServerSystemInfo.SerialComInfoList != null)) && (ServerSystemInfo.SerialComInfoList.Count != 0)) { SerialComConfig config = (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 3 select t).FirstOrDefault <SerialComConfig>(); if (config != null) { this.GetRTDataSM = new SysManager(config.SerialComInfo.Key, config.SerialComInfo.Value); if (!this.GetRTDataSM.comm._serialPort.IsOpen) { return; } } } this._RTthread = new Thread(new ThreadStart(delegate { MethodInvoker method = null; if (this.GetRTDataSM.ConnectOBD()) { this.HasECUSelect = true; MessageBox.Show("连接通道打开成功,开始获取实时数据"); if (this.simpleButton1.InvokeRequired) { if (method == null) { method = delegate { this.simpleButton1.Tag = "开启状态"; this.simpleButton1.Appearance.BackColor = Color.Red; this.simpleButton1.Text = "关闭实时数据通道"; this.IsRTDataRun = true; }; } this.simpleButton1.Invoke(method); } while (true) { while ((this.GetRTDataSM != null) && this.IsRTDataRun) { RTData allRTData = this.GetRTDataSM.GetAllRTData(); if (allRTData != null) { this.barStaticItem5.Caption = allRTData.FDJLQYWD; this.barStaticItem6.Caption = allRTData.FDJZS; } Thread.Sleep(0x3e8); } Thread.CurrentThread.Suspend(); } } MessageBox.Show("连接通道打开失败,请检查串口配置"); })); this._RTthread.IsBackground = true; this._RTthread.Start(); }
private static void LoadSerialComInfo() { lock (LoadSerialComInfoLock) { if (((_comm == null) && (ServerSystemInfo.SerialComInfoList != null)) && (ServerSystemInfo.SerialComInfoList.Count != 0)) { SerialComConfig config = (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 3 select t).FirstOrDefault <SerialComConfig>(); if (config != null) { _comm = new Communication(config.SerialComInfo.Key, config.SerialComInfo.Value); } } } }
private void SerialComConfigChange_SerialComConfigChange(int type, object args) { KeyValuePair <string, int> keyvalue = (KeyValuePair <string, int>)args; if (type > 0) { SerialComConfig serialComConfig = (from t in ClientSystemInfo.SerialComInfoList where t.SerialComInfo.Key == keyvalue.Key select t).FirstOrDefault <SerialComConfig>(); if (serialComConfig != null) { switch (serialComConfig.SerialComType) { case 1: this.closeMyCom(this.comm1); break; case 2: this.closeMyCom(this.comm2); break; } } } switch (type) { case -2: case 2: this.closeMyCom(this.comm2); this.comm2 = new Communication(keyvalue.Key, keyvalue.Value); break; case -1: case 1: this.closeMyCom(this.comm1); this.comm1 = new Communication(keyvalue.Key, keyvalue.Value); return; case 0: break; default: return; } }
public void ReadConfig() { SecurityHelper securityHelper = new SecurityHelper(); string strPath = ClientSystemInfo.strPath; try { string key = securityHelper.ReadFile("检测板", "SerialCom", strPath); int value = int.Parse(securityHelper.ReadFile("检测板", "BaudRate", strPath)); SerialComConfig serialComConfig = new SerialComConfig(1, new KeyValuePair <string, int>(key, value)); serialComConfig.SerialComConfigChange += new SerialComConfigDelegate(this.SerialComConfigChange_SerialComConfigChange); ClientSystemInfo.SerialComInfoList = new List <SerialComConfig> { serialComConfig }; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void simpleButton2_Click(object sender, EventArgs e) { if (this.comm2 == null && ClientSystemInfo.SerialComInfoList != null && ClientSystemInfo.SerialComInfoList.Count != 0) { SerialComConfig serialComConfig = (from t in ClientSystemInfo.SerialComInfoList where t.SerialComType == 2 select t).FirstOrDefault <SerialComConfig>(); if (serialComConfig != null) { this.comm2 = new Communication(serialComConfig.SerialComInfo.Key, serialComConfig.SerialComInfo.Value); } } if (this.comm2.openPort()) { this.simpleButton5.Enabled = true; MessageBox.Show("串口打开成功"); this.simpleButton2.Enabled = false; this.timer2.Enabled = true; return; } MessageBox.Show("串口打开失败"); }
private void simpleButton3_Click(object sender, EventArgs e) { if (this.comm1 == null && ClientSystemInfo.SerialComInfoList != null && ClientSystemInfo.SerialComInfoList.Count != 0) { SerialComConfig serialComConfig = (from t in ClientSystemInfo.SerialComInfoList where t.SerialComType == 1 select t).FirstOrDefault <SerialComConfig>(); if (serialComConfig != null) { this.comm1 = new Communication(serialComConfig.SerialComInfo.Key, serialComConfig.SerialComInfo.Value); this.comm1.DataRecived += new Communication.MyDataRecivedDelegate(this.comm_DataRecived); } } if (this.comm1.openPort()) { this.simpleButton4.Enabled = true; MessageBox.Show("串口打开成功"); this.simpleButton3.Enabled = false; return; } MessageBox.Show("串口打开失败"); }
private void FrmSetting_Load(object sender, EventArgs e) { string[] comList = this.GetComList(); this.comboBoxEdit2.Properties.Items.AddRange(comList); this.comboBoxEdit4.Properties.Items.AddRange(comList); SerialComConfig serialComConfig = null; SerialComConfig serialComConfig2 = null; if (ClientSystemInfo.SerialComInfoList != null && ClientSystemInfo.SerialComInfoList.Count != 0) { serialComConfig = (from t in ClientSystemInfo.SerialComInfoList where t.SerialComType == 1 select t).FirstOrDefault <SerialComConfig>(); serialComConfig2 = (from t in ClientSystemInfo.SerialComInfoList where t.SerialComType == 2 select t).FirstOrDefault <SerialComConfig>(); } if (serialComConfig != null) { this.comboBoxEdit2.SelectedIndex = this.comboBoxEdit2.Properties.Items.IndexOf(serialComConfig.SerialComInfo.Key); this.comboBoxEdit1.SelectedIndex = this.comboBoxEdit1.Properties.Items.IndexOf(serialComConfig.SerialComInfo.Value.ToString()); } else { this.comboBoxEdit2.SelectedItem = "COM1"; this.comboBoxEdit1.SelectedItem = "19200"; } if (serialComConfig2 != null) { this.comboBoxEdit4.SelectedIndex = this.comboBoxEdit4.Properties.Items.IndexOf(serialComConfig2.SerialComInfo.Key); this.comboBoxEdit3.SelectedIndex = this.comboBoxEdit3.Properties.Items.IndexOf(serialComConfig2.SerialComInfo.Value.ToString()); return; } this.comboBoxEdit4.SelectedItem = "COM1"; this.comboBoxEdit3.SelectedItem = "19200"; }
private void FrmSetting_Load(object sender, EventArgs e) { this.labelControl3.Text = (ServerSystemInfo.SysPattern == 0) ? "自由训练模式" : "实训考核模式"; this.textEdit1.Text = this.GetIpv4().FirstOrDefault <string>(); this.textEdit1.Enabled = false; if ((this.Test != null) && (this.Test.Rows.Count != 0)) { this.textEdit2.Text = this.Test.Rows[0]["Port1"].ToString(); this.textEdit5.Text = this.Test.Rows[0]["Port2"].ToString(); } string[] comList = this.GetComList(); this.comboBoxEdit1.SelectedIndex = ServerSystemInfo.SysPattern; this.comboBoxEdit2.Properties.Items.AddRange(comList); this.comboBoxEdit5.Properties.Items.AddRange(comList); this.comboBoxEdit7.Properties.Items.AddRange(comList); SerialComConfig config = null; SerialComConfig config2 = null; SerialComConfig config3 = null; if ((ServerSystemInfo.SerialComInfoList != null) && (ServerSystemInfo.SerialComInfoList.Count != 0)) { config = (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 1 select t).FirstOrDefault <SerialComConfig>(); config2 = (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 2 select t).FirstOrDefault <SerialComConfig>(); config3 = (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 3 select t).FirstOrDefault <SerialComConfig>(); } if (config != null) { this.comboBoxEdit2.SelectedIndex = this.comboBoxEdit2.Properties.Items.IndexOf(config.SerialComInfo.Key); this.comboBoxEdit3.SelectedIndex = this.comboBoxEdit3.Properties.Items.IndexOf(config.SerialComInfo.Value.ToString()); } else { this.comboBoxEdit2.SelectedItem = "COM1"; this.comboBoxEdit3.SelectedItem = "19200"; } if (config2 != null) { this.comboBoxEdit5.SelectedIndex = this.comboBoxEdit5.Properties.Items.IndexOf(config2.SerialComInfo.Key); this.comboBoxEdit4.SelectedIndex = this.comboBoxEdit4.Properties.Items.IndexOf(config2.SerialComInfo.Value.ToString()); } else { this.comboBoxEdit5.SelectedItem = "COM1"; this.comboBoxEdit4.SelectedItem = "19200"; } if (config3 != null) { this.comboBoxEdit7.SelectedIndex = this.comboBoxEdit7.Properties.Items.IndexOf(config3.SerialComInfo.Key); this.comboBoxEdit6.SelectedIndex = this.comboBoxEdit6.Properties.Items.IndexOf(config3.SerialComInfo.Value.ToString()); } else { this.comboBoxEdit7.SelectedItem = "COM1"; this.comboBoxEdit6.SelectedItem = "19200"; } }
private void simpleButton1_Click(object sender, EventArgs e) { try { string str = this.comboBoxEdit2.SelectedItem.ToString(); int num = int.Parse(this.comboBoxEdit3.SelectedItem.ToString().Trim()); string str2 = this.comboBoxEdit5.SelectedItem.ToString(); int num2 = int.Parse(this.comboBoxEdit4.SelectedItem.ToString().Trim()); string str3 = this.comboBoxEdit7.SelectedItem.ToString(); int num3 = int.Parse(this.comboBoxEdit6.SelectedItem.ToString().Trim()); if (((str == str2) || (str2 == str3)) || (str == str3)) { MessageBox.Show("请选择正确的串口"); } else { if (this._isRTDataRun) { SerialComConfig config = (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 3 select t).FirstOrDefault <SerialComConfig>(); if ((config != null) && ((config.SerialComInfo.Key != str3) || (config.SerialComInfo.Value != num3))) { MessageBox.Show("实时数据正在获取中,不能更改相应的串口通信配置"); return; } } if (CheckInfo.PcCheckState && (this.comboBoxEdit1.SelectedIndex == 1)) { MessageBox.Show("考核过程中不能切换为自由训练模式"); } else { string str4 = this.textEdit1.Text.Trim(); string str5 = this.textEdit3.Text.Trim(); int num4 = Convert.ToInt32(this.textEdit2.Text.Trim()); int num5 = Convert.ToInt32(this.textEdit5.Text.Trim()); ServerSystemInfo.SysPatternBuff = this.comboBoxEdit1.SelectedIndex; string sql = null; if ((this.Test != null) && (this.Test.Rows.Count != 0)) { sql = string.Concat(new object[] { "update serverinfo set ip='", str4, "',port1=", num4, ",port2=", num5 }); if (!string.IsNullOrWhiteSpace(str5)) { sql = sql + ",shareaddress='" + str5 + "'"; } sql = sql + " where id=1"; } else { sql = string.Concat(new object[] { "insert into serverinfo values('", str4, "',", num4, ",", num5, "," }); if (!string.IsNullOrWhiteSpace(str5)) { sql = sql + "'" + str5 + "',"; } else { sql = sql + "null,"; } sql = sql + "null)"; } if (this.da.SqlCommand(sql)) { SecurityHelper helper = new SecurityHelper(); string strPath = ServerSystemInfo.strPath; helper.WriteFile("切换板", "SerialCom", str, strPath); helper.WriteFile("切换板", "BaudRate", num.ToString(), strPath); helper.WriteFile("设故板", "SerialCom", str2, strPath); helper.WriteFile("设故板", "BaudRate", num2.ToString(), strPath); helper.WriteFile("实时数据", "SerialCom", str3, strPath); helper.WriteFile("实时数据", "BaudRate", num3.ToString(), strPath); if ((ServerSystemInfo.SerialComInfoList != null) && (ServerSystemInfo.SerialComInfoList.Count != 0)) { KeyValuePair <string, int> pair = new KeyValuePair <string, int>(str, num); (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 1 select t).FirstOrDefault <SerialComConfig>().NewSerialComInfo = pair; KeyValuePair <string, int> pair2 = new KeyValuePair <string, int>(str2, num2); (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 2 select t).FirstOrDefault <SerialComConfig>().NewSerialComInfo = pair2; KeyValuePair <string, int> pair3 = new KeyValuePair <string, int>(str3, num3); (from t in ServerSystemInfo.SerialComInfoList where t.SerialComType == 3 select t).FirstOrDefault <SerialComConfig>().NewSerialComInfo = pair3; } MessageBox.Show("信息保存成功!"); if ((this.textEdit2.Text.Trim() != this.Test.Rows[0]["Port1"].ToString()) || (this.textEdit5.Text.Trim() != this.Test.Rows[0]["Port2"].ToString())) { MessageBox.Show("通信端口已更改,需重启服务器才能生效"); } base.Close(); } } } } catch { MessageBox.Show("请输入合法参数"); } }