public static WriteMultipleCoils Decode(string message) { WriteMultipleCoils response = JsonConvert.DeserializeObject <WriteMultipleCoils>(message); byte[] msg = response.Encode(); return(Decode(msg)); }
public static WriteMultipleCoils Create(byte slaveId, ushort startingAddress, BitArray coilValues) { WriteMultipleCoils request = new WriteMultipleCoils() { SlaveAddress = slaveId, FunctionCode = 15, StartingAddress = startingAddress, QuantityOfCoils = (ushort)coilValues.Length, ByteCount = (coilValues.Length % 8) == 0 ? (byte)(coilValues.Length / 8) : (byte)((coilValues.Length / 8) + 1), Data = coilValues, Protocol = ProtocolType.RTU }; byte[] rtuEncoded = request.Encode(); return(WriteMultipleCoils.Decode(rtuEncoded)); }
public static WriteMultipleCoils Create(byte unitId, ushort transactionId, ushort protocolId, ushort startingAddress, BitArray coilValues) { WriteMultipleCoils request = new WriteMultipleCoils() { Header = new MbapHeader() { ProtocolId = protocolId, TransactionId = transactionId, UnitId = unitId }, SlaveAddress = unitId, FunctionCode = 15, StartingAddress = startingAddress, QuantityOfCoils = (ushort)coilValues.Length, ByteCount = (coilValues.Length % 8) == 0 ? (byte)(coilValues.Length / 8) : (byte)((coilValues.Length / 8) + 1), Data = coilValues, Protocol = ProtocolType.TCP }; byte[] encoded = request.Encode(); return(WriteMultipleCoils.Decode(encoded)); }