Ejemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Scada.Model.IO_PARA model)
        {
            if (dal.Update(model))
            {
                alarmBll.Update(model.AlarmConfig);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(Scada.Model.IO_PARA model)
 {
     if (dal.Add(model))
     {
         alarmBll.Add(model.AlarmConfig);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <Scada.Model.IO_PARA> DataTableToList(DataTable dt)
        {
            List <Scada.Model.IO_PARA> modelList = new List <Scada.Model.IO_PARA>();

            List <Task> tasks = new List <Task>();

            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                int sid = dt.Rows.Count % 100 == 0 ? (dt.Rows.Count / 100) : (dt.Rows.Count / 100 + 1);
                for (int a = 1; a <= sid; a++)
                {
                    object aa = a.ToString() + "," + sid.ToString();
                    tasks.Add(Task.Run(() =>
                    {
                        int startindex = Convert.ToInt32(aa.ToString().Split(',')[0]);
                        int limitstep  = Convert.ToInt32(aa.ToString().Split(',')[1]);
                        for (int i = (startindex > 1 ? ((startindex - 1) * 100) : 0); i < (startindex == limitstep ? (dt.Rows.Count) : startindex * 100); i++)
                        {
                            Scada.Model.IO_PARA model = dal.DataRowToModel(dt.Rows[i]);
                            if (model != null)
                            {
                                lock (modelList)
                                {
                                    modelList.Add(model);
                                }
                            }
                        }
                    }));
                }
            }



            Task.WaitAll(tasks.ToArray());
            tasks.Clear();
            return(modelList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 传入的是实际的数据包,并不包含头标识和尾标识
        /// </summary>
        /// <param name="receivebytes"></param>
        /// <param name="count"></param>
        /// <param name="c"></param>
        private void SplitReceivePack(byte[] receivebytes, int count, AsyncTcpClient c)
        {
            //将实际字节转化成字符串
            string message = Encoding.UTF8.GetString(receivebytes);

            //心跳包,不做处理
            if (message == c.HeartBeat)
            {
                return;
            }
            #region 处理实际数据体


            byte opeartor = receivebytes[0];


            ScadaTcpOperator operatorEnum = (ScadaTcpOperator)opeartor;
            if (c.IsOperator(opeartor))
            {
                switch (operatorEnum)
                {
                case ScadaTcpOperator.登录反馈:
                {
                    try
                    {
                        #region 处理采集器端登录
                        TcpData tcpData = new TcpData();
                        byte[]  narra   = new byte[count - 1];

                        System.Array.Copy(receivebytes, 1, narra, 0, count - 1);
                        tcpData.BytesToTcpItem(narra);
                        if (tcpData == null)
                        {
                            if (OnUserLogined != null)
                            {
                                OnUserLogined(c, false, "登录失败");
                            }
                            return;
                        }
                        STATION_TCP_INFO loginInfo = new STATION_TCP_INFO();
                        try
                        {
                            loginInfo.IO_SERVER_ID = tcpData.GetItemValue("IO_SERVER_ID");
                            loginInfo.IO_SERVER_IP = tcpData.GetItemValue("IO_SERVER_IP");
                            loginInfo.PASSWROD     = tcpData.GetItemValue("PASSWROD");
                            loginInfo.USER         = tcpData.GetItemValue("USER");
                            loginInfo.RESULT       = tcpData.GetItemValue("RESULT");
                            loginInfo.MSG          = tcpData.GetItemValue("MSG");
                            loginInfo.FUNCTION     = tcpData.GetItemValue("FUNCTION");

                            //判断是否已经存在有发布的采集站工程

                            if (loginInfo.RESULT == "true")
                            {
                                if (OnUserLogined != null)
                                {
                                    OnUserLogined(c, true, loginInfo.MSG);
                                }
                            }
                            else
                            {
                                if (OnUserLogined != null)
                                {
                                    OnUserLogined(c, false, loginInfo.MSG);
                                }
                            }
                        }
                        catch
                        {
                            if (OnUserLogined != null)
                            {
                                OnUserLogined(c, false, "登录失败");
                            }
                            return;
                        }

                        tcpData.Dispose();
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        ThrowExceptionToMain(new Exception("ERR10024" + ex.Message));
                    }
                }
                break;

                case ScadaTcpOperator.更新采集站报警:    //接收到服务器端更新采集站中报警配置通知
                {
                    try
                    {
                        #region 更新采集站报警
                        TcpData tcpData = new TcpData();
                        byte[]  narra   = new byte[count - 1];

                        System.Array.Copy(receivebytes, 1, narra, 0, count - 1);
                        tcpData.BytesToTcpItem(narra);
                        if (tcpData == null)
                        {
                            //解析字符串失败
                            return;
                        }
                        IO_ALARM_CONFIG alarmConfig = new IO_ALARM_CONFIG();
                        try
                        {
                            alarmConfig.IO_ALARM_LEVEL   = tcpData.GetItemValue("IO_ALARM_LEVEL");
                            alarmConfig.IO_ALARM_NUMBER  = int.Parse(tcpData.GetItemValue("IO_ALARM_NUMBER"));
                            alarmConfig.IO_ALARM_TYPE    = tcpData.GetItemValue("IO_ALARM_TYPE");
                            alarmConfig.IO_COMM_ID       = tcpData.GetItemValue("IO_COMM_ID");
                            alarmConfig.IO_CONDITION     = tcpData.GetItemValue("IO_CONDITION");
                            alarmConfig.IO_DEVICE_ID     = tcpData.GetItemValue("IO_DEVICE_ID");
                            alarmConfig.IO_ENABLE_MAX    = int.Parse(tcpData.GetItemValue("IO_ENABLE_MAX"));
                            alarmConfig.IO_ENABLE_MAXMAX = int.Parse(tcpData.GetItemValue("IO_ENABLE_MAXMAX"));
                            alarmConfig.IO_ENABLE_MIN    = int.Parse(tcpData.GetItemValue("IO_ENABLE_MIN"));
                            alarmConfig.IO_ENABLE_MINMIN = int.Parse(tcpData.GetItemValue("IO_ENABLE_MINMIN"));
                            alarmConfig.IO_ID            = tcpData.GetItemValue("IO_ID");
                            alarmConfig.IO_MAXMAX_TYPE   = tcpData.GetItemValue("IO_MAXMAX_TYPE");
                            alarmConfig.IO_MAXMAX_VALUE  = int.Parse(tcpData.GetItemValue("IO_MAXMAX_VALUE"));
                            alarmConfig.IO_MAX_TYPE      = tcpData.GetItemValue("IO_MAX_TYPE");
                            alarmConfig.IO_MAX_VALUE     = int.Parse(tcpData.GetItemValue("IO_MAX_VALUE"));
                            alarmConfig.IO_MINMIN_TYPE   = tcpData.GetItemValue("IO_MINMIN_TYPE");
                            alarmConfig.IO_MINMIN_VALUE  = int.Parse(tcpData.GetItemValue("IO_MINMIN_VALUE"));
                            alarmConfig.IO_MIN_TYPE      = tcpData.GetItemValue("IO_MIN_TYPE");
                            alarmConfig.IO_MIN_VALUE     = int.Parse(tcpData.GetItemValue("IO_MIN_VALUE"));
                            alarmConfig.IO_SERVER_ID     = tcpData.GetItemValue("IO_SERVER_ID");
                            alarmConfig.UPDATE_DATE      = "";
                            alarmConfig.UPDATE_RESULT    = "";
                            alarmConfig.UPDATE_UID       = "";
                        }
                        catch (Exception ex)
                        {
                            ThrowExceptionToMain(new Exception("ERROR20102  " + ex.Message));
                            alarmConfig = null;
                        }

                        if (alarmConfig != null)
                        {
                            if (alarmconfigBll.Update(alarmConfig))
                            {
                                byte[] sendbytes = tcpData.StringToTcpByte(tcpData.TcpItemToString(), ScadaTcpOperator.更新采集站报警反馈);
                                this.Send(new ArraySegment <byte>(sendbytes));
                                IO_DEVICE device = MonitorDataBaseModel.IODevices.Find(x => x.IO_DEVICE_ID == alarmConfig.IO_DEVICE_ID);
                                if (device != null)
                                {
                                    IO_PARA para = device.IOParas.Find(x => x.IO_ID == alarmConfig.IO_ID);
                                    if (para != null)
                                    {
                                        para.AlarmConfig = alarmConfig;
                                        AddLogToMainLog("管理员更新" + device.IO_DEVICE_NAME + "[" + device.IO_DEVICE_LABLE + "]//" + para.IO_NAME + "[" + para.IO_LABEL + "]" + "报警配置成功! ");
                                    }
                                }
                            }
                            else
                            {
                                AddLogToMainLog("管理员更新" + alarmConfig.IO_ID + "报警配置失败! ");
                            }
                        }



                        tcpData.Dispose();
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        ThrowExceptionToMain(new Exception("ERR10029" + ex.Message));
                    }
                }
                break;

                case ScadaTcpOperator.置命令:     //接收到用户要下置命令
                {
                    try
                    {
                        byte[] contentbytes = new byte[receivebytes.Length - 1];
                        System.Array.Copy(receivebytes, 1, contentbytes, 0, receivebytes.Length - 1);
                        TcpData tcpData = new TcpData();
                        tcpData.BytesToTcpItem(contentbytes);
                        IO_COMMANDS command = new IO_COMMANDS()
                        {
                            COMMAND_DATE   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            COMMAND_ID     = tcpData.GetItemValue("COMMAND_ID"),
                            COMMAND_RESULT = tcpData.GetItemValue("COMMAND_RESULT"),
                            COMMAND_USER   = tcpData.GetItemValue("COMMAND_USER"),
                            COMMAND_VALUE  = tcpData.GetItemValue("COMMAND_VALUE"),
                            IO_COMM_ID     = tcpData.GetItemValue("IO_COMM_ID"),
                            IO_DEVICE_ID   = tcpData.GetItemValue("IO_DEVICE_ID"),
                            IO_ID          = tcpData.GetItemValue("IO_ID"),
                            IO_LABEL       = tcpData.GetItemValue("IO_LABEL"),
                            IO_NAME        = tcpData.GetItemValue("IO_NAME"),
                            IO_SERVER_ID   = tcpData.GetItemValue("IO_SERVER_ID")
                        };


                        Scada.Model.IO_COMMUNICATION _COMMUNICATION = MonitorDataBaseModel.IOCommunications.Find(x => x.IO_COMM_ID == command.IO_COMM_ID && command.IO_SERVER_ID == x.IO_SERVER_ID);
                        Scada.Model.IO_DEVICE        device         = MonitorDataBaseModel.IODevices.Find(x => x.IO_COMM_ID == command.IO_COMM_ID && command.IO_SERVER_ID == x.IO_SERVER_ID && x.IO_DEVICE_ID == command.IO_DEVICE_ID);

                        if (_COMMUNICATION != null && device != null)
                        {
                            Scada.Model.IO_PARA para = device.IOParas.Find(x => x.IO_COMM_ID == command.IO_COMM_ID && command.IO_SERVER_ID == x.IO_SERVER_ID && x.IO_DEVICE_ID == command.IO_DEVICE_ID && x.IO_ID == command.IO_ID);
                            if (para == null)
                            {
                                AddLogToMainLog(device.IO_DEVICE_NAME + "[" + device.IO_DEVICE_LABLE + "] 设备下参数 " + para.IO_ID + " " + para.IO_LABEL + " " + para.IO_NAME + " 参数不存在");
                                return;
                            }
                            if (_COMMUNICATION.DriverInfo == null)
                            {
                                AddLogToMainLog("请在采集站中设置该通讯通道驱动!");
                                return;
                            }
                            try
                            {
                                if (_COMMUNICATION.CommunicateDriver == null)
                                {
                                    AddLogToMainLog("请在采集站中设置该通讯通道驱动!");
                                    return;
                                }
                                else
                                {
                                    ((ScadaCommunicateKernel)_COMMUNICATION.CommunicateDriver).IsCreateControl = false;
                                }

                                ScadaCommunicateKernel driverDll = (ScadaCommunicateKernel)_COMMUNICATION.CommunicateDriver;
                                driverDll.SetUIParameter(_COMMUNICATION.IO_COMM_PARASTRING);
                                driverDll.IsCreateControl = false;
                                driverDll.InitKernel(MonitorDataBaseModel.IOServer, _COMMUNICATION, _COMMUNICATION.Devices, _COMMUNICATION.DriverInfo);
                                try
                                {
                                    driverDll.SendCommand(MonitorDataBaseModel.IOServer, _COMMUNICATION, device, para, command.COMMAND_VALUE);
                                    AddLogToMainLog(device.IO_DEVICE_NAME + "[" + device.IO_DEVICE_LABLE + "] 设备下参数 " + para.IO_ID + " " + para.IO_LABEL + " " + para.IO_NAME + " 已经下置成功,下置值" + command.COMMAND_VALUE);
                                }
                                catch (Exception ex)
                                {
                                    ThrowExceptionToMain(new Exception("ERROR600002" + ex.Message));
                                }
                            }
                            catch (Exception ex)
                            {
                                ThrowExceptionToMain(new Exception("ERROR600001" + ex.Message));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ThrowExceptionToMain(new Exception("ERR10030" + ex.Message));
                    }
                }
                break;

                case ScadaTcpOperator.重新启动:
                    break;
                }
            }
            #endregion
        }
Ejemplo n.º 5
0
        public IO_PARA Copy()
        {
            IO_PARA para = new IO_PARA()
            {
                IO_ADDRESS               = this.IO_ADDRESS,
                IO_ALERT_ENABLE          = this.IO_ALERT_ENABLE,
                IO_COMM_ID               = this.IO_COMM_ID,
                IO_DATATYPE              = this.IO_DATATYPE,
                IO_DEVICE_ID             = this.IO_DEVICE_ID,
                IO_ENABLEALARM           = this.IO_ENABLEALARM,
                IO_ENABLERANGECONVERSION = this.IO_ENABLERANGECONVERSION,
                IO_HISTORY               = this.IO_HISTORY,
                IO_ID          = this.IO_ID,
                IO_INITALVALUE = this.IO_INITALVALUE,
                IO_LABEL       = this.IO_LABEL,
                IO_MAXVALUE    = this.IO_MAXVALUE,
                IO_MINVALUE    = this.IO_MINVALUE,
                IO_NAME        = this.IO_NAME,
                IO_ONE         = this.IO_ONE,
                IO_OUTLIES     = this.IO_OUTLIES,
                IO_PARASTRING  = this.IO_PARASTRING,
                IO_POINTTYPE   = this.IO_POINTTYPE,
                IO_RANGEMAX    = this.IO_RANGEMAX,
                IO_RANGEMIN    = this.IO_RANGEMIN,
                IO_SERVER_ID   = this.IO_SERVER_ID,
                IO_SYSTEM      = this.IO_SYSTEM,
                IO_UNIT        = this.IO_UNIT,
                IO_ZERO        = this.IO_ZERO,
                IO_FORMULA     = this.IO_FORMULA,
                IO_DATASOURCE  = this.IO_DATASOURCE
            };


            if (this.IORealData != null)
            {
                para.IORealData = new IOData()
                {
                    BitStoreMode    = this.IORealData.BitStoreMode,
                    CommunicationID = this.IORealData.CommunicationID,
                    datas           = this.IORealData.datas,
                    DataType        = this.IORealData.DataType,
                    Date            = this.IORealData.Date,
                    End             = this.IORealData.End,
                    ID           = this.IORealData.ID,
                    ParaName     = this.IORealData.ParaName,
                    ParaString   = this.IORealData.ParaString,
                    ParaValue    = this.IORealData.ParaValue,
                    QualityStamp = this.IORealData.QualityStamp,
                    ServerID     = this.IORealData.ServerID
                };
            }
            if (this.AlarmConfig != null)
            {
                para.AlarmConfig = new IO_ALARM_CONFIG()
                {
                    IO_ALARM_LEVEL   = this.AlarmConfig.IO_ALARM_LEVEL,
                    IO_ALARM_NUMBER  = this.AlarmConfig.IO_ALARM_NUMBER,
                    IO_ALARM_TYPE    = this.AlarmConfig.IO_ALARM_TYPE,
                    IO_COMM_ID       = this.AlarmConfig.IO_COMM_ID,
                    IO_CONDITION     = this.AlarmConfig.IO_CONDITION,
                    IO_DEVICE_ID     = this.AlarmConfig.IO_DEVICE_ID,
                    IO_ENABLE_MAX    = this.AlarmConfig.IO_ENABLE_MAX,
                    IO_ENABLE_MAXMAX = this.AlarmConfig.IO_ENABLE_MAXMAX,
                    IO_ENABLE_MIN    = this.AlarmConfig.IO_ENABLE_MIN,
                    IO_ENABLE_MINMIN = this.AlarmConfig.IO_ENABLE_MINMIN,

                    IO_ID           = this.AlarmConfig.IO_ID,
                    IO_MAXMAX_TYPE  = this.AlarmConfig.IO_MAXMAX_TYPE,
                    IO_MAXMAX_VALUE = this.AlarmConfig.IO_MAXMAX_VALUE,
                    IO_MAX_TYPE     = this.AlarmConfig.IO_MAX_TYPE,
                    IO_MAX_VALUE    = this.AlarmConfig.IO_MAX_VALUE,
                    IO_MINMIN_TYPE  = this.AlarmConfig.IO_MINMIN_TYPE,
                    IO_MINMIN_VALUE = this.AlarmConfig.IO_MINMIN_VALUE,
                    IO_MIN_TYPE     = this.AlarmConfig.IO_MIN_TYPE,
                    IO_MIN_VALUE    = this.AlarmConfig.IO_MIN_VALUE,
                    IO_SERVER_ID    = this.AlarmConfig.IO_SERVER_ID
                };
            }
            return(para);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 显示最近产生的报警
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>

        #region 加载IO属性
        public static void SetIOPara(Scada.Model.IO_SERVER server, Scada.Model.IO_COMMUNICATION comm, Scada.Model.IO_DEVICE device, Scada.Model.IO_PARA para)
        {
            if (mediator.IOMonitorForm.IsHandleCreated)
            {
                mediator.IOMonitorForm.BeginInvoke(new EventHandler(delegate
                {
                    mediator.IOPropertiesForm.SetPara(server, comm, device, para);
                }));
            }
        }
Ejemplo n.º 7
0
 public static void AppendSendCommand(Scada.Model.IO_SERVER server, Scada.Model.IO_COMMUNICATION communication, Scada.Model.IO_DEVICE device, Scada.Model.IO_PARA para, Scada.Model.IO_COMMANDS command)
 {
     if (mediator == null)
     {
         return;
     }
     mediator.IOMonitorForm.InsertMonitorCommandListView(server, communication, device, para, command);
     Scada.Logger.Logger.GetInstance().Info(command.GetCommandString());
 }