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); //} }
public void InitGpio() { outputs = new PinConfiguration[] { Station1OutputPin.Output().Name("Station1"), Station2OutputPin.Output().Name("Station2"), Station3OutputPin.Output().Name("Station3"), Station4OutputPin.Output().Name("Station4"), Station5OutputPin.Output().Name("Station5"), Station6OutputPin.Output().Name("Station6"), Station7OutputPin.Output().Name("Station7"), Station8OutputPin.Output().Name("Station8"), PumpOperationPin.Output().Name("PumpOperation"), TankRelayOutputPin.Output().Name("TankRelay"), SpareOutputPin.Output().Name("Spare"), ResetRelayOutputPin.Output().Name("ResetRelay") }; connection = new GpioConnection(outputs); connection.Add(LowPressureFaultInputPin.Input().OnStatusChanged(b => { Console.WriteLine("LowPressureFaultInput {0}", b ? "on" : "off"); bLowPressureFaultState = b; CreateEvent(EventType.IOEvent, string.Format("Input {0} on", LowPressureFaultInputPin.ToString())); CreateEvent(EventType.FaultEvent, string.Format("Low pressure fault {0}", b ? "detected" : "cleared")); })); connection.Add(HighPressureFaultInputPin.Input().OnStatusChanged(b => { Console.WriteLine("HighPressureFaultInput {0}", b ? "on" : "off"); bHighPressureFaultState = b; CreateEvent(EventType.IOEvent, string.Format("Input {0} {1}", HighPressureFaultInputPin.ToString(), b ? "on" : "off")); CreateEvent(EventType.FaultEvent, string.Format("High pressure fault {0}", b ? "detected" : "cleared")); })); connection.Add(LowWellFaultInputPin.Input().OnStatusChanged(b => { Console.WriteLine("LowWellFaultInput {0}", b ? "on" : "off"); bLowWellFaultState = b; CreateEvent(EventType.IOEvent, string.Format("Input {0} {1}", LowWellFaultInputPin.ToString(), b ? "on" : "off")); CreateEvent(EventType.FaultEvent, string.Format("Low well fault {0}", b ? "detected" : "cleared")); if (b) { dtFaultStartDate = DateTime.Now; Log(string.Format("Initializing timeout at {0}", dtFaultStartDate.ToString())); ChangeState(State.WaitForTimeout); } else { ChangeState(State.Monitor); } })); connection.Add(OverloadFaultInputPin.Input().OnStatusChanged(b => { Console.WriteLine("OverloadFaultInput {0}", b ? "on" : "off"); bOverloadFaultState = b; })); //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)); spiInput = spi.In(Mcp3008Channel.Channel0); connection.Open(); }
/// <summary> /// Initializes a new instance of the <see cref="Tmp36Connection"/> class. /// </summary> /// <param name="inputPin">The input pin.</param> /// <param name="referenceVoltage">The reference voltage.</param> public Tmp36Connection(IInputAnalogPin inputPin, ElectricPotential referenceVoltage) { this.inputPin = inputPin; this.referenceVoltage = referenceVoltage; }
/// <summary> /// Initializes a new instance of the <see cref="VariableResistiveDividerConnection"/> class. /// </summary> /// <param name="analogPin">The analog pin.</param> /// <param name="resistorEvalFunc">The resistor eval function.</param> /// <remarks>Methods from <see cref="ResistiveDivider"/> should be used.</remarks> public VariableResistiveDividerConnection(IInputAnalogPin analogPin, Func <AnalogValue, ElectricResistance> resistorEvalFunc) { this.analogPin = analogPin; this.resistorEvalFunc = resistorEvalFunc; }
public SPIAnalog(int id, string name, double multiplier, string units, string address) { Id = id; Name = name; Multiplier = multiplier; Units = units; Address = address; Threshold = 100.0; log.DebugFormat("SPIAnalog() {0}", Name); //Address property will be SPI:CHANNEL, eg 0:1 //The following code parses out the address to get SPI and CHANNEL string[] parts = Address.Split(':'); int spiId = Convert.ToInt32(parts[0]); string channel = parts[1]; ConnectorPin spiClock = GPIOService.GetGPIOPin(string.Format("P1Pin{0}", 23)); ConnectorPin spiCs = GPIOService.GetGPIOPin(string.Format("P1Pin{0}", 24)); ConnectorPin spiMISO = GPIOService.GetGPIOPin(string.Format("P1Pin{0}", 21)); ConnectorPin spiMOSI = GPIOService.GetGPIOPin(string.Format("P1Pin{0}", 19)); SpiDevice spi = new SpiDevice(1, "Redundant", spiClock, spiCs, spiMISO, spiMOSI); if (spi == null) { throw new Exception(string.Format("Configuration error: unknown SPI Id {0}", spiId)); } switch (channel) { case "0": spiInput = spi.Connection.In(Mcp3008Channel.Channel0); break; case "1": spiInput = spi.Connection.In(Mcp3008Channel.Channel1); break; case "2": spiInput = spi.Connection.In(Mcp3008Channel.Channel2); break; case "3": spiInput = spi.Connection.In(Mcp3008Channel.Channel3); break; case "4": spiInput = spi.Connection.In(Mcp3008Channel.Channel4); break; case "5": spiInput = spi.Connection.In(Mcp3008Channel.Channel5); break; case "6": spiInput = spi.Connection.In(Mcp3008Channel.Channel6); break; case "7": spiInput = spi.Connection.In(Mcp3008Channel.Channel7); break; default: throw new Exception(string.Format("Configuration error: unknown analog input channel {0}", channel)); } }
/// <summary> /// Initializes a new instance of the <see cref="Tmp36Connection"/> class. /// </summary> /// <param name="inputPin">The input pin.</param> /// <param name="referenceVoltage">The reference voltage.</param> public Tmp36Connection(IInputAnalogPin inputPin, decimal referenceVoltage) { this.inputPin = inputPin; this.referenceVoltage = referenceVoltage; }
/// <summary> /// Initializes a new instance of the <see cref="Tmp36Connection"/> class. /// </summary> /// <param name="inputPin">The input pin.</param> /// <param name="referenceVoltage">The reference voltage.</param> public Tmp36Connection(IInputAnalogPin inputPin, ElectricPotential referenceVoltage) { this.inputPin = inputPin; this.referenceVoltage = referenceVoltage; }
/// <summary> /// Initializes a new instance of the <see cref="VariableResistiveDividerConnection"/> class. /// </summary> /// <param name="analogPin">The analog pin.</param> /// <param name="resistorEvalFunc">The resistor eval function.</param> /// <remarks>Methods from <see cref="ResistiveDivider"/> should be used.</remarks> public VariableResistiveDividerConnection(IInputAnalogPin analogPin, Func<AnalogValue, ElectricResistance> resistorEvalFunc) { this.analogPin = analogPin; this.resistorEvalFunc = resistorEvalFunc; }
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(); }
/// <summary> /// Initializes a new instance of the <see cref="Tmp36Connection"/> class. /// </summary> /// <param name="inputPin">The input pin.</param> /// <param name="referenceVoltage">The reference voltage.</param> public Tmp36Connection(IInputAnalogPin inputPin, decimal referenceVoltage) { this.inputPin = inputPin; this.referenceVoltage = referenceVoltage; }