public void Receive(DataPackage pkgData) { //收到版本信息【采集器→主机】 VersionItem verItem = new VersionItem(); byte[] dataBuffer = pkgData.PureData; using (MemoryStream ms = new MemoryStream(dataBuffer)) { using (BinaryReader br = new BinaryReader(ms)) { byte[] readBytes = br.ReadBytes(64); verItem.SN = Encoding.Default.GetString(readBytes).Trim(new char[]{'\0'}); //序列号 readBytes = br.ReadBytes(32); verItem.Ver = Encoding.Default.GetString(readBytes).Trim(new char[] { '\0' }); //firmware 版本 } } if (OnDataChanged != null) { DataHandlerEventArgs eventArgs = new DataHandlerEventArgs(); eventArgs.CMD_ID = pkgData.CtrlHead.CMD_ID; eventArgs.Value = verItem; OnDataChanged(this, eventArgs); } }
public void OnDataChanged(object sender, DataHandlerEventArgs e) { if (e.CurrentMode == RunMode.Monitor) { //更新客户端设备的状态信息 if (e.CMD_ID == HCCommand.QUERY_DEVICE_STATUS) { this.DeviceStatus = e.Value as DeviceStatusItem; Console.WriteLine(DateTime.Now); } else if (e.CMD_ID == HCCommand.QUERY_VERSION) { this.Version = e.Value as VersionItem; } } //数据存储 dataSaveMan.OnDataChanged(sender, e); //if (e.CurrentMode == RunMode.Monitor) //{ // Client client = sender as Client; // if (client != null && clientDict.ContainsKey(client.Name)) // { // clientDict[client.Name].Client_OnDataChanged(sender, e); // //更新客户端设备的状态信息 // if (e.CMD_ID == HCBase.HCCommand.QUERY_DEVICE_STATUS) // { // clientDict[client.Name].DeviceStatus = e.Value as DeviceStatusItem; // Console.WriteLine(DateTime.Now); // } // else if (e.CMD_ID == HCBase.HCCommand.QUERY_VERSION) // { // clientDict[client.Name].Version = e.Value as VersionItem; // } // } //} }