Example #1
0
        /// <summary>
        /// Tests the socket class.
        /// </summary>
        private static void TestSocketClass()
        {
            ISocketAdapter socketAdapter = new SocketClassAdapterImpl();
            Volts          v3            = socketAdapter.Get3Volts();
            Volts          v12           = socketAdapter.Get12Volts();
            Volts          v120          = socketAdapter.Get120Volts();

            Console.WriteLine("V3 using class Adapter = " + v3.Getvolts());
            Console.WriteLine("V12 using class Adapter = " + v12.Getvolts());
            Console.WriteLine("V120 using class Adapter = " + v120.Getvolts());
        }
Example #2
0
        private static void ObserverThread()
        {
            try
            {
                var device = new USBM();

                if (!device.OpenDevice())
                {
                    throw new Exception("Could not open device.");
                }

                while (true)
                {
                    var volts = device.GetMeasuredValue();

                    if (volts == 0.0f)
                    {
                        throw new Exception("Value read from device was zero. This indicates the device may not be working. Restarting to try to recover.");
                    }

                    var ppmPerVolt = 197.5f; // Experimentally determined - looks perfectly linear.
                    var ppm        = (int)(volts * ppmPerVolt);

                    Measurements.Inc();
                    Volts.Set(volts);
                    Ppm.Set(ppm);

                    Console.WriteLine($"{volts:#00.000} V\t\t{ppm} PPM");

                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }
            catch (Exception ex)
            {
                // Oh no! This is fatal error.
                Console.WriteLine(ex.ToString());
                Console.WriteLine("Will restart after sleeping for a while.");
                Thread.Sleep(TimeSpan.FromSeconds(30));
                Process.GetCurrentProcess().Kill();
            }
        }
Example #3
0
 /// <summary>
 /// Converts the volt.
 /// </summary>
 /// <param name="v">The v.</param>
 /// <param name="i">The i.</param>
 /// <returns></returns>
 private Volts ConvertVolt(Volts v, int i)
 {
     return(new Volts(v.Getvolts() / i));
 }
Example #4
0
        /// <summary>
        /// Get3s the volts.
        /// </summary>
        /// <returns></returns>
        public Volts Get3Volts()
        {
            Volts v = socket.SocketVolt();

            return(ConvertVolt(v, 40));
        }
Example #5
0
        /// <summary>
        /// Get12s the volts.
        /// </summary>
        /// <returns></returns>
        public Volts Get12Volts()
        {
            Volts v = SocketVolt();

            return(ConvertVolt(v, 10));
        }