/// <summary> /// 客户端返回消息解码 /// </summary> /// <param name="buff"></param> /// <returns></returns> private DeviceMaterial DecodeData(byte[] buff) { DeviceMaterial info = new DeviceMaterial(); byte[] tempData = buff; //机器码 int locIdx = 2; info.MachineId = ConvertHelper.BytesToInt16(tempData, 0, true); //施工单编码 int tempLen = tempData[locIdx++]; byte[] scheduleByte = new byte[tempLen]; Array.Copy(tempData, locIdx, scheduleByte, 0, tempLen); info.ScheduleNumber = Encoding.ASCII.GetString(scheduleByte); return(info); }
public byte[] HandlerClientData(byte[] buff) { byte[] buffResp = { 1 }; DbTableDbContext db = new DbTableDbContext(); try { DeviceMaterial outInfo = this.DecodeData(buff); Machines machine = db.Machines.Find(outInfo.MachineId); Schedules schedule = db.Schedules.FirstOrDefault(item => item.Number == outInfo.ScheduleNumber); MachineCallMaterial innerInfo = this.exchangeData(machine, schedule); //记录原始数据 db.MachineCallMaterial.Add(innerInfo); db.SaveChanges(); buffResp[0] = 0; } catch { } return(buffResp); }