//********************************************************************************************************** //** Collect SensorCollection ** //********************************************************************************************************** public SensorCollection ReadCell(string location) { SensorCollection sensors = new SensorCollection(); string sn; if (Directory.Exists(location)) { foreach (string path in Directory.GetDirectories(location)) { sn = path.Remove(0, location.Length + 1); if (!sn.StartsWith("SN")) { continue; } string verPath = path + "\\" + sn + ".xml"; //path to main XML file Sensor sensor = new Sensor(); Regex rgx = new Regex(@"[^0-9]"); if (!File.Exists(verPath)) { sensor.Sn = -1; sensor.Model = string.Format("No file {0}.xml", sn); sensor.Location = path; } else { //sensor.Time = File.GetLastWriteTime(verPath).ToUniversalTime().ToString(); sensor.Time = File.GetLastWriteTime(verPath).ToLocalTime(); XmlDocument doc = new XmlDocument(); if (IsValidXml(verPath)) { doc.Load(verPath); XmlNodeList nodes = doc.DocumentElement.SelectNodes("/Entries/Entries/Item"); //bool f = false;// foreach (XmlNode node in nodes) { if (!node.SelectSingleNode("SensorModel").InnerText.Equals("")) { sensor.Model = node.SelectSingleNode("SensorModel").InnerText; } if (!node.SelectSingleNode("SensorId").InnerText.Equals("")) { var sntext = node.SelectSingleNode("SensorId").InnerText; //remove symbols var snnumb = rgx.Replace(sntext, ""); //remove leading zerros int number; bool result = Int32.TryParse(snnumb, out number); if (result) { sensor.Sn = number; } else { sensor.Sn = -3; } } if (node.SelectSingleNode("Type").InnerText.Equals("Initialize")) { if (node.SelectSingleNode("Values") != null) { foreach (XmlNode innerNode in node.SelectSingleNode("Values")) { if (innerNode.Name.Equals("WorkOrder")) { sensor.Wip = innerNode.InnerText; //f = true; } } } } sensor.Location = path; } } else { sensor.Sn = -2; sensor.Model = string.Format("{0}.xml is not valid", sn); sensor.Location = path; } } sensors.Add(sensor); } } return(sensors); }
public void AddEvent(Sensor result, SensorStatus sensorStatus) { InvokerHelper.RunSave(async() => { SensorCollection currentSensorCollection; bool event_exist = false; //foreach (var sensor in SensorCollection) //{ // if (result.Id == sensor.CurrentSensor.Id) // { // event_exist = true; // break; // } //} Parallel.ForEach(SensorCollection, (sensor, state) => { if (result.Id == sensor.CurrentSensor.Id) { event_exist = true; state.Stop(); } }); if (IsSensorAlarming(result, sensorStatus)) { if (event_exist) { currentSensorCollection = SensorCollection.FirstOrDefault(t => t.CurrentSensor.Id == result.Id); if (currentSensorCollection != null) { bool canUpdate = await cacheService.UpdateEntity(currentSensorCollection.CurrentSensor); if (canUpdate) { currentSensorCollection.SensorEvents.EventAlarms?. Add(new EventAlarm(sensorStatus)); UpdateSensorEvent?. Invoke(null, currentSensorCollection); } } } else { currentSensorCollection = new SensorCollection() { CurrentSensor = result, FirstSensorStatus = sensorStatus, SensorEvents = new Event() { EventAlarms = new List <EventAlarm>() { new EventAlarm(sensorStatus) } } }; bool canSave = await cacheService.AddEntity(currentSensorCollection.CurrentSensor); if (canSave) { if (sensorStatus.StatusType == StatusType.Alarm) { SensorCollection.Add(currentSensorCollection); } else { SensorCollection.Insert(0, currentSensorCollection); } AddSensorEvent?. Invoke(null, currentSensorCollection); } } } }); }
// : CANBusDevice TODO CLEANUP and package CAN stuff /* all CAN stuff here */ public TalonSRX(int deviceNumber, bool externalEnable = false) : base(deviceNumber | 0x02040000, externalEnable) { _sensorColl = new SensorCollection(_ll); }
public void SimpleEnumeratorTest() { SensorCollection collection = new SensorCollection(null); Assert.IsNull(collection[Arduino.Arduino1, ArduinoPort.Port1]); }
public static SensorCollection ToSensorCollection(this SensorSet sensorSet) { var sc = new SensorCollection { Title = sensorSet.Title }; sc.AddRange(sensorSet.Values); return sc; }