Exemple #1
0
        public static string GetAlarmCacheString(IO_DEVICE device, out List <IO_PARAALARM> alarms)
        {
            alarms = new List <IO_PARAALARM>();

            IODeviceParaMaker paraMaker   = new IODeviceParaMaker();
            string            alarmString = "";

            for (int i = 0; i < device.IOParas.Count; i++)
            {
                try
                {
                    IO_PARAALARM alarm = paraMaker.MakeAlarm(device.IOParas, device.IOParas[i], device.IOParas[i].IORealData, device.IO_DEVICE_LABLE);
                    if (alarm != null && !string.IsNullOrEmpty(alarm.IO_ALARM_DATE))
                    {
                        alarmString += "^" + alarm.GetCommandString();
                        alarms.Add(alarm);
                    }
                }
                catch
                {
                    continue;
                }
            }
            return(alarmString);
        }
Exemple #2
0
        private void RunSimulator()
        {
            Task.Run(() => {
                try
                {
                    for (int d = 0; d < Devices.Count; d++)
                    {
                        try
                        {
                            Scada.Model.IO_DEVICE Device = Devices[d];
                            TaskManager.Add(
                                Task.Run(delegate
                            {
                                //将新值写入数据库
                                while (IsSimulator)
                                {
                                    Task.Run(() =>
                                    {
                                        Device.GetedValueDate = DateTime.Now;
                                        ///重新赋值
                                        for (int i = 0; i < Device.IOParas.Count; i++)
                                        {
                                            Device.IOParas[i].IORealData = new Scada.IOStructure.IOData()
                                            {
                                                ParaName = Device.IOParas[i].IO_NAME, ParaValue = random.Next(5000, 9000).ToString(), QualityStamp = Scada.IOStructure.QualityStamp.GOOD, Date = Device.GetedValueDate.Value
                                            };
                                        }
                                        ///将接收到的数据存储到当前缓存

                                        IOCenterManager.InfluxDbManager.DbWrite_RealPoints(new List <Scada.Model.IO_DEVICE>()
                                        {
                                            Device
                                        }, DateTime.Now);
                                        if (SimulatorForm != null)
                                        {
                                            SimulatorForm.AddLog(Device.IO_DEVICE_NAME + " IO点插入了模拟数据成功");
                                        }

                                        if (IsMakeAlarm)
                                        {
                                            IODeviceParaMaker paraMaker = new IODeviceParaMaker();
                                            List <IO_PARAALARM> alarms  = new List <IO_PARAALARM>();

                                            for (int i = 0; i < Device.IOParas.Count; i++)
                                            {
                                                try
                                                {
                                                    IO_PARAALARM alarm = paraMaker.MakeAlarm(Device.IOParas, Device.IOParas[i], Device.IOParas[i].IORealData, Device.IO_DEVICE_LABLE);
                                                    if (alarm != null)
                                                    {
                                                        IOCenterManager.InfluxDbManager.DbWrite_AlarmPoints(alarm.IO_SERVER_ID, alarm.IO_COMM_ID, alarm, DateTime.Now);
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    this.SimulatorForm.AddLog("ERROR20003" + ex.Message);
                                                }
                                            }
                                        }
                                    });

                                    if (SimulatorForm != null && SimulatorForm.IsCustomTimer)
                                    {
                                        Thread.Sleep(Interval * 1000);
                                    }
                                    else
                                    {
                                        Thread.Sleep(Device.IO_DEVICE_UPDATECYCLE * 1000);
                                    }
                                }
                            }));
                        }
                        catch (Exception ex)
                        {
                            if (SimulatorForm != null)
                            {
                                SimulatorForm.AddLog(ex.Message);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SimulatorForm.AddLog(ex.Message);
                    ColseSimulator();
                }
            });
        }