public virtual void WriteMultipleCoils() { ushort testAddress = 200; bool[] testValues = new bool[] { true, false, true, false, false, false, true, false, true, false }; bool[] originalValues = Master.ReadCoils(SlaveAddress, testAddress, (ushort)testValues.Length); Master.WriteMultipleCoils(SlaveAddress, testAddress, testValues); bool[] newValues = Master.ReadCoils(SlaveAddress, testAddress, (ushort)testValues.Length); Assert.AreEqual(testValues, newValues); Master.WriteMultipleCoils(SlaveAddress, testAddress, originalValues); }
public bool Write(int addr, bool[] status) { if (_master == null) { throw new NullReferenceException("_master"); } try { //锁一下Transport,避免和其它的调用者发生冲突 lock (Transport) { return(_master.WriteMultipleCoils(addr, status)); } } catch (Exception ex) { XTrace.WriteException(ex); return(false); } }