Exemplo n.º 1
0
        protected void LoadSolenoids()
        {
            log.InfoFormat("LoadSolenoids()");
            Solenoids.Clear();
            List <Solenoid> solenoids = dataServer.GetSolenoids(device.Id);

            if (solenoids != null)
            {
                foreach (Solenoid s in solenoids)
                {
                    log.DebugFormat("{0}  {1} {2}", s.Id, s.Description, s.HardwareType.ToString());
                    ISolenoid sol = CreateSolenoid(s);
                    Solenoids.Add(new SolenoidTuple {
                        Data = s, Hardware = sol
                    });

                    if (s.Id == device.PumpSolenoid)
                    {
                        PumpSolenoid = sol;
                    }
                }
            }
            foreach (SolenoidTuple solenoid in Solenoids)
            {
                log.Info(solenoid.Report());
            }
            log.DebugFormat("{0} Solenoids configured", Solenoids.Count());
        }
Exemplo n.º 2
0
        public IrrigationProgram(int id, string name, DateTime start, int duration, int solenoidId, HardwareService hw, DataService data)
        {
            Id         = id;
            Name       = name;
            Start      = start;
            Duration   = duration;
            SolenoidId = solenoidId;

            hardwareService  = hw;
            dataService      = data;
            DataSolenoid     = dataService.Solenoids.AsQueryable <Solenoid>().Where(s => s.Id == solenoidId).First <Solenoid>();
            HardwareSolenoid = hardwareService.Solenoids.AsQueryable <ISolenoid>().Where(s => s.Id == solenoidId).First <ISolenoid>();

            HardwarePumpSolenoid                           = hardwareService.PumpSolenoid;
            DataPumpSolenoid                               = dataService.Solenoids
                                              RequiresPump = DataSolenoid.RequiresPump;


            Data.IrrigationProgram program = new Data.IrrigationProgram()
            {
                Name         = Name,
                Start        = Start,
                Duration     = Duration,
                DeviceId     = data.device.Id,
                SolenoidName = DataSolenoid.Name,
                SolenoidId   = DataSolenoid.Id,
                RequiresPump = DataSolenoid.RequiresPump
            };
            dataService.dataServer.PutIrrigationProgram(program);

            //start irrigating
            HardwareSolenoid.On();
            DataSolenoid.Value = 1;
            dataService.dataServer.PutSolenoid(DataSolenoid);

            if (RequiresPump)
            {
                hardwareService.PumpSolenoid.On();
            }

            //report to the server
            DataSolenoid.Value = 1;
            dataService.dataServer.PutSolenoid(DataSolenoid);
        }
        public DeviceSolenoid(Solenoid s)
        {
            dataSolenoid = s;
            log.DebugFormat("DeviceSolenoid() {0}", s.Name);
            switch (s.HardwareType)
            {
            case "GPIO":
                log.DebugFormat("{0}", s.Address);
                hardwareSolenoid = new GPIOSolenoid(dataSolenoid.Id, dataSolenoid.Name, dataSolenoid.Address);
                break;

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

            case "SPI":
                hardwareSolenoid = new SPISolenoid(dataSolenoid.Id, dataSolenoid.Name, dataSolenoid.Address);
                break;

            default:
                throw new Exception("Unknown Solenoid type");
            }
        }