Esempio n. 1
0
        public void TestCreateLimits()
        {
            List <DigitalInput> inputs = new List <DigitalInput>();

            for (int i = 0; i < NumInterrupts; i++)
            {
                inputs.Add(new DigitalInput(i));
            }

            foreach (var input in inputs)
            {
                input.RequestInterrupts();
            }
            DigitalInput in9 = new DigitalInput(NumInterrupts);

            Assert.Throws <AllocationException>(() =>
            {
                in9.RequestInterrupts();
            });
            in9.Dispose();

            foreach (var input in inputs)
            {
                input.Dispose();
            }
        }
Esempio n. 2
0
 public bool Teardown()
 {
     if (m_allocated)
     {
         m_input.Dispose();
         m_output.Dispose();
         m_allocated = false;
     }
     return(true);
 }
Esempio n. 3
0
        /// <summary>
        ///     Releases managed and native resources
        /// </summary>
        /// <param name="disposing"></param>
        private void dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }
#if USE_LOCKING
            lock (din)
#endif
            {
                din?.Dispose();
            }
        }
Esempio n. 4
0
        public static void TearDownAfterClass()
        {
            compressor.Dispose();

            fakePressureSwitch.Dispose();
            fakeCompressor.Dispose();

            fakeSolenoid1.Dispose();
            fakeSolenoid2.Dispose();

            if (RobotBase.IsSimulation)
            {
                SimData.DIO[11].CancelValueCallback(callbackId);
            }
        }
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
        public void TestCreateDispose()
        {
            DigitalInput d1 = new DigitalInput(0);
            DigitalInput d2 = new DigitalInput(1);

            d1.RequestInterrupts();
            Assert.AreEqual(0, (int)d1.InterruptIndex);

            d1.CancelInterrupts();

            d2.RequestInterrupts();
            Assert.AreEqual(0, (int)d2.InterruptIndex);

            d1.Dispose();
            d2.Dispose();
        }
Esempio n. 7
0
        public void TestCreateDispose()
        {
            DigitalInput d1 = new DigitalInput(0);
            DigitalInput d2 = new DigitalInput(1);

            d1.RequestInterrupts();
            Assert.AreEqual(0, (int)d1.InterruptIndex);

            d1.CancelInterrupts();

            d2.RequestInterrupts();
            Assert.AreEqual(0, (int)d2.InterruptIndex);

            d1.Dispose();
            d2.Dispose();
        }
Esempio n. 8
0
        public void TestCreateLimits()
        {
            List<DigitalInput> inputs = new List<DigitalInput>();
            for (int i = 0; i < NumInterrupts; i++)
            {
                inputs.Add(new DigitalInput(i));
            }

            foreach (var input in inputs)
            {
                input.RequestInterrupts();
            }
            DigitalInput in9 = new DigitalInput(NumInterrupts);
            Assert.Throws<AllocationException>(() => in9.RequestInterrupts());
            in9.Dispose();

            foreach (var input in inputs)
            {
                input.Dispose();
            }
        }
Esempio n. 9
0
        public static int Main(string[] args)
        {
            Log.Register(new ConsoleOutEventLog(80));
            Log.Information("Initializing application...");

            HttpSocketClient.RegisterHttpProxyUse(false, false);                // Don't look for proxies.

            DB.BackupConnectionString = "Data Source=sensor.db;Version=3;";
            DB.BackupProviderName     = "Clayster.Library.Data.Providers.SQLiteServer.SQLiteServerProvider";
            db = DB.GetDatabaseProxy("TheSensor");

            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) =>
            {
                e.Cancel = true;
                executionLed.Low();
            };

            // Initializing hardware and retrieving current sensor values

            try
            {
                tmp102.Configure(false, TexasInstrumentsTMP102.FaultQueue.ConsecutiveFaults_6, TexasInstrumentsTMP102.AlertPolarity.AlertActiveLow,
                                 TexasInstrumentsTMP102.ThermostatMode.ComparatorMode, false, TexasInstrumentsTMP102.ConversionRate.Hz_1, false);

                temp         = (short)tmp102.ReadTemperatureRegister();
                temperatureC = temp / 256.0;

                for (int i = 0; i < 10; i++)
                {
                    tempAvgWindow [i] = temp;
                }

                sumTemp = temp * 10;
            } catch (Exception ex)
            {
                Log.Exception(ex);

                sumTemp      = 0;
                temperatureC = 0;
                errorLed.High();
            }

            try
            {
                adc.Configure(true, false, false, false, false, false);

                light        = adc.ReadRegistersBinary() [0];
                lightPercent = (100.0 * light) / 0x0fff;

                for (int i = 0; i < 10; i++)
                {
                    lightAvgWindow [i] = light;
                }

                sumLight = light * 10;
            } catch (Exception ex)
            {
                Log.Exception(ex);

                sumLight     = 0;
                lightPercent = 0;
                errorLed.High();
            }

            // Loading historical Sensor Values

            Log.Information("Loading Minute Values.");
            perMinute.AddRange(Record.LoadRecords(Rank.Minute));

            Log.Information("Loading Hour Values.");
            perHour.AddRange(Record.LoadRecords(Rank.Hour));

            Log.Information("Loading Day Values.");
            perDay.AddRange(Record.LoadRecords(Rank.Day));

            Log.Information("Loading Month Values.");
            perMonth.AddRange(Record.LoadRecords(Rank.Month));

            // Resuming average calculations

            int      Pos         = perSecond.Count;
            DateTime CurrentTime = DateTime.Now;
            DateTime Timestamp;

            while (Pos-- > 0)
            {
                Record Rec = perSecond [Pos];
                Timestamp = Rec.Timestamp;
                if (Timestamp.Minute == CurrentTime.Minute && Timestamp.Hour == CurrentTime.Hour && Timestamp.Date == CurrentTime.Date)
                {
                    sumSeconds += Rec;
                    nrSeconds++;
                }
                else
                {
                    break;
                }
            }

            Pos = perMinute.Count;
            while (Pos-- > 0)
            {
                Record Rec = perMinute [Pos];
                Timestamp = Rec.Timestamp;
                if (Timestamp.Hour == CurrentTime.Hour && Timestamp.Date == CurrentTime.Date)
                {
                    sumMinutes += Rec;
                    nrMinutes++;
                }
                else
                {
                    break;
                }
            }

            Pos = perHour.Count;
            while (Pos-- > 0)
            {
                Record Rec = perHour [Pos];
                Timestamp = Rec.Timestamp;
                if (Timestamp.Date == CurrentTime.Date)
                {
                    sumHours += Rec;
                    nrHours++;
                }
                else
                {
                    break;
                }
            }

            Pos = perDay.Count;
            while (Pos-- > 0)
            {
                Record Rec = perDay [Pos];
                Timestamp = Rec.Timestamp;
                if (Timestamp.Month == CurrentTime.Month && Timestamp.Year == CurrentTime.Year)
                {
                    sumDays += Rec;
                    nrDays++;
                }
                else
                {
                    break;
                }
            }

            // Sampling of new Sensor Values

            Timer Timer = new Timer(SampleSensorValues, null, 1000 - DateTime.Now.Millisecond, 1000);                   // Every second.

            // HTTP Interface

            HttpServer HttpServer = new HttpServer(80, 10, true, true, 1);

            Log.Information("HTTP Server receiving requests on port " + HttpServer.Port.ToString());

            HttpServer.Register("/", HttpGetRoot, false);                                               // Synchronous, no authentication
            HttpServer.Register("/html", HttpGetHtml, false);                                           // Synchronous, no authentication
            HttpServer.Register("/historygraph", HttpGetHistoryGraph, false);                           // Synchronous, no authentication
            HttpServer.Register("/xml", HttpGetXml, false);                                             // Synchronous, no authentication
            HttpServer.Register("/json", HttpGetJson, false);                                           // Synchronous, no authentication
            HttpServer.Register("/turtle", HttpGetTurtle, false);                                       // Synchronous, no authentication
            HttpServer.Register("/rdf", HttpGetRdf, false);                                             // Synchronous, no authentication

            // HTTPS interface

            // Certificate must be a valid P12 (PFX) certificate file containing a private key.
            // X509Certificate2 Certificate = new X509Certificate2 ("Certificate.pfx", "PASSWORD");
            // HttpServer HttpsServer = new HttpServer (443, 10, true, true, 1, true, false, Certificate);
            //
            // foreach (IHttpServerResource Resource in HttpServer.GetResources())
            //    HttpsServer.Register (Resource);
            //
            // Log.Information ("HTTPS Server receiving requests on port " + HttpsServer.Port.ToString ());

            // Main loop

            Log.Information("Initialization complete. Application started...");

            try
            {
                while (executionLed.Value)
                {
                    System.Threading.Thread.Sleep(1000);
                }
            } catch (Exception ex)
            {
                Log.Exception(ex);
                executionLed.Low();
            } finally
            {
                Log.Information("Terminating application.");
                Log.Flush();
                Log.Terminate();
                Timer.Dispose();
                HttpServer.Dispose();
                //HttpsServer.Dispose ();
                executionLed.Dispose();
                measurementLed.Dispose();
                errorLed.Dispose();
                networkLed.Dispose();
                motion.Dispose();
                i2cBus.Dispose();
            }

            return(0);
        }
        public static int Main(string[] args)
        {
            Log.Register(new ConsoleOutEventLog(80));
            Log.Information("Initializing application...");

            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) =>
            {
                e.Cancel = true;
                executionLed.Low();
            };

            // Initializing hardware and retrieving current sensor values

            try
            {
                tmp102.Configure(false, TexasInstrumentsTMP102.FaultQueue.ConsecutiveFaults_6, TexasInstrumentsTMP102.AlertPolarity.AlertActiveLow,
                                 TexasInstrumentsTMP102.ThermostatMode.ComparatorMode, false, TexasInstrumentsTMP102.ConversionRate.Hz_1, false);

                temp         = (short)tmp102.ReadTemperatureRegister();
                temperatureC = temp / 256.0;

                for (int i = 0; i < 10; i++)
                {
                    tempAvgWindow [i] = temp;
                }

                sumTemp = temp * 10;
            } catch (Exception ex)
            {
                Log.Exception(ex);

                sumTemp      = 0;
                temperatureC = 0;
                errorLed.High();
            }

            try
            {
                adc.Configure(true, false, false, false, false, false);

                light        = adc.ReadRegistersBinary() [0];
                lightPercent = (100.0 * light) / 0x0fff;

                for (int i = 0; i < 10; i++)
                {
                    lightAvgWindow [i] = light;
                }

                sumLight = light * 10;
            } catch (Exception ex)
            {
                Log.Exception(ex);

                sumLight     = 0;
                lightPercent = 0;
                errorLed.High();
            }

            // Sampling of new Sensor Values

            Timer Timer = new Timer(SampleSensorValues, null, 1000 - DateTime.Now.Millisecond, 1000);                   // Every second.

            // Main loop

            Log.Information("Initialization complete. Application started...");

            try
            {
                while (executionLed.Value)
                {
                    System.Threading.Thread.Sleep(1000);
                }
            } catch (Exception ex)
            {
                Log.Exception(ex);
                executionLed.Low();
            } finally
            {
                Log.Information("Terminating application.");
                Log.Flush();
                Log.Terminate();
                Timer.Dispose();
                executionLed.Dispose();
                measurementLed.Dispose();
                errorLed.Dispose();
                networkLed.Dispose();
                motion.Dispose();
                i2cBus.Dispose();
            }

            return(0);
        }
Esempio n. 11
0
        public virtual bool Teardown()
        {
            var type = m_motor != null?GetCustomType() : "null";

            if (!m_tornDown)
            {
                bool wasNull = false;
                var  pwm     = m_motor as PWM;
                if (pwm != null && m_motor != null)
                {
                    pwm.Dispose();
                    m_motor = null;
                }
                else if (m_motor == null)
                {
                    wasNull = true;
                }
                if (m_encoder != null)
                {
                    m_encoder.Dispose();
                    m_encoder = null;
                }
                else
                {
                    wasNull = true;
                }
                if (m_counters[0] != null)
                {
                    m_counters[0].Dispose();
                    m_counters[0] = null;
                }
                else
                {
                    wasNull = true;
                }
                if (m_counters[1] != null)
                {
                    m_counters[1].Dispose();
                    m_counters[1] = null;
                }
                else
                {
                    wasNull = true;
                }
                if (m_aSource != null)
                {
                    m_aSource.Dispose();
                    m_aSource = null;
                }
                else
                {
                    wasNull = true;
                }
                if (m_bSource != null)
                {
                    m_bSource.Dispose();
                    m_bSource = null;
                }
                else
                {
                    wasNull = true;
                }

                m_tornDown = true;

                if (wasNull)
                {
                    throw new NullReferenceException("MotorEncoderFixture had null params at teardown");
                }
            }
            else
            {
                throw new SystemException(type + " Motor Encoder torn down multiple times");
            }

            return(true);
        }
        public static int Main(string[] args)
        {
            Log.Register(new ConsoleOutEventLog(80));
            Log.Information("Initializing application...");

            HttpSocketClient.RegisterHttpProxyUse(false, false);                // Don't look for proxies.

            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) =>
            {
                e.Cancel = true;
                executionLed.Low();
            };

            // Initializing hardware and retrieving current sensor values

            try
            {
                tmp102.Configure(false, TexasInstrumentsTMP102.FaultQueue.ConsecutiveFaults_6, TexasInstrumentsTMP102.AlertPolarity.AlertActiveLow,
                                 TexasInstrumentsTMP102.ThermostatMode.ComparatorMode, false, TexasInstrumentsTMP102.ConversionRate.Hz_1, false);

                temp         = (short)tmp102.ReadTemperatureRegister();
                temperatureC = temp / 256.0;

                for (int i = 0; i < 10; i++)
                {
                    tempAvgWindow [i] = temp;
                }

                sumTemp = temp * 10;
            } catch (Exception ex)
            {
                Log.Exception(ex);

                sumTemp      = 0;
                temperatureC = 0;
                errorLed.High();
            }

            try
            {
                adc.Configure(true, false, false, false, false, false);

                light        = adc.ReadRegistersBinary() [0];
                lightPercent = (100.0 * light) / 0x0fff;

                for (int i = 0; i < 10; i++)
                {
                    lightAvgWindow [i] = light;
                }

                sumLight = light * 10;
            } catch (Exception ex)
            {
                Log.Exception(ex);

                sumLight     = 0;
                lightPercent = 0;
                errorLed.High();
            }

            // Sampling of new Sensor Values

            Timer Timer = new Timer(SampleSensorValues, null, 1000 - DateTime.Now.Millisecond, 1000);                   // Every second.

            // HTTP Interface

            HttpServer HttpServer = new HttpServer(80, 10, true, true, 1);

            Log.Information("HTTP Server receiving requests on port " + HttpServer.Port.ToString());

            HttpServer.Register("/", HttpGetRoot, false);                                               // Synchronous, no authentication
            HttpServer.Register("/html", HttpGetHtml, false);                                           // Synchronous, no authentication
            HttpServer.Register("/historygraph", HttpGetHistoryGraph, false);                           // Synchronous, no authentication
            HttpServer.Register("/xml", HttpGetXml, false);                                             // Synchronous, no authentication
            HttpServer.Register("/json", HttpGetJson, false);                                           // Synchronous, no authentication
            HttpServer.Register("/turtle", HttpGetTurtle, false);                                       // Synchronous, no authentication
            HttpServer.Register("/rdf", HttpGetRdf, false);                                             // Synchronous, no authentication

            // HTTPS interface

            // Certificate must be a valid P12 (PFX) certificate file containing a private key.
            // X509Certificate2 Certificate = new X509Certificate2 ("Certificate.pfx", "PASSWORD");
            // HttpServer HttpsServer = new HttpServer (443, 10, true, true, 1, true, false, Certificate);
            //
            // foreach (IHttpServerResource Resource in HttpServer.GetResources())
            //    HttpsServer.Register (Resource);
            //
            // Log.Information ("HTTPS Server receiving requests on port " + HttpsServer.Port.ToString ());

            // Main loop

            Log.Information("Initialization complete. Application started...");

            try
            {
                while (executionLed.Value)
                {
                    System.Threading.Thread.Sleep(1000);
                }
            } catch (Exception ex)
            {
                Log.Exception(ex);
                executionLed.Low();
            } finally
            {
                Log.Information("Terminating application.");
                Log.Flush();
                Log.Terminate();
                Timer.Dispose();
                HttpServer.Dispose();
                //HttpsServer.Dispose ();
                executionLed.Dispose();
                measurementLed.Dispose();
                errorLed.Dispose();
                networkLed.Dispose();
                motion.Dispose();
                i2cBus.Dispose();
            }

            return(0);
        }