Ejemplo n.º 1
0
 //
 // GET: /Device/Create
 public ActionResult Create()
 {
     ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name");
     ViewBag.ProductTypeId = new SelectList(db.ProductTypes, "Id", "Name");
     var dev = new Device();
     return View(dev);
 }
Ejemplo n.º 2
0
        public ActionResult Create(Device device)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Devices.Add(device);
                    db.SaveChanges();

                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                Logger.LogMessageToDB("Error creating device: " + ex.Message);
            }

            ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", device.CompanyId);
            ViewBag.ProductTypeId = new SelectList(db.ProductTypes, "Id", "Name", device.ProductTypeId);
            return View(device);
        }
Ejemplo n.º 3
0
 private List<ModBusMasterRegisterGroup> buildModBusGroups(Device device, List<List<Register>> regGroups)
 {
     var modBusGroups = new List<ModBusMasterRegisterGroup>();
     foreach (var regGroup in regGroups)
     {
         var registers = new List<RegisterNumberAndAddress>(regGroup.Count());
         foreach (var reg in regGroup)
         {
             registers.Add(new RegisterNumberAndAddress()
             {
                 Address = reg.RegisterAddress(),
                 RegisterNumber = reg.RegisterNumber
             });
         }
         var modBusGroup = new ModBusMasterRegisterGroup(registers);
         modBusGroups.Add(modBusGroup);
     }
     return modBusGroups;
 }
Ejemplo n.º 4
0
        public DeviceRegisterImporter(int deviceID, StreamReader stream)
        {
            using (var m_context = new DynapowerCloudMonitoringDbContext())
            {
                var device = m_context.Devices.Find(deviceID);
                if (device != null)
                {
                    var regs = device.Registers.ToList();
                    for (int i = 0; i < regs.Count(); i++)
                    {
                        m_context.Entry(regs[i]).State = System.Data.EntityState.Deleted;
                    }
                }
                else
                {
                    var dev = new Device()
                    {
                        Id = 1,
                        Name = "Device 1",
                        Location = new Location() { Address = "146 ESR", City = "South Hero", Name = "Location 1", State = "VT", Zip = "05486" },
                        SerialNumber = "9999n",
                        NetworkConfiguration = new NetworkingSettings() { IpAddress = "166.130.63.214", PortNumber = 502 },
                        SensorCloudSettings = new SensorCloudSettings() { LastPush = DateTime.UtcNow.AddHours(-5.0), DeviceID = "OAPI008DD8NQA6S0", APIKey = "bceb944e7de5a2d79cc1db707b9db69ee682f4fb04a80fa1bfe96815150b5eee" },
                        CircularBufferSampleRate = new TimeSpan(0, 0, 1),
                        DataStorageRate = new TimeSpan(1, 0, 0),
                        SalesOrderNumber = "234234",
                        SampleRate = new TimeSpan(0, 0, 5),
                        ProductTypeId = 1,
                        CompanyId = 1
                    };
                    m_context.Devices.Add(dev);
                }
                m_context.SaveChanges();
            }
            CsvFileDescription inputFileDescription = new CsvFileDescription
            {
                SeparatorChar = ',',
                FirstLineHasColumnNames = true
            };

            Logger.LogMessage("Starting to load CSV File");
            CsvContext cc = new CsvContext();
            IEnumerable<CSVRegister> registers = cc.Read<CSVRegister>(stream, inputFileDescription);
            var goodRegisters = registers.Where(reg => reg.Type.Trim() != "Ignore");
            Logger.LogMessage("Loaded " + registers.Count() + " good registers");
            foreach (var reg in goodRegisters)
            {
                try
                {
                    var regType = reg.Type.Trim();
                    Signedness sign = Signedness.Unsigned;
                    if (reg.DataType.Trim() == "Signed")
                    {
                        sign = Signedness.Signed;
                    }
                    else if (reg.DataType.Trim() == "Unsigned")
                    {
                        sign = Signedness.Unsigned;
                    }
                    if (regType == "Analog")
                    {
                        RegisterFactory.CreateAnalogRegister(deviceID, reg.Alias ?? "None", reg.Description ?? "None", reg.RegisterNumber, reg.EngineeringUnit ?? "None", reg.ScalingFactor, sign);
                    }
                    else if (regType == "Fault Word")
                    {
                        RegisterFactory.CreateStatusRegister(deviceID, reg.Alias ?? "None", reg.Description ?? "None", reg.RegisterNumber, sign);
                    }
                    else if (regType == "Alarm Word")
                    {
                        RegisterFactory.CreateStatusRegister(deviceID, reg.Alias ?? "None", reg.Description ?? "None", reg.RegisterNumber, sign);
                    }
                    else
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogMessage("Could not add register, exception: " + ex.Message);
                }
            }
        }
Ejemplo n.º 5
0
 private bool registerIsUniqueOnDevice(Device dev, Register reg)
 {
     var regMatches = dev.Registers.Where(regi => regi.Id != reg.Id && regi.RegisterNumber == reg.RegisterNumber).FirstOrDefault();
     if (regMatches != null)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
Ejemplo n.º 6
0
 private SensorCloud.Sensor addSensor(SensorCloud.Device device, Device DPDevice)
 {
     SensorCloud.Sensor sensor = null;
     if (!device.HasSensor(this.DPDeviceID.ToString()))
     {
         sensor = device.AddSensor(this.DPDeviceID.ToString(), DPDevice.Name, DPDevice.ProductType.Name, DPDevice.SerialNumber);
     }
     else
     {
         sensor = getSensor(device);
     }
     return sensor;
 }