Exemple #1
0
        public static ReadCoils Create(byte slaveId, ushort startingAddress, ushort quantity)
        {
            ReadCoils request = new ReadCoils()
            {
                SlaveAddress    = slaveId,
                FunctionCode    = 1,
                StartingAddress = (ushort)(startingAddress),
                QuantityOfCoils = quantity,
                Protocol        = ProtocolType.RTU
            };

            byte[] encoded = request.Encode();
            return(ReadCoils.Decode(encoded));
        }
Exemple #2
0
        public static ReadCoils Create(byte unitId, ushort transactionId, ushort protocolId, ushort startingAddress, ushort quantity)
        {
            ReadCoils request = new ReadCoils()
            {
                Header = new MbapHeader()
                {
                    ProtocolId = protocolId, TransactionId = transactionId, UnitId = unitId
                },
                SlaveAddress    = unitId,
                FunctionCode    = 1,
                StartingAddress = (ushort)(startingAddress),
                QuantityOfCoils = quantity,
                Protocol        = ProtocolType.TCP
            };

            byte[] rtuEncoded = request.Encode();
            return(ReadCoils.Decode(rtuEncoded));
        }