Exemplo n.º 1
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            ILog log = LogManager.GetLogger("GPIO");

            log.Debug("Start");

            PinConfiguration output = ConnectorPin.P1Pin36.Output().Name("Output1");

            PinConfiguration[] outputs = new PinConfiguration[]
            {
                output
            };

            GpioConnection gpio = new GpioConnection(outputs);
            //gpio.Open();

            ElectricPotential referenceVoltage = ElectricPotential.FromVolts(3.3);

            var driver = new MemoryGpioConnectionDriver(); //GpioConnectionSettings.DefaultDriver;

            Mcp3008SpiConnection spi = new Mcp3008SpiConnection(
                driver.Out(adcClock),
                driver.Out(adcCs),
                driver.In(adcMiso),
                driver.Out(adcMosi));

            IInputAnalogPin inputPin = spi.In(Mcp3008Channel.Channel0);

            gpio.Open();
            ElectricPotential volts = ElectricPotential.FromVolts(0);

            while (!Console.KeyAvailable)
            {
                var v = referenceVoltage * (double)inputPin.Read().Relative;
                Console.WriteLine("{0} mV", v.Millivolts);
                if ((Math.Abs(v.Millivolts - volts.Millivolts) > 100))
                {
                    volts = ElectricPotential.FromMillivolts(v.Millivolts);
                    Console.WriteLine("Voltage ch0: {0}", volts.Millivolts.ToString());
                }
                gpio.Toggle("Output1");
                Thread.Sleep(2000);
            }
            gpio.Close();

            //bool bShutdown = false;
            //while(!bShutdown)
            //{

            //    gpio.Toggle(output);
            //    log.Debug("Toggle output");

            //    Thread.Sleep(5000);

            //}
        }
Exemplo n.º 2
0
        public void ReadSPI()
        {
            var v = referenceVoltage * (double)spiInput.Read().Relative;

            Pressure = Convert.ToInt32(v.Millivolts * TransducerCharacteristic);
            double diff = Math.Abs(v.Millivolts - volts.Millivolts);

            if (diff > 250)
            {
                volts = ElectricPotential.FromMillivolts(v.Millivolts);
                Console.WriteLine("Pressure: {0}", Pressure);
                CreateEvent(EventType.IOEvent, string.Format("Pressure change {0}", Pressure));
                bUpdateStatus = true;
            }
            if ((diff > 150) && !bUpdateStatus)
            {
                volts = ElectricPotential.FromMillivolts(v.Millivolts);
                Console.WriteLine("Pressure: {0}", Pressure);
                CreateEvent(EventType.IOEvent, string.Format("Pressure change {0}", Pressure));
                bUpdateStatus = true;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the temperature.
        /// </summary>
        /// <returns>The temperature.</returns>
        public UnitsNet.Temperature GetTemperature()
        {
            var voltage = referenceVoltage * (double)inputPin.Read().Relative;

            return(UnitsNet.Temperature.FromDegreesCelsius(voltage.Volts * 100 - 50));
        }
        /// <summary>
        /// Gets the electric resistance.
        /// </summary>
        /// <returns>The resistance value.</returns>
        public ElectricResistance GetResistance()
        {
            var value = analogPin.Read();

            return(resistorEvalFunc(value));
        }
Exemplo n.º 5
0
 protected void Read()
 {
     //read data from SPI channel
     prevSample = sample;
     sample     = referenceVoltage * (double)spiInput.Read().Relative;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the resistor, in Ohms.
        /// </summary>
        /// <returns>The resistor value.</returns>
        public decimal GetResistor()
        {
            var value = analogPin.Read();

            return(resistorEvalFunc(value));
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("GPIOTestHarness");
            bool Station1OutputState = false;
            bool Station2OutputState = false;
            bool Station3OutputState = false;
            bool Station4OutputState = false;

            //var Output1 = Station1OutputPin.Output();
            //var Output2 = Station2OutputPin.Output();
            //var Output3 = Station3OutputPin.Output();
            //var Output4 = Station4OutputPin.Output();
            var pins = new PinConfiguration[]
            {
                Station1OutputPin.Output().Name("Output1"),
                Station2OutputPin.Output().Name("Output2"),
                Station3OutputPin.Output().Name("Output3"),
                Station4OutputPin.Output().Name("Output4")
            };
            //var settings = new GpioConnectionSettings();
            var connection = new GpioConnection(pins);

            var Input1 = LowPressureFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("LowPressureFaultInput {0}", b ? "on" : "off");
                if (Station1OutputState != b)
                {
                    connection.Toggle("Output1"); Station1OutputState = b;
                }
            });

            connection.Add(Input1);
            var Input2 = HighPressureFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("HighPressureFaultInput {0}", b ? "on" : "off");
                if (Station2OutputState != b)
                {
                    connection.Toggle("Output2"); Station2OutputState = b;
                }
            });

            connection.Add(Input2);
            var Input3 = LowWellFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("LowWellFaultInput {0}", b ? "on" : "off");
                if (Station3OutputState != b)
                {
                    connection.Toggle("Output3"); Station3OutputState = b;
                }
            });

            connection.Add(Input3);
            var Input4 = OverloadFaultInputPin.Input().OnStatusChanged(b =>
            {
                Console.WriteLine("OverloadFaultInput {0}", b ? "on" : "off");
                if (Station4OutputState != b)
                {
                    connection.Toggle("Output4"); Station4OutputState = b;
                }
            });

            connection.Add(Input4);

            ElectricPotential referenceVoltage = ElectricPotential.FromVolts(3.3);

            var driver = new MemoryGpioConnectionDriver(); //GpioConnectionSettings.DefaultDriver;

            Mcp3008SpiConnection spi = new Mcp3008SpiConnection(
                driver.Out(adcClock),
                driver.Out(adcCs),
                driver.In(adcMiso),
                driver.Out(adcMosi));

            IInputAnalogPin inputPin = spi.In(Mcp3008Channel.Channel0);

            connection.Open();
            ElectricPotential volts = ElectricPotential.FromVolts(0);

            while (!Console.KeyAvailable)
            {
                var v = referenceVoltage * (double)inputPin.Read().Relative;
                if ((Math.Abs(v.Millivolts - volts.Millivolts) > 100))
                {
                    volts = ElectricPotential.FromMillivolts(v.Millivolts);
                    Console.WriteLine("Voltage ch0: {0}", volts.Millivolts.ToString());
                }
            }
            connection.Close();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the temperature, in Celsius.
        /// </summary>
        /// <returns>The temperature, in Celsius.</returns>
        public decimal GetTemperature()
        {
            var voltage = inputPin.Read().Relative *referenceVoltage;

            return(voltage * 100 - 50);
        }