public ISolenoid CreateSolenoid(Solenoid s)
        {
            log.DebugFormat("HardwareService.CreateSolenoid()");
            ISolenoid sol;

            switch (s.HardwareType)
            {
            case "GPIO":
                log.DebugFormat("{0}", s.Address);
                ConnectorPin pin = GetGPIOPin(s.Address);
                log.DebugFormat("Got pin {0}", pin.ToString());
                sol = new GPIOSolenoid(pin, s.Name, gpio);
                break;

            case "Distributed":
                //return new DistributedSolenoid(s.Name, s.Address);
                sol = new BEM106EthernetSolenoid(s.Name, s.Address);
                break;

            case "SPI":
                sol = new SPISolenoid(s.Name, s.Address);
                break;

            default:
                throw new Exception("Unknown Solenoid type");
            }
            Solenoids.Add(sol);
            return(sol);
        }
예제 #2
0
 //turn on the output using Raspberry.IO.GeneralPurpose library
 protected override void OutputOn()
 {
     //don't allow GPIO pins to be accessed at the same time
     lock (PinFileLock.Instance)
     {
         try
         {
             Log.LogMessage("Turn on " + _connectorPin.ToString());
             _driver.Write(_processorPin, true);
             _pinState = PinState.High;
         }
         catch (Exception e)
         {
             Log.LogError("Failed to turn On " + _connectorPin.ToString() + " Error: " + e.ToString());
         }
     }
 }
예제 #3
0
        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();
        }
예제 #4
0
        /// <summary>
        /// Convert the specified connector pin to a processor pin.
        /// </summary>
        /// <param name="pin">The connector pin.</param>
        /// <returns>The processor pin.</returns>
        public static ProcessorPin ToProcessor(this ConnectorPin pin)
        {
            if (!processorMappings.TryGetValue(pin, out var processorPin))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Connector pin {0} is not mapped to processor with pin layout revision {1}", pin.ToString().Replace("Pin", "-"), GpioConnectionSettings.ConnectorPinout));
            }

            return(processorPin);
        }
예제 #5
0
        /// <summary>
        /// Convert the specified connector pin to a processor pin.
        /// </summary>
        /// <param name="pin">The connector pin.</param>
        /// <returns>The processor pin.</returns>
        public static ProcessorPin ToProcessor(this ConnectorPin pin)
        {
            ProcessorPin processorPin;

            if (processorMappings.TryGetValue(pin, out processorPin))
            {
                return(processorPin);
            }
            else
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Connector pin {0} is not mapped to processor on board revision {1}", pin.ToString().Replace("Pin", "-"), Board.Current.Revision));
            }
        }