Пример #1
0
        public Pdu(byte[] recievedPdu)
        {
            int Type = recievedPdu[1];

            pduHeaderLen = (Type == 2 || Type == 3) ? 12 : 10;

            byte[] array = new byte[pduHeaderLen];
            Array.Copy(recievedPdu, 0, array, 0, pduHeaderLen);
            header = EndianessMarshaler.BytesToStruct <PDUHeader>(array);

            Param = new List <byte>();
            array = new byte[header.plen];
            Array.Copy(recievedPdu, pduHeaderLen, array, 0, header.plen);
            Param.AddRange(array);

            Data        = new List <byte>();
            array       = new byte[header.dlen];
            header.dlen = (ushort)Math.Min(header.dlen, recievedPdu.Length - pduHeaderLen - header.plen);//for OLD PLC: recievedPdu.Length = 400, header.dlen = 448

            Array.Copy(recievedPdu, pduHeaderLen + header.plen, array, 0, header.dlen);
            Data.AddRange(array);


            UData = new List <byte>();
            initUData();
        }
        public Pdu(byte[] recievedPdu)
        {
            int Type = recievedPdu[1];

            pduHeaderLen = (Type == 2 || Type == 3) ? 12 : 10;

            byte[] array = new byte[pduHeaderLen];
            Array.Copy(recievedPdu, 0, array, 0, pduHeaderLen);
            header = EndianessMarshaler.BytesToStruct <PDUHeader>(array);

            Param = new List <byte>();
            array = new byte[header.plen];
            Array.Copy(recievedPdu, pduHeaderLen, array, 0, header.plen);
            Param.AddRange(array);

            Data  = new List <byte>();
            array = new byte[header.dlen];
            Array.Copy(recievedPdu, pduHeaderLen + header.plen, array, 0, header.dlen);
            Data.AddRange(array);

            UData = new List <byte>();
        }