/// <summary> /// Close the relay. If Pulse is running it will cancel the timer and remain closed. /// </summary> public void Close() { if (_pulseTimer != null && !_pulseTimer.Disposed) { _pulseTimer.Stop(); _pulseTimer.Dispose(); } _relay.Close(); }
public void CanWriteAllChannels() { var en = new RelaysEnumerator(); var relaysInfo = en.CollectInfo(); var relayInfo = relaysInfo.First(); var relay = new Relay(relayInfo); var mask = 0; for (var i = relay.ChannelsCount - 1; i >= 0; i--) { mask |= 1 << i; } if (relay.Open()) { relay.WriteChannels(false); var status = relay.ReadChannels(); Assert.That(status & mask, Is.EqualTo(0)); relay.WriteChannels(true); status = relay.ReadChannels(); Assert.That(status & mask, Is.EqualTo(mask)); relay.WriteChannels(false); status = relay.ReadChannels(); Assert.That(status & mask, Is.EqualTo(0)); relay.Close(); } }
public void CanReadWriteOneChannel([Range(1, 8)] int channel) { var en = new RelaysEnumerator(); var relaysInfo = en.CollectInfo(); var relayInfo = relaysInfo.First(); var relay = new Relay(relayInfo); if (relay.ChannelsCount < channel) { return; } if (relay.Open()) { relay.WriteChannel(channel, false); var state = relay.ReadChannel(channel); Assert.That(state, Is.False); relay.WriteChannel(channel, true); state = relay.ReadChannel(channel); Assert.That(state, Is.True); relay.WriteChannel(channel, false); state = relay.ReadChannel(channel); Assert.That(state, Is.False); relay.Close(); } }
private object pulse(Relay relay) { relay.Close(); Thread.Sleep(100); relay.Open(); return(relay); }
public void CanReadStatus() { var en = new RelaysEnumerator(); var relaysInfo = en.CollectInfo(); var relayInfo = relaysInfo.First(); var relay = new Relay(relayInfo); if (relay.Open()) { relay.ReadChannels(); relay.Close(); } }
public void CanReadId() { var en = new RelaysEnumerator(); var relaysInfo = en.CollectInfo(); var relayInfo = relaysInfo.First(); var relay = new Relay(relayInfo); if (relay.Open()) { var id = relay.ReadId(); Assert.That(id.Length, Is.EqualTo(5)); relay.Close(); } }
public void CanOpenClose() { var en = new RelaysEnumerator(); var relaysInfo = en.CollectInfo(); var relayInfo = relaysInfo.First(); var relay = new Relay(relayInfo); Assert.That(relay.IsOpened, Is.False); var opened = relay.Open(); Assert.That(opened, Is.True); Assert.That(relay.IsOpened, Is.True); relay.Close(); Assert.That(relay.IsOpened, Is.False); }
public void CanWriteId() { var en = new RelaysEnumerator(); var relaysInfo = en.CollectInfo(); var relayInfo = relaysInfo.First(); var relay = new Relay(relayInfo); if (relay.Open()) { var id = relay.ReadId(); var newId = DateTime.Now.ToString("Hmmss").Substring(0, 5); relay.WriteId(newId); var newIdCheck = relay.ReadId(); Assert.That(id, Is.Not.EqualTo(newIdCheck)); Assert.That(newIdCheck, Is.EqualTo(newId)); relay.Close(); } }
public void on() { Control.Close(); }