Ejemplo n.º 1
0
        public static Message CreateReadCoilStatusCommand(SlaveAddress slaveAddress, CoilAddress firstCoil, ushort numberOfCoils)
        {
            var data = new List <byte>();

            WriteSlaveAddress(data, slaveAddress);
            WriteFunctionCode(data, FunctionCode.ReadCoilStatus);
            WriteCoilAddress(data, firstCoil);
            WriteBigEndianUInt16(data, numberOfCoils);

            return(CreateFromRaw(data));
        }
Ejemplo n.º 2
0
 public CoilVariable(ModbusControllerConnection connection, CoilAddress address)
 {
     _connection = connection;
     _address    = address;
 }
Ejemplo n.º 3
0
        public static Message CreateForceSingleCoilCommand(SlaveAddress slaveAddress, CoilAddress coil, bool desiredState)
        {
            var data = new List <byte>();

            WriteSlaveAddress(data, slaveAddress);
            WriteFunctionCode(data, FunctionCode.ForceSingleCoil);
            WriteCoilAddress(data, coil);

            const byte On  = 0xff;
            const byte Off = 0x00;

            data.Add(desiredState ? On : Off);
            data.Add(0x00);

            return(CreateFromRaw(data));
        }
Ejemplo n.º 4
0
 private static void WriteCoilAddress(List <byte> buffer, CoilAddress address)
 {
     WriteBigEndianUInt16(buffer, address.WireValue);
 }
Ejemplo n.º 5
0
        public static Message CreateForceMultipleCoilsCommand(SlaveAddress slaveAddress, CoilAddress firstCoil, bool[] desiredStates)
        {
            if (desiredStates == null)
            {
                throw new ArgumentNullException();
            }
            if (desiredStates.Length == 0)
            {
                throw new ArgumentException("Must write at least one coil.");
            }
            if (desiredStates.Length > MaxBooleanArrayLength)
            {
                throw new ArgumentException("Too many coils.");
            }

            var data = new List <byte>();

            WriteSlaveAddress(data, slaveAddress);
            WriteFunctionCode(data, FunctionCode.ForceSingleCoil);
            WriteCoilAddress(data, firstCoil);
            WriteBigEndianUInt16(data, (ushort)desiredStates.Length);
            WriteLengthPrefixedPackedBooleanArray(data, desiredStates);

            return(CreateFromRaw(data));
        }
 internal void WriteCoil(CoilAddress coil, bool value)
 {
     _master.WriteSingleCoil(_slaveRaw, coil.WireValue, value);
 }
 internal bool[] ReadCoils(CoilAddress firstCoil, ushort numberOfCoils)
 {
     return(_master.ReadCoils(_slaveRaw, firstCoil.WireValue, numberOfCoils));
 }