Пример #1
0
        public Sensor FindSensorForDXS(string key, SensorUID sensorUID)
        {
            if (!SensorsByNpt.ContainsKey(key))
            {
                throw new Exception("Не найден прибор типа " + key);
            }
            Sensor sensor = (from p in SensorsByNpt[key] where p.UseForCalibrate == 1 && p.SensorUID.Class == sensorUID.Class && p.SensorUID.Senstype == sensorUID.Senstype select p).FirstOrDefault <Sensor>();

            if (sensor == null)
            {
                throw new Exception("Не найден датчик " + sensorUID.Class + ":" + sensorUID.Senstype + " для прибора " + key);
            }
            return(sensor);
        }
Пример #2
0
        bool LoadSensors()
        {
            bool   rez    = true;
            string errmsg = "";

            Helpers.IniFile snames_ini = new Helpers.IniFile("SensorData\\Russian.lng");

            foreach (var key in SensorsByNpt.Keys)
            {
                SensorsByNpt[key].Clear();
                SensorsNamesByNpt[key].Clear();

                Helpers.IniFile iniFile = new Helpers.IniFile("SensorData\\" + DevTypesList[key].IniFileName);
                string          buf     = iniFile.Read("QuantitySensorsType", "Global");
                int             cnt     = int.Parse(buf);
                List <Sensor>   List    = new List <Sensor>();
                for (int i = 1; i <= cnt; i++)
                {
                    int ndx;
                    try
                    {
                        if (key == "1KEX")
                        {
                            ndx = i + 299;
                        }
                        else
                        {
                            ndx = 149 + int.Parse(iniFile.Read("TypeName", "Sensor" + i));
                        }
                        SensorUID sensor = new SensorUID()
                        {
                            Class    = int.Parse(iniFile.Read("sClass", "Sensor" + i) ?? "0"),
                            Senstype = int.Parse(iniFile.Read("senstype", "Sensor" + i) ?? "0"),
                        };

                        SensorsNamesByNpt[key].Add(sensor, snames_ini.Read(ndx.ToString(), "text"));

                        SensorsByNpt[key].Add(new Sensor()
                        {
                            DevType          = key,
                            SensorUID        = sensor,
                            UnitMeas         = iniFile.Read("UnitMeas", "Sensor" + i) ?? "0",
                            UseForCalibrate  = int.Parse(iniFile.Read("UseForCalibrate", "Sensor" + i) ?? "0"),
                            MinScale         = Win32Helper.ParseFloat(iniFile.Read("minScale", "Sensor" + i) ?? "0"),
                            MaxScale         = Win32Helper.ParseFloat(iniFile.Read("maxScale", "Sensor" + i) ?? "0"),
                            MinRangeDisabled = Win32Helper.ParseFloat(iniFile.Read("minRangeDisabled", "Sensor" + i) ?? "0"),
                            MinRangeEnabled  = Win32Helper.ParseFloat(iniFile.Read("minRangeEnabled", "Sensor" + i) ?? "0"),
                            MinCalibrate     = Win32Helper.ParseFloat(iniFile.Read("minCalibrate", "Sensor" + i) ?? "0"),
                            MaxCalibrate     = Win32Helper.ParseFloat(iniFile.Read("maxCalibrate", "Sensor" + i) ?? "0"),
                        });
                    }
                    catch (Exception e0)
                    {
                        rez    = false;
                        errmsg = GetLineNumber(e0) + ":" + e0.Message;
                        break;
                    }
                }
            }
            if (!rez)
            {
                MessageBox.Show("Ошибка чтения настроек." + errmsg);
                Environment.Exit(1);
            }
            return(rez);
        }
Пример #3
0
 public string FindSensorTypeName(int devndx, SensorUID uid)
 {
     return((from p in SensorsByNpt.ElementAt(devndx).Value where p.SensorUID.Class == uid.Class && p.SensorUID.Senstype == uid.Senstype select p.TypeName).
            SingleOrDefault <string>());
 }