Пример #1
0
        public override byte[] PackRequest()
        {
            byte[] request = new byte[20];

            DNP3ReadCommandParameters commadnParam = (DNP3ReadCommandParameters)CommandParameters;

            CommandParameters.Length = 0x0d; //20 - 2*(2 CRC) - 2 Start - 1 len
            Buffer.BlockCopy(headerBuilder.Build(CommandParameters), 0, request, 0, 10);
            request[10] = commadnParam.TransportControl;
            request[11] = commadnParam.AplicationControl;
            request[12] = commadnParam.FunctionCode;
            Buffer.BlockCopy(BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short)commadnParam.ObjectTypeField)), 0, request, 13, 2);
            request[15] = commadnParam.Qualifier;
            request[16] = (byte)commadnParam.RangeField;
            request[17] = (byte)commadnParam.RangeField;
            ushort crc = 0;

            for (int i = 10; i < 18; i++)
            {
                CrcCalculator.computeCRC(request[i], ref crc);
            }
            crc = (ushort)(~crc);
            Buffer.BlockCopy(BitConverter.GetBytes(crc), 0, request, 18, 2);

            return(request);
        }
Пример #2
0
        public override byte[] PackRequest()
        {
            byte[] request = new byte[25];

            DNP3WriteCommandParameters commandParam = (DNP3WriteCommandParameters)CommandParameters;

            CommandParameters.Length = 18;
            Buffer.BlockCopy(headerBuilder.Build(CommandParameters), 0, request, 0, 10);
            request[10] = commandParam.TransportControl;
            request[11] = commandParam.AplicationControl;
            request[12] = commandParam.FunctionCode;
            Buffer.BlockCopy(BitConverter.GetBytes(IPAddress.HostToNetworkOrder((short)commandParam.ObjectTypeField)), 0, request, 13, 2);
            request[15] = commandParam.Qualifier;
            Buffer.BlockCopy(BitConverter.GetBytes(Convert.ToUInt16(commandParam.RangeField)), 0, request, 16, 2);
            Buffer.BlockCopy(BitConverter.GetBytes(Convert.ToUInt16(commandParam.Prefix)), 0, request, 18, 2);
            Buffer.BlockCopy(BitConverter.GetBytes(Convert.ToUInt16(commandParam.Value)), 0, request, 20, 2);
            request[22] = 0x00;

            ushort crc1 = 0;

            for (int i = 10; i < 23; i++)
            {
                CrcCalculator.computeCRC(request[i], ref crc1);
            }
            crc1 = (ushort)(~crc1);

            Buffer.BlockCopy(BitConverter.GetBytes(crc1), 0, request, 23, 2);

            return(request);
        }
Пример #3
0
        public override byte[] PackRequest()
        {
            byte[] message = new byte[15];

            DNP3ConfirmCommandParamters commandParam = (DNP3ConfirmCommandParamters)CommandParameters;

            CommandParameters.Length = 0x08;
            Buffer.BlockCopy(headerBuilder.Build(CommandParameters), 0, message, 0, 10);
            message[10] = commandParam.TransportControl;
            message[11] = commandParam.AplicationControl;
            message[12] = commandParam.FunctionCode;

            ushort crc = 0;

            for (int i = 10; i < 13; i++)
            {
                CrcCalculator.computeCRC(message[i], ref crc);
            }
            crc = (ushort)(~crc);

            Buffer.BlockCopy(BitConverter.GetBytes(crc), 0, message, 13, 2);

            return(message);
        }