Ejemplo n.º 1
0
        public static byte[] Serialize(RFIDData d)
        {
            if (d == null)
            {
                return(null);
            }
            var data      = new byte[DataLength];
            var guidBytes = d.Guid.ToByteArray();

            for (int i = 0; i < guidBytes.Length; i++)
            {
                data[i] = guidBytes[i];
            }
            data[16] = (byte)d.LOGO;
            data[17] = (byte)d.Obligate;
            data[18] = (byte)d.Workpiece;
            data[19] = (byte)d.Clean;
            data[20] = (byte)d.Gauge;
            data[21] = (byte)d.Assemble;
            for (int i = 0; i < d.ProcessDataList.Count; i++)
            {
                data[i * 2 + 22] = (byte)d.ProcessDataList[i].Site;
                data[i * 2 + 23] = (byte)d.ProcessDataList[i].Result;
            }
            return(data);
        }
Ejemplo n.º 2
0
        public static RFIDData Deserialize(byte[] data)
        {
            if (data == null || data.Length != DataLength)
            {
                return(null);
            }
            var r = new RFIDData(new Guid(data.Take(16).ToArray()));

            r.LOGO      = (EnumLOGO)data[16];
            r.Obligate  = (EnumObligate)data[17];
            r.Workpiece = (EnumWorkpiece)data[18];
            r.Clean     = (EnumClean)data[19];
            r.Gauge     = (EnumGauge)data[20];
            r.Assemble  = (EnumAssemble)data[21];
            for (int i = 0; i < data.Length; i += 2)
            {
                if (data[i + 22] == 0)
                {
                    break;
                }
                else
                {
                    var processData = new ProcessData((EnumPSite)data[i + 22], (EnumPResult)data[i + 23]);
                    r.ProcessDataList.Add(processData);
                }
            }
            return(r);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取默认RFID数据
        /// </summary>
        /// <param name="guid">工件编号</param>
        /// <param name="workpiece">工件类型</param>
        /// <param name="clean">清洗</param>
        /// <param name="gauge">检测</param>
        /// <param name="assemble">装配</param>
        /// <returns>RFIDData对象</returns>
        public static RFIDData GetDefaut(Guid guid, EnumWorkpiece workpiece, EnumClean clean = EnumClean.Wanted, EnumGauge gauge = EnumGauge.Wanted, EnumAssemble assemble = EnumAssemble.Wanted)
        {
            var data = new RFIDData(guid);

            data.Workpiece = workpiece;
            data.Clean     = clean;
            data.Gauge     = gauge;
            data.Assemble  = assemble;
            switch (workpiece)
            {
            case EnumWorkpiece.A:
                data.ProcessDataList.Add(new ProcessData(EnumPSite.S1));
                data.ProcessDataList.Add(new ProcessData(EnumPSite.S3));
                data.ProcessDataList.Add(new ProcessData(EnumPSite.S2));
                break;

            case EnumWorkpiece.B:
                data.ProcessDataList.Add(new ProcessData(EnumPSite.S1));
                data.ProcessDataList.Add(new ProcessData(EnumPSite.S3));
                break;

            case EnumWorkpiece.C:
                data.ProcessDataList.Add(new ProcessData(EnumPSite.S1));
                data.ProcessDataList.Add(new ProcessData(EnumPSite.S3));
                break;

            case EnumWorkpiece.D:
                data.ProcessDataList.Add(new ProcessData(EnumPSite.S4));
                break;

            case EnumWorkpiece.E:
                break;

            default:
                break;
            }
            return(data);
        }
Ejemplo n.º 4
0
 public byte[] Serialize()
 {
     return(RFIDData.Serialize(this));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 初始化RFID信息
        /// </summary>
        /// <param name="workpiece">工件类型</param>
        /// <returns>是否成功</returns>
        public bool Init(Guid guid, EnumWorkpiece workpiece)
        {
            var data = RFIDData.GetDefaut(guid, workpiece).Serialize();

            return(WriteBytes(data));
        }
Ejemplo n.º 6
0
 public RFIDData Read()
 {
     return(RFIDData.Deserialize(ReadBytes()));
 }
Ejemplo n.º 7
0
 public bool Write(RFIDData data)
 {
     return(WriteBytes(data.Serialize()));
 }