Beispiel #1
0
        public virtual void WriteSingleCoil()
        {
            bool coilValue = Master.ReadCoils(SlaveAddress, 10, 1)[0];

            Master.WriteSingleCoil(SlaveAddress, 10, !coilValue);
            Assert.AreEqual(!coilValue, Master.ReadCoils(SlaveAddress, 10, 1)[0]);
            Master.WriteSingleCoil(SlaveAddress, 10, coilValue);
            Assert.AreEqual(coilValue, Master.ReadCoils(SlaveAddress, 10, 1)[0]);
        }
Beispiel #2
0
 public void WriteSingleCoil(ushort address, bool value)
 {
     if (RTUConnected || TCPConnected)
     {
         lock (_Locker)
             _Master.WriteSingleCoil(1, address, value);
     }
 }
        public bool Write(int addr, bool status)
        {
            if (_master == null)
            {
                throw new NullReferenceException("_master");
            }

            try
            {
                //锁一下Transport,避免和其它的调用者发生冲突
                lock (Transport)
                {
                    return(_master.WriteSingleCoil(addr, status));
                }
            }
            catch (Exception ex)
            {
                XTrace.WriteException(ex);
                return(false);
            }
        }