Ejemplo n.º 1
0
        public byte[] GetBytes()
        {
            List <byte> header  = new List <byte>();
            List <byte> body    = new List <byte>();
            List <byte> arrData = new List <byte>();

            header.AddRange(Utils.GetBytes(CommConst.CMD_TDAT));
            header.AddRange(Utils.GetBytes(CommConst.WORK_CODE));
            header.AddRange(Utils.GetBytes(CommConst.CHIM_CODE));
            header.AddRange(BitConverter.GetBytes(Length));                // 전체길이
            header.AddRange(Utils.GetBytes(MeasureTime.ToString("yyMMddHHmm")));

            body.AddRange(BitConverter.GetBytes(Convert.ToUInt16(ListPreFc.Count)));
            foreach (Facility preFc in ListPreFc)
            {
                body.AddRange(preFc.GetBytes());
            }
            body.AddRange(BitConverter.GetBytes(Convert.ToUInt16(ListDisFc.Count)));
            foreach (Facility disFc in ListDisFc)
            {
                body.AddRange(disFc.GetBytes());
            }

            Length = header.Count + body.Count + 4;                     // Tailer 포함
            byte[] bCnt = BitConverter.GetBytes(Length);
            for (int i = 0; i < 4; i++)
            {
                header[i + 11] = bCnt[i];
            }

            // arrData Tailer에 chksum을 추가
            arrData.AddRange(header);
            arrData.AddRange(body);

            byte[] data = arrData.OfType <byte>().ToArray();

            Crc16Ccitt crc    = new Crc16Ccitt(InitialCrcValue.Zeros);
            int        chksum = crc.ComputeChecksum(data);

            arrData.AddRange(BitConverter.GetBytes(chksum));

            data = arrData.OfType <byte>().ToArray();

            return(data);
        }
Ejemplo n.º 2
0
        }                                                   // 오류 검증코드

        public bool SetBytes(byte[] data)
        {
            Cmd           = Utils.GetString(data, 0, 4);
            WorkPlaceCode = Utils.GetString(data, 4, 7);
            ChimneyCode   = Utils.GetString(data, 11, 4);
            Length        = Convert.ToInt32(Utils.GetString(data, 15, 4));
            StartDate     = DateTime.ParseExact(Utils.GetString(data, 19, 10), "yyMMddHHmm", null);
            EndDate       = DateTime.ParseExact(Utils.GetString(data, 29, 10), "yyMMddHHmm", null);
            UInt32 chksum = BitConverter.ToUInt32(data, 39);

            byte[]     chkData = new byte[data.Length - 4];
            Crc16Ccitt crc     = new Crc16Ccitt(InitialCrcValue.Zeros);

            if (chksum == crc.ComputeChecksum(chkData))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }