示例#1
0
        public static void  UserLogin(string user, string password)
        {
            STATION_TCP_INFO loginInfo = new STATION_TCP_INFO();

            loginInfo.USER         = user;
            loginInfo.PASSWROD     = password;
            loginInfo.IO_SERVER_ID = MonitorDataBaseModel.ServerID;
            loginInfo.IO_SERVER_IP = "";
            loginInfo.RESULT       = "false";
            loginInfo.FUNCTION     = "IOMonitor";
            Scada.AsyncNetTcp.TcpData tcpData = new Scada.AsyncNetTcp.TcpData();
            byte[] loginbytes = tcpData.StringToTcpByte(loginInfo.GetCommandString(), Scada.AsyncNetTcp.ScadaTcpOperator.登录);
            //发送登录命令
            TcpClient.Send(new ArraySegment <byte>(loginbytes));
        }
示例#2
0
        public static bool LoginManager(string user, string password)
        {
            STATION_TCP_INFO loginInfo = new STATION_TCP_INFO();

            loginInfo.USER         = user;
            loginInfo.PASSWROD     = password;
            loginInfo.IO_SERVER_ID = "";
            loginInfo.IO_SERVER_IP = "";
            loginInfo.RESULT       = "false";
            loginInfo.FUNCTION     = "IOFlow";
            Scada.AsyncNetTcp.TcpData tcpData = new Scada.AsyncNetTcp.TcpData();
            byte[] loginbytes = tcpData.StringToTcpByte(loginInfo.GetCommandString(), Scada.AsyncNetTcp.ScadaTcpOperator.流程设计器登录);
            //发送登录命令
            TcpClient.Send(new ArraySegment <byte>(loginbytes));
            return(false);
        }
示例#3
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)
                    {
                        DisplayException(new Exception("ERR80014" + 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)
                        {
                            if (OnPublishProject != null)
                            {
                                OnPublishProject(c, false, "发布失败");
                            }
                            return;
                        }

                        try
                        {
                            string IO_SERVER_ID = tcpData.GetItemValue("IO_SERVER_ID");
                            string RESULT       = tcpData.GetItemValue("RESULT");
                            string MSG          = tcpData.GetItemValue("MSG");
                            //判断是否已经存在有发布的采集站工程

                            if (RESULT == "true")
                            {
                                if (OnPublishProject != null)
                                {
                                    OnPublishProject(c, true, MSG);
                                }
                            }
                            else
                            {
                                if (OnUserLogined != null)
                                {
                                    OnPublishProject(c, false, MSG);
                                }
                            }
                        }
                        catch
                        {
                            if (OnPublishProject != null)
                            {
                                OnPublishProject(c, false, "发布失败");
                            }
                            return;
                        }

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

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

                    System.Array.Copy(receivebytes, 1, narra, 0, count - 1);
                    tcpData.BytesToTcpItem(narra);

                    if (OnPublishProjectFault != null)
                    {
                        OnPublishProjectFault(c, false, tcpData.GetItemValue("MSG"));
                    }
                }
                break;

                case ScadaTcpOperator.发布工程成功:    //接收到服务器端更新采集站中报警配置通知
                {
                    AddLog("发布采集站工程成功,请重新启动采集服务!");
                    TcpData tcpData = new TcpData();
                    byte[]  narra   = new byte[count - 1];

                    System.Array.Copy(receivebytes, 1, narra, 0, count - 1);
                    tcpData.BytesToTcpItem(narra);

                    if (this.OnPublishProjectSuccess != null)
                    {
                        OnPublishProjectSuccess(c, true, "发布采集站工程成功,请重新启动采集服务");
                    }
                }
                break;

                case ScadaTcpOperator.发布工程进度:
                {
                    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;
                    }
                    //显示服务器端更新进度
                    AddLog(tcpData.GetItemValue("MSG") + "  " + tcpData.GetItemValue("PROCESS"));
                }
                break;

                case ScadaTcpOperator.发布工程数据传输进度:
                {
                    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;
                    }
                    int index = int.Parse(tcpData.GetItemValue("PROCESS"));        //请求的数据
                    //显示服务器端更新进度
                    AddLog(tcpData.GetItemValue("MSG") + "  正在发送第" + tcpData.GetItemValue("PROCESS") + "条数据");
                    if (OnPublishing != null)
                    {
                        OnPublishing(c, index, tcpData.GetItemValue("MSG"));
                    }
                }
                break;

                case ScadaTcpOperator.重新启动:
                    break;
                }
            }
            #endregion
        }
示例#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
        }
示例#5
0
 public TcpClientEx(string hostname, int port) : base(hostname, port)
 {
     LogUser = null;
 }
示例#6
0
 public TcpClientEx(IPEndPoint port) : base(port)
 {
     LogUser = null;
 }
示例#7
0
 public TcpClientEx() : base()
 {
     LogUser = null;
 }
示例#8
0
 public TcpClientEx(AddressFamily add) : base(add)
 {
     LogUser = null;
 }