Пример #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
        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
 public OpcManager()
 {
     AnOPCServer = new OPCAutomation.OPCServer();
     ConnectedOPCServer = new OPCAutomation.OPCServer();
 }
Пример #9
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;
        }
Пример #10
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;
         }
     }
 }