Beispiel #1
0
        private void UpdateHpicThreshold()
        {
            string      filePath = GetDeviceConfigFile("scada.hpic");
            DeviceEntry entry    = DeviceEntry.GetDeviceEntry("scada.hpic", filePath);

            Settings.Instance.HpicAlarm = (StringValue)entry["Alarm1"];
        }
Beispiel #2
0
        private Device Load(DeviceEntry entry)
        {
            if (entry == null)
            {
                return(null);
            }


            //实例化设备
            StringValue className = (StringValue)entry[DeviceEntry.ClassName];

            if (typeof(StandardDevice).ToString() == className)
            {
                return(new StandardDevice(entry));
            }
            else if (typeof(WebFileDevice).ToString() == className)
            {
                return(new WebFileDevice(entry));
            }
            else if (typeof(FormProxyDevice).ToString() == className)
            {
                return(new FormProxyDevice(entry));
            }
            else if (typeof(CinderlDataDevice).ToString() == className)
            {
                return(new CinderlDataDevice(entry));
            }
            else if (typeof(CinderlStatusDevice).ToString() == className)
            {
                return(new CinderlStatusDevice(entry));
            }
            else if (typeof(ShelterDevice).ToString() == className)
            {
                return(new ShelterDevice(entry));
            }
            else if (typeof(HPGEFileDevice).ToString() == className)
            {
                return(new HPGEFileDevice(entry));
            }
            else if (typeof(WeatherDevice).ToString() == className)
            {
                return(new WeatherDevice(entry));
            }

            // Other Device defined in some Assemblies.
            if (entry[DeviceEntry.Assembly] != null)
            {
                string   assemblyName = (StringValue)entry[DeviceEntry.Assembly];
                string   assemblyFile = LogPath.GetExeFilePath(assemblyName);
                Assembly assembly     = Assembly.LoadFile(assemblyFile);
                Type     deviceClass  = assembly.GetType((StringValue)entry[DeviceEntry.ClassName]);
                if (deviceClass != null)
                {
                    object device = Activator.CreateInstance(deviceClass, new object[] { entry });
                    return(device as Device);
                }
            }
            MessageBox.Show("Create Device Failed");
            return((Device)null);
        }
Beispiel #3
0
        public IReadOnlyCollection <DeviceEntry> Commit(IEnumerable <long> deviceIds)
        {
            lock (_lock)
            {
                var result = new List <DeviceEntry>();

                foreach (var deviceId in deviceIds)
                {
                    var meta = _messagingMetas[deviceId];

                    if (meta.DequeueIndex < meta.EnqueueIndex && meta.Peek)
                    {
                        meta.DequeueIndex++;
                        meta.Peek = false;
                        meta.Version++;

                        var dequeueResult = new DeviceEntry
                        {
                            Id           = deviceId,
                            DequeueIndex = meta.DequeueIndex,
                            EnqueueIndex = meta.EnqueueIndex,
                            Peek         = meta.Peek,
                            Version      = meta.Version
                        };

                        result.Add(dequeueResult);
                    }
                }

                return(result);
            }
        }
Beispiel #4
0
        private void Initialize(DeviceEntry entry)
        {
            this.Name             = entry[DeviceEntry.Name].ToString();
            this.Id               = entry[DeviceEntry.Identity].ToString();
            this.DeviceConfigPath = entry[DeviceEntry.Path].ToString();
            this.Version          = entry[DeviceEntry.Version].ToString();

            this.ipAddr = entry["IPADDR"].ToString();

            this.Flow  = entry["Flow"].ToString();
            this.Hours = entry["Hours"].ToString();

            this.tableName = (StringValue)entry[DeviceEntry.TableName];
            if (!string.IsNullOrEmpty(tableName))
            {
                string tableFields = (StringValue)entry[DeviceEntry.TableFields];
                this.insertSQL = this.MakeInsertSQL(this.tableName, tableFields);
            }

            IValue v = entry["TSAP"];

            if (v != null)
            {
                this.tsap = v.ToString();
            }
        }
Beispiel #5
0
        private void CheckVirtualDevice(DeviceEntry entry, string configFile)
        {
            DirectoryInfo di = Directory.GetParent(configFile);
            string        virtualDeviceFlagFile = string.Format("{0}\\virtual-device", di.FullName);

            if (!File.Exists(virtualDeviceFlagFile))
            {
                return;
            }

            string       deviceDisplayName = (StringValue)entry[DeviceEntry.Name];
            string       caption           = "连接虚拟设备提示";
            string       message           = string.Format("是否要连接 '{0}' 的虚拟设备,连接虚拟设备点击‘是’,\n连接真实设备点击‘否’", deviceDisplayName);
            DialogResult dr = MessageBox.Show(message, caption, MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                entry[DeviceEntry.Virtual] = new StringValue("true");
            }
            else
            {
                entry[DeviceEntry.Virtual] = new StringValue("false");

                string       deleteVirtualFileMsg = string.Format("是否要删除 '{0}' 的虚拟设备标志文件?", deviceDisplayName);
                DialogResult del = MessageBox.Show(deleteVirtualFileMsg, caption, MessageBoxButtons.YesNo);
                if (del == DialogResult.Yes)
                {
                    File.Delete(virtualDeviceFlagFile);
                }
            }
        }
Beispiel #6
0
        private bool RunDevice(DeviceRunContext context)
        {
            string path = GetDeviceConfigPath(context.DeviceName, context.Version);

            if (Directory.Exists(path))
            {
                string deviceCfgFile = string.Format("{0}\\{1}", path, DeviceConfigFile);
                // TODO: Config file reading
                if (deviceCfgFile != null)
                {
                    DeviceEntry entry = DeviceEntry.GetDeviceEntry(context.DeviceName, deviceCfgFile);
                    this.CheckVirtualDevice(entry, deviceCfgFile);
                    Device device = Load(entry);
                    if (device != null)
                    {
                        context.Device = device;

                        // Set thread-sync-context
                        device.SynchronizationContext = context.SynchronizationContext;
                        // Set data-received callback
                        device.DataReceived += context.Callback;

                        string address         = this.GetCOMPort(entry);
                        string deviceLoadedStr = string.Format("Device: '{0}' Loaded @ '{1}'", entry[DeviceEntry.Identity], address);
                        RecordManager.DoSystemEventRecord(device, deviceLoadedStr);

                        device.Start(address);
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #7
0
 private string GetCOMPort(DeviceEntry entry)
 {
     if (entry.Contains(DeviceEntry.SerialPort))
     {
         return((StringValue)entry[DeviceEntry.SerialPort]);
     }
     return(string.Empty);
 }
Beispiel #8
0
        protected override object BuildSettings(DeviceEntry entry)
        {
            AisSettings settings = new AisSettings();

            settings.Factor    = (StringValue)entry["factor1"];
            settings.Frequence = (StringValue)entry[DeviceEntry.RecordInterval];
            return(settings);
        }
Beispiel #9
0
 public static DeviceJson From(DeviceEntry entry)
 {
     return(new DeviceJson
     {
         devicePath = entry.devicePath,
         isOptional = entry.isOptional,
     });
 }
Beispiel #10
0
 public void initDevices()
 {
     devices = new DeviceEntry[bandsCount][];
     for (int co = 0; co < bandsCount; co++)
     {
         devices[co] = new DeviceEntry[2];
     }
 }
Beispiel #11
0
        protected override object BuildSettings(DeviceEntry entry)
        {
            WeatherSettings settings = new WeatherSettings();

            settings.SerialPort = (StringValue)entry[DeviceEntry.SerialPort];
            settings.Frequence  = (StringValue)entry[DeviceEntry.RecordInterval];
            return(settings);
        }
Beispiel #12
0
 public WeatherDevice(DeviceEntry entry)
 {
     this.entry = entry;
     if (!this.Initialize(entry))
     {
         string initFailedEvent = string.Format("Device '{0}' initialized failed. Error is {1}.", entry[DeviceEntry.Identity], error);
         RecordManager.DoSystemEventRecord(this, initFailedEvent);
     }
 }
Beispiel #13
0
 protected override object BuildSettings(DeviceEntry entry)
 {
     NaISettings settings = new NaISettings();
     settings.DeviceSn = (StringValue)entry[DeviceEntry.DeviceSn];
     settings.Frequence = (StringValue)entry[DeviceEntry.RecordInterval];
     settings.MinuteAdjust = (StringValue)entry["MinuteAdjust"];
     settings.IPAddress = (StringValue)entry[DeviceEntry.IPAddress];
     return settings;
 }
Beispiel #14
0
        public IReadOnlyCollection <DeviceEntry> Commit(IEnumerable <long> deviceIds)
        {
            if (!deviceIds.Any())
            {
                return(new List <DeviceEntry>());
            }

            var dataTable = new DataTable("DeviceIdTable");

            dataTable.Columns.Add("DeviceId", typeof(long));

            foreach (var deviceId in deviceIds)
            {
                var dataRow = dataTable.NewRow();
                dataRow[0] = deviceId;
                dataTable.Rows.Add(dataRow);
            }

            using (var sqlConnection = new SqlConnection(_connectionString))
            {
                sqlConnection.Open();

                using (var sqlCommand = new SqlCommand("Commit", sqlConnection))
                {
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.Parameters.Add(new SqlParameter("@CommitItems", dataTable));

                    var deviceEntries = new List <DeviceEntry>();

                    using (var reader = sqlCommand.ExecuteReader())
                    {
                        var colDeviceId     = reader.GetOrdinal("DeviceId");
                        var colDequeueIndex = reader.GetOrdinal("DequeueIndex");
                        var colEnqueueIndex = reader.GetOrdinal("EnqueueIndex");
                        var colPeek         = reader.GetOrdinal("Peek");
                        var colVersion      = reader.GetOrdinal("Version");

                        while (reader.Read())
                        {
                            var deviceEntry = new DeviceEntry
                            {
                                Id           = (long)reader[colDeviceId],
                                DequeueIndex = (int)reader[colDequeueIndex],
                                EnqueueIndex = (int)reader[colEnqueueIndex],
                                Peek         = (bool)reader[colPeek],
                                Version      = (int)reader[colVersion]
                            };

                            deviceEntries.Add(deviceEntry);
                        }
                    }

                    return(deviceEntries);
                }
            }
        }
Beispiel #15
0
        protected override object BuildSettings(DeviceEntry entry)
        {
            HpicSettings settings = new HpicSettings();

            settings.SerialPort = (StringValue)entry[DeviceEntry.SerialPort];
            settings.Frequence  = (StringValue)entry[DeviceEntry.RecordInterval];
            settings.Factor     = (StringValue)entry["factor1"];
            settings.AlarmValue = (StringValue)entry[DeviceEntry.Alarm1];
            return(settings);
        }
Beispiel #16
0
        protected string GetValue(DeviceEntry entry, string entryName, string defaultValue)
        {
            IValue v = entry[entryName];

            if (v != null)
            {
                return((StringValue)v);
            }
            return(defaultValue);
        }
Beispiel #17
0
        protected void SetDataParserFactors(DataParser dataParser, DeviceEntry entry)
        {
            int    i = 0;
            double v = 0.0;

            while (Device.GetFactor(entry, ++i, out v))
            {
                dataParser.Factors.Add(v);
            }
        }
Beispiel #18
0
 private void dgvDevices_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex > 0 && e.RowIndex > -1)
     {
         DeviceEntry de = appConf.devices[e.RowIndex][e.ColumnIndex - 1];
         if (de != null && de.index != -1)
         {
             Process.Start(appConf.rotatorPaths[de.programType] + "//" + exeNames[de.programType], de.index.ToString());
         }
     }
 }
Beispiel #19
0
 private byte[] GetExampleLine(int rand = 0)
 {
     if (this.actionSendInHex)
     {
         return(DeviceEntry.ParseHex(this.exampleLine));
     }
     else
     {
         return(Encoding.ASCII.GetBytes(this.exampleLine));
     }
 }
Beispiel #20
0
        protected override object BuildSettings(DeviceEntry entry)
        {
            ShelterSettings settings = new ShelterSettings();

            settings.SerialPort = (StringValue)entry[DeviceEntry.SerialPort];
            settings.Frequence  = (StringValue)entry[DeviceEntry.RecordInterval];
            string sensitive = (StringValue)entry[DeviceEntry.Sensitive];

            settings.Sensitive = (sensitive == "true");
            return(settings);
        }
Beispiel #21
0
    public void Register(Device device, ITemperatureWriter temperatureWriter)
    {
        var entry = new DeviceEntry(
            device: device,
            temperatureWriter: temperatureWriter
            );

        if (!_devices.TryAdd(device.Id, entry))
        {
            throw new ArgumentException("device already registered");
        }
    }
Beispiel #22
0
        protected object Reset()
        {
            string deviceKey = this.GetDeviceKey();

            Debug.Assert(deviceKey != null);
            string      filePath = Program.GetDeviceConfigFile(deviceKey);
            DeviceEntry entry    = DeviceEntry.GetDeviceEntry(deviceKey, filePath);
            object      settings = this.BuildSettings(entry);

            this.UpdateSettings(settings);
            return(settings);
        }
Beispiel #23
0
        private void autoDeviceRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (autoDeviceRadioButton.Checked)
            {
                DeviceEntry autoDev = engineMgr.GetBestDevice();
                if (autoDev != null)
                {
                    deviceComboBox.SelectedItem = autoDev;
                }

                deviceComboBox.Enabled = false;
            }
        }
Beispiel #24
0
        public IReadOnlyCollection <DeviceEntry> Commit(IEnumerable <long> deviceIds)
        {
            if (!deviceIds.Any())
            {
                return(new List <DeviceEntry>());
            }

            using (var connection = new NpgsqlConnection(_connectionString))
            {
                connection.Open();

                using (var command = new NpgsqlCommand("commit", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    var commitItemsJsonSource = deviceIds.Select(item => new CommitData {
                        deviceid = item
                    }).ToList();
                    var messages = new NpgsqlParameter("commititemsjson", NpgsqlDbType.Json);
                    messages.Value = JsonConvert.SerializeObject(commitItemsJsonSource);
                    command.Parameters.Add(messages);

                    var deviceEntries = new List <DeviceEntry>();

                    using (var reader = command.ExecuteReader())
                    {
                        var colDeviceId     = reader.GetOrdinal("deviceid");
                        var colDequeueIndex = reader.GetOrdinal("dequeueindex");
                        var colEnqueueIndex = reader.GetOrdinal("enqueueindex");
                        var colPeek         = reader.GetOrdinal("peek");
                        var colVersion      = reader.GetOrdinal("version");

                        while (reader.Read())
                        {
                            var deviceEntry = new DeviceEntry
                            {
                                Id           = (long)reader[colDeviceId],
                                DequeueIndex = (int)reader[colDequeueIndex],
                                EnqueueIndex = (int)reader[colEnqueueIndex],
                                Peek         = (bool)reader[colPeek],
                                Version      = (int)reader[colVersion]
                            };

                            deviceEntries.Add(deviceEntry);
                        }
                    }

                    return(deviceEntries);
                }
            }
        }
Beispiel #25
0
        public static bool GetFactor(DeviceEntry entry, int i, out double v)
        {
            v = 0.0;
            string factor = string.Format("factor{0}", i);
            string s      = (StringValue)entry[factor];

            if (s != null && s.Length > 0)
            {
                if (double.TryParse(s, out v))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #26
0
        private void setDevEntry(int band, int devType, DeviceEntry de)
        {
            appConf.devices[band][devType] = de;
            DeviceRow dr = blDevices[band];

            if (devType == 0)
            {
                dr.run = de.name;
            }
            else
            {
                dr.run2 = de.name;
            }
            blDevices.ResetItem(band);
        }
Beispiel #27
0
        private void btnConnAIS_Click(object sender, EventArgs e)
        {
            DeviceEntry entry = new DeviceEntry();

            entry[DeviceEntry.Name]     = new StringValue("AIS");
            entry[DeviceEntry.Identity] = new StringValue("Scada.AIS");
            entry[DeviceEntry.Path]     = new StringValue("");
            entry[DeviceEntry.Version]  = new StringValue("0.9");

            entry["IPADDR"] = new StringValue("192.168.0.6");
            this.aisDevice  = new AISDevice(entry);
            this.aisDevice.Start("S7200.OPCServer");

            this.aisDevice.Send(Encoding.ASCII.GetBytes("connect"), default(DateTime));
        }
Beispiel #28
0
        private void deviceComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            DeviceEntry selDevice = deviceComboBox.SelectedItem as DeviceEntry;

            if (selDevice != null)
            {
                hardwareTypeValueLabel.Text = selDevice.Api;
                performanceValueLabel.Text  = selDevice.PerformanceRating.ToString("F1");
            }
            else
            {
                hardwareTypeValueLabel.Text = "";
                performanceValueLabel.Text  = "";
            }
        }
Beispiel #29
0
        // POST api/values
        public void Post([FromBody] DeviceDataEntry value)
        {
            var entry = new DeviceEntry
            {
                id                = Guid.NewGuid(),
                dataType          = value.DataType,
                value             = value.Value,
                direction         = value.Direction,
                sourceDescription = value.SourceDescription,
                sourceId          = value.SourceId,
                timestamp         = DateTime.Now
            };

            Context.DeviceEntries.Add(entry);
            Context.SaveChanges();
        }
Beispiel #30
0
        // Initialize the device
        private void Initialize(DeviceEntry entry)
        {
            this.Name             = entry[DeviceEntry.Name].ToString();
            this.DeviceConfigPath = entry[DeviceEntry.Path].ToString();
            this.Version          = entry[DeviceEntry.Version].ToString();
            this.Id = entry[DeviceEntry.Identity].ToString();

            this.strFileMonitoringPath = (StringValue)entry["FileMonitoringPath"];
            this.strFileCopy2Path      = (StringValue)entry["FileCopy2Path"];
            this.strSidPath            = (StringValue)entry["SIDPath"];
            this.strActionInterval     = (StringValue)entry[DeviceEntry.ActionInterval];

            string tableName   = (StringValue)entry[DeviceEntry.TableName];
            string tableFields = (StringValue)entry[DeviceEntry.TableFields];

            this.InitializeHPGeTable(tableName, tableFields, out this.insertIntoCommand);
        }