コード例 #1
0
        public void Attach(NativeOpcServer server, string serverAddress)
        {
            try
            {
                _group = server.OPCGroups.Add(Address);
            }
            catch (Exception ex)
            {
                _group = null;
                this.Error($"{Id}连接失败,错误原因{ex}");
                throw;
            }

            this.InfoSuccess($"连接");

            if (_group == null)
            {
                return;
            }

            _group.IsActive = true;
            _group.OPCItems.DefaultIsActive = true;
            _group.IsSubscribed             = true;
            _group.UpdateRate = 100;

            foreach (var item in OpcItems)
            {
                item.Attach(serverAddress, _group);
                _opcItemsLookupTable.Add(item.ClientHandle, item);
            }

            _group.DataChange += DataChange;
        }
コード例 #2
0
        public List <string> GetOpcServerList()
        {
            List <string> serverlist = new List <string>();

            try
            {
                // Create a temporary OPCServer object and use it to get the list of
                // available OPC Servers
                AnOPCServer = new OPCAutomation.OPCServer();

                // Obtain the list of available OPC servers
                object AllOPCServers = null;
                AllOPCServers = AnOPCServer.GetOPCServers();

                // Load the list returned into the List box for user selection
                int i = 0;

                for (i = Microsoft.VisualBasic.Information.LBound((System.Array)AllOPCServers, 1); i <= Information.UBound((System.Array)AllOPCServers, 1); i++)
                {
                    serverlist.Add(((System.Array)AllOPCServers).GetValue(i).ToString());
                }

                // Release the temporary OPCServer object now that we're done with it
                AnOPCServer = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show("List OPC servers failed with exception: " + ex.Message, "SimpleOPCInterface Exception", MessageBoxButtons.OK);
            }

            return(serverlist);
        }
コード例 #3
0
        public void OPCServerConnect(string servername, string nodename)
        {
            //If InStr(OPCServerName, "Click") = 0 Then
            try
            {
                ConnectedOPCServer = new OPCAutomation.OPCServer();
                ConnectedOPCServer.Connect(servername, nodename);

                this.OPCServerName = servername;
                this.OPCNodeName   = nodename;
            }
            catch (Exception ex)
            {
                ConnectedOPCServer = null;
                MessageBox.Show("OPC server connect failed with exception: " + ex.Message, "SimpleOPCInterface Exception", MessageBoxButtons.OK);
            };
        }
コード例 #4
0
        public Context()
        {
            //var type=Type.GetTypeFromProgID("OPC.Automation");
            //var type = Type.GetTypeFromCLSID(new Guid("28E68F9A-8D75-11D1-8DC3-3C302A000000"));
            //_opcServer = Activator.CreateInstance(type);
            _opcServer = new OPCAutomation.OPCServerClass();
            opcConnctionChangedEvent += Station_opcConnctionChangedEvent;

            /*
             * if (!connectOPCAsync().Result)
             * {
             *  throw new Exception("连接不上opc,请检查配置");
             * }
             */
            connectOPCAsync();
            EventPushList.ForEach(pl => pl.setReNewValueCallBack(new Func <IValuesChanged <IComparable>, bool>(clientChangedValue)));
        }
コード例 #5
0
 public void DisConnectServer()
 {
     if (ConnectedOPCServer != null)
     {
         try
         {
             ConnectedOPCServer.Disconnect();
         }
         catch (Exception ex)
         {
             MessageBox.Show("OPC server disconnect failed with exception: " + ex.Message, "SimpleOPCInterface Exception", MessageBoxButtons.OK);
         }
         finally
         {
             ConnectedOPCServer = null;
         }
     }
 }
コード例 #6
0
 public OpcManager()
 {
     AnOPCServer        = new OPCAutomation.OPCServer();
     ConnectedOPCServer = new OPCAutomation.OPCServer();
 }
コード例 #7
0
ファイル: OpcManager.cs プロジェクト: noseii/powerscada2011
        public void OPCServerConnect(string servername,string nodename)
        {
            //If InStr(OPCServerName, "Click") = 0 Then
            try
            {

                ConnectedOPCServer = new OPCAutomation.OPCServer();
                ConnectedOPCServer.Connect(servername, nodename);

                this.OPCServerName=servername;
                this.OPCNodeName = nodename;
            }
            catch (Exception ex)
            {
                ConnectedOPCServer = null;
                MessageBox.Show("OPC server connect failed with exception: " + ex.Message, "SimpleOPCInterface Exception", MessageBoxButtons.OK);
            };
        }
コード例 #8
0
ファイル: OpcManager.cs プロジェクト: noseii/powerscada2011
 public OpcManager()
 {
     AnOPCServer = new OPCAutomation.OPCServer();
     ConnectedOPCServer = new OPCAutomation.OPCServer();
 }
コード例 #9
0
ファイル: OpcManager.cs プロジェクト: noseii/powerscada2011
        public List<string> GetOpcServerList()
        {
            List<string> serverlist = new List<string>();
            try
            {

                // Create a temporary OPCServer object and use it to get the list of
                // available OPC Servers
                AnOPCServer = new OPCAutomation.OPCServer();

                // Obtain the list of available OPC servers
                object AllOPCServers = null;
                AllOPCServers = AnOPCServer.GetOPCServers();

                // Load the list returned into the List box for user selection
                int i = 0;

                for (i = Microsoft.VisualBasic.Information.LBound((System.Array)AllOPCServers, 1); i <= Information.UBound((System.Array)AllOPCServers, 1); i++)
                {
                    serverlist.Add(((System.Array)AllOPCServers).GetValue(i).ToString());
                }

                // Release the temporary OPCServer object now that we're done with it
                AnOPCServer = null;

            }
            catch (Exception ex)
            {

                MessageBox.Show("List OPC servers failed with exception: " + ex.Message, "SimpleOPCInterface Exception", MessageBoxButtons.OK);
            }

               return serverlist;
        }
コード例 #10
0
ファイル: OpcManager.cs プロジェクト: noseii/powerscada2011
 public void DisConnectServer()
 {
     if (ConnectedOPCServer != null)
     {
         try
         {
             ConnectedOPCServer.Disconnect();
         }
         catch (Exception ex)
         {
             MessageBox.Show("OPC server disconnect failed with exception: " + ex.Message, "SimpleOPCInterface Exception", MessageBoxButtons.OK);
         }
         finally
         {
             ConnectedOPCServer = null;
         }
     }
 }