/// <summary> /// 摆盘入库 /// </summary> /// <param name="vGoodsNu">物料编号</param> /// <param name="vDiskNu">胶盘编号</param> /// <returns></returns> public IMsg MsgPlatingInDb(string vGoodsNu, string vDiskNu) { var obj = new MsgPlatingInDb(FrmMsg); //命令格式:HEAD+版本 + BR +工位+ 物料编号+胶盘编号+流水号+END //例如: 工位=1 ;物料编号为 A12345; 胶盘编号:X1111 // 侧发送命令帧→ HEAD+10 + RK+1+ A12345 +X1111+1102310+END obj.DaType = "BR"; obj.LotNu = obj.WorkStation.ToString() + DateTime.Now.ToString("HHmmss"); obj.GoodsNu = string.IsNullOrEmpty(vGoodsNu) ? "NULL" : vGoodsNu?.Trim(); obj.DiskNu = string.IsNullOrEmpty(vDiskNu) ? "NULL" : vDiskNu?.Trim(); obj.strFrm = string.Format("HEAD+{0}+{1}+{2}+{3}+{4}+{5}+END", obj.Ver, obj.DaType, obj.WorkStation, obj.GoodsNu, obj.DiskNu, obj.LotNu); obj.Buffer = Encoding.Default.GetBytes(obj.strFrm); return(obj); }
/// <summary> /// 帧解析 /// </summary> /// <param name="vFrm">帧数组</param> /// <param name="vIP">远程IP</param> /// <param name="vPort">远程端口</param> /// <returns>返回</returns> public IMsg FrmAnaly(byte[] vFrm, string vIP = "0.0.0.0", int vPort = 0) { if (vFrm == null || vFrm.Length <= 0) { return(new MsgError(MsgEnu.RecvNull)); } string recv = Encoding.Default.GetString(vFrm); string[] split = recv.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries); if (split == null || split.Length < MsgConst.cMinLen) { return(new MsgError(MsgEnu.StringNull)); } int last = split.Length - 1; if (split[0] != MsgConst.cHead || split[last] != MsgConst.cEnd) { return(new MsgError(MsgEnu.ErrHeadEnd)); } if (split[1] != MsgConst.cVersion) { return(new MsgError(MsgEnu.VerErr)); } var msgInfo = FrmMsg; if (vPort > 0) { msgInfo = new MsgBase(FrmMsg, vIP, vPort); } switch (split[2]) { case "RK": { //命令格式:HEAD+版本 + RK +工位+ 物料编号+胶盘编号+流水号+END if (split.Length < 8) { return(new MsgError(MsgEnu.ErrRKLen)); } var msg = new MsgInDb(msgInfo); msg.strFrm = recv; int tmp = 0; bool flag = int.TryParse(split[3], out tmp); if (!flag) { return(msg.SetResVal(MsgEnu.ErrWorkStation)); } msg.WorkStation = tmp; msg.GoodsNu = split[4] != "NULL" ? split[4] : string.Empty; msg.DiskNu = split[5] != "NULL" ? split[5] : string.Empty; msg.LotNu = split[6] != "NULL" ? split[6] : string.Empty; return(msg); } case "CK": { //命令格式:HEAD+版本 + CK +工位+ 物料编号+胶盘编号+流水号+END if (split.Length < 8) { return(new MsgError(MsgEnu.ErrCKLen)); } var msg = new MsgOutDb(msgInfo); msg.strFrm = recv; int tmp = 0; bool flag = int.TryParse(split[3], out tmp); if (!flag) { return(msg.SetResVal(MsgEnu.ErrWorkStation)); } msg.WorkStation = tmp; msg.GoodsNu = split[4] != "NULL" ? split[4] : string.Empty; msg.DiskNu = split[5] != "NULL" ? split[5] : string.Empty; msg.LotNu = split[6] != "NULL" ? split[6] : string.Empty; return(msg); } case "YD": { //回应命令帧格式:HEAD+ 版本 + YD+ 操作编码+胶盘编号+流水号+END if (split.Length < 7) { return(new MsgError(MsgEnu.ErrYDLen)); } var msg = new MsgBack(msgInfo); msg.strFrm = recv; int tmp = 0; bool flag = int.TryParse(split[3], out tmp); if (!flag) { return(msg.SetResVal(MsgEnu.ErrOpCode)); } msg.RetCode = (MsgEnu)tmp; msg.DiskNu = split[4] != "NULL" ? split[5] : string.Empty; msg.LotNu = split[5]; return(msg); } case "BC": { //1)摆盘出库 //命令格式:HEAD +版本+ BC +工位+盘类型+盘数量 //+ 物料编号+胶盘编号+流水号+END var msg = new MsgPlatingOutDb(msgInfo); msg.strFrm = recv; if (split.Length < 10) { return(msg.SetResVal(MsgEnu.ErrBCLen)); } int tmp = 0; bool flag = int.TryParse(split[3], out tmp); if (!flag) { return(msg.SetResVal(MsgEnu.ErrWorkStation)); } msg.WorkStation = tmp; flag = int.TryParse(split[4], out tmp); if (!flag) { return(msg.SetResVal(MsgEnu.ErrDiskTypeNo)); } msg.DiskType = tmp; flag = int.TryParse(split[5], out tmp); if (!flag) { return(msg.SetResVal(MsgEnu.ErrWorkStation)); } if (tmp < 0) { return(msg.SetResVal(MsgEnu.ErrDiskCountLeZero)); } msg.DiskCount = tmp; msg.GoodsNu = split[6] != "NULL" ? split[6] : string.Empty; msg.DiskNu = split[7] != "NULL" ? split[7] : string.Empty; msg.LotNu = split[8] != "NULL" ? split[8] : string.Empty; return(msg); } case "BR": { //2)摆盘入库 //命令格式:HEAD + 版本 + BR + 工位 + 物料编号 + 胶盘编号 + 流水号 + END if (split.Length < 8) { return(new MsgError(MsgEnu.ErrBRLen)); } var msg = new MsgPlatingInDb(msgInfo); msg.strFrm = recv; int tmp = 0; bool flag = int.TryParse(split[3], out tmp); if (!flag) { msg.SetResVal(MsgEnu.ErrWorkStation); } msg.WorkStation = tmp; msg.GoodsNu = split[4] != "NULL" ? split[4] : string.Empty; msg.DiskNu = split[5] != "NULL" ? split[5] : string.Empty; msg.LotNu = split[6] != "NULL" ? split[6] : string.Empty; return(msg); } } return(new MsgError(MsgEnu.ErrCmdNo)); }