private void SocPlc_NewMessageEvent(Socket socket, byte[] Message) { try { Dispatcher.BeginInvoke(new Action(() => { var model = ProtocolHelper.CreateProtocol(this.txbTitle.Text); string data = socPlc.ByteConvertToString(Message); SimpleLogHelper.Instance.WriteLog(LogType.Info, this.txbTitle.Text + ": " + data); if (data.Length < 494) { return; } if (model.AnalysisData(data.Substring(18, data.Length - 18))) { this.txtLeiJiShangDianShiJian.Text = model.PowerTime; this.txtLeiJiShouQuanShiJian.Text = model.AuthorizeTimer; this.txtLeiJiGuZhangShiJian.Text = model.ErrorTimer; this.txtLeiJiJianXiuShiJian.Text = model.CheckTimer; this.txtLeiJiDaiJiShiJian.Text = model.WaitTimer; this.txtLeiJiYunXingShiJian.Text = model.RunTimer; this.txtJiePaiZhouQiShiJian.Text = model.CycleTimer; this.txtLeiJiChanLiang.Text = model.SumCount; this.txtDangBanChanLiang.Text = model.ClassCount; SetConnectState(imgAutoRun, model.AutoRun); SetConnectState(imgCheckState, model.CheckState); SetConnectState(imgErrorState, model.ErrorState); SetConnectState(imgWaitState, model.WaitState); } ChangColor(); //存储到数据库 if (sql.TestConn) { string sqlcommand = string.Format("INSERT INTO PlcData" + "(Name,PowerTimer,AuthorizeTimer,ErrorTimer,CheckTimer,WaitTimer," + "RunTimer,CycleTimer,SumCount,ClassCount) values ('{0}','{1}','{2}','{3}'," + "'{4}','{5}','{6}','{7}','{8}','{9}')", this.txbTitle.Text, model.PowerTime , model.AuthorizeTimer, model.ErrorTimer, model.CheckTimer, model.WaitTimer, model.RunTimer, model.CycleTimer, model.SumCount, model.ClassCount); sql.Execute(sqlcommand); } })); } catch (Exception ex) { SimpleLogHelper.Instance.WriteLog(LogType.Info, ex); } }