Esempio n. 1
0
            public void TestOn()
            {

                Relay relay = new Relay(0, Relay.Direction.Both);
                relay.Set(Relay.Value.On);
                Assert.AreEqual(true, SimData.Relay[0].Forward);
                Assert.AreEqual(true, SimData.Relay[0].Reverse);
                relay.Dispose();
            }
Esempio n. 2
0
            public void TestOff()
            {
                Relay relay = new Relay(0, Relay.Direction.Both);

                relay.Set(Relay.Value.Off);
                Assert.AreEqual(false, SimData.Relay[0].GetForward());
                Assert.AreEqual(false, SimData.Relay[0].GetReverse());
                relay.Dispose();
            }
Esempio n. 3
0
            public void TestForward()
            {
                Relay relay = new Relay(0, Relay.Direction.Reverse);

                Assert.Throws <InvalidValueException>(() =>
                {
                    relay.Set(Relay.Value.Forward);
                });
                relay.Dispose();
            }
Esempio n. 4
0
        /// <summary>
        ///     Releases managed and native resources
        /// </summary>
        /// <param name="disposing"></param>
        private void dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }
#if USE_LOCKING
            lock (relay)
#endif
            {
                relay?.Dispose();
            }
        }
Esempio n. 5
0
 public bool Teardown()
 {
     if (!m_freed)
     {
         m_relay.Dispose();
         m_inputOne.Dispose();
         m_inputTwo.Dispose();
         m_freed = true;
     }
     else
     {
         throw new SystemException($"You attempted to free the {nameof(RelayCrossConnectFixture)} multiple times");
     }
     return(true);
 }
Esempio n. 6
0
        private void MainPage_Unloaded(object sender, object args)
        {
            // Cleanup
            if (timer != null)
            {
                timer.Tick -= Timer_Tick;
                timer.Stop();
            }

            connection?.Dispose();

            if (deviceClient != null)
            {
                geolocator.PositionChanged -= OnPositionChanged;
                geolocator   = null;
                deviceClient = null;
            }

            led?.Dispose();
            relay?.Dispose();

            if (humitureSensor != null)
            {
                humitureSensor.ReadingChanged -= HumitureSensor_ReadingChanged;
                humitureSensor.Dispose();
            }

            if (motionDetector != null)
            {
                motionDetector.MotionDetected -= MotionDetector_MotionDetected;
                motionDetector.MotionStopped  -= MotionDetector_MotionStopped;
                motionDetector.Dispose();
            }

            if (metalTouchSensor != null)
            {
                metalTouchSensor.TouchDetected -= MetalTouchSensor_TouchRemoved;
                metalTouchSensor.TouchRemoved  -= MetalTouchSensor_TouchDetected;
                metalTouchSensor.Dispose();
            }

            if (flameSensor != null)
            {
                flameSensor.FlameDetected -= FlameSensor_FlameDetected;
                flameSensor.FlameDetected -= FlameSensor_FlameExtinguished;
                flameSensor.Dispose();
            }
        }
Esempio n. 7
0
        public void Render(VirtualCanvas canvas)
        {
            Relay.Initialize(RelaySocket);
            ThermoCouple.Initialize(ThermoCoupleSocket);

            canvas.SetOrientation(Orientation.Landscape);
            canvas.DrawFill(BackgroundColor);
            canvas.DrawString(55, 4, 0, VerdanaBold14.ID, "Temperature & Relay");
            canvas.DrawString(32, 74, 0, VerdanaBold14.ID, "Celsius:");
            canvas.DrawString(32, 116, 0, VerdanaBold14.ID, "Fahrenheit:");
            canvas.DrawString(32, 154, 0, VerdanaBold14.ID, "Relay:");
            canvas.DrawButton(
                32, 197,
                250, 36,
                VerdanaBold14.ID, 20,
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                ColorHelpers.GetRGB24toRGB565(255, 255, 255),
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                "Click To Exit",
                RoundedCornerStyle.All);
            canvas.Execute();
            canvas.Touch += TouchEventHandler;
            while (LastTouchIsValid == 0)
            {
                ReadTemp();
                Thread.Sleep(100);
                canvas.DrawRectangleFilled(93, 153, 158, 176, BackgroundColor);
                canvas.DrawRectangleFilled(105, 69, 175, 94, BackgroundColor);
                canvas.DrawRectangleFilled(138, 112, 205, 137, BackgroundColor);
                canvas.DrawString(32, 74, 0, VerdanaBold14.ID, "Celsius: " + Shorten(ThermoCouple.Celsius.ToString()));
                canvas.DrawString(32, 116, 0, VerdanaBold14.ID, "Fahrenheit: " + Shorten(ThermoCouple.Farenheit.ToString()));
                canvas.DrawString(32, 154, 0, VerdanaBold14.ID, "Relay: " + ((RelayStatus) ? "ON" : "OFF"));
                canvas.Execute();
                canvas.TouchscreenWaitForEvent(TouchScreenEventMode.NonBlocking);
            }
            canvas.Touch -= TouchEventHandler;
            Relay.Dispose();
            ThermoCouple.Dispose();
        }
Esempio n. 8
0
 public override void OnDispose()
 {
     Relay.Dispose();
     base.OnDispose();
 }
Esempio n. 9
0
            public void TestOff()
            {

                Relay relay = new Relay(0, Relay.Direction.Reverse);
                relay.Set(Relay.Value.Off);
                Assert.AreEqual(false, SimData.Relay[0].Forward);
                Assert.AreEqual(false, SimData.Relay[0].Reverse);
                relay.Dispose();
            }
Esempio n. 10
0
            public void TestForward()
            {

                Relay relay = new Relay(0, Relay.Direction.Reverse);
                Assert.Throws<InvalidValueException>(() =>
                {
                    relay.Set(Relay.Value.Forward);
                });
                relay.Dispose();
            }
Esempio n. 11
0
        private void ListeningRoutine()
        {
            lock (_lock)
            {
                try
                {
                    _tcpListener = new TcpListener(_conf.IPEndPoint);
                    _tcpListener.Start();

                    Logger.InfoFormat("Started TCP listener (Id: {0}) at {1}", _conf.Id, _conf.IPEndPoint);
                }
                catch (Exception ex)
                {
                    Logger.ErrorException("Could not start TCP listener", ex);

                    try
                    {
                        _tcpListener.Stop();
                    }
                    catch
                    {
                        // dismiss
                    }

                    _isRunning = false;

                    // no re-throw
                    return;
                }
            }

            TcpClient client = null;
            Relay     relay  = null;

            try
            {
                while (true)
                {
                    client = _tcpListener.AcceptTcpClient();

                    Logger.InfoFormat("Listener {0} accepted client: {1}", _conf.Id, client.Client.RemoteEndPoint);

                    try
                    {
                        relay = this.EstablishConnection(client);
                        relay.Start();
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            client?.Dispose();
                        }
                        catch
                        {
                            // dismiss
                        }

                        try
                        {
                            relay?.Dispose();
                        }
                        catch
                        {
                            // dismiss
                        }

                        Logger.ErrorException("Could not start relay", ex);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new NotImplementedException(); // todo000000[ak]
            }
        }