public GPIOSolenoid(int id, string name, string address) { log = LogManager.GetLogger("Device"); Id = id; Name = name; Address = address; pin = GPIOService.GetGPIOPin(Address); pinConfig = pin.Output().Name(name); GPIOService.Gpio.Add(pinConfig); }
public GPIOAlarm(int id, string name, string address) { Id = id; Name = name; Address = address; pin = GPIOService.GetGPIOPin(Address); pinConfig = pin.Input().Name(Name).OnStatusChanged(b => { State = b ? true : false; //Console.WriteLine("Alarm {0} {1}", Name, b ? "on" : "off"); AlarmStatusChangedEventArgs e = new AlarmStatusChangedEventArgs(); e.Value = b; OnStatusChanged(e); }); Id = id; GPIOService.Gpio.Add(pinConfig); }
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)); } }