Ejemplo n.º 1
0
        private static void LoadTestHandler()
        {
            string[] tags = new string[_tags.Count];
            _tags.Keys.CopyTo(tags, 0);

            OPCServiceClient.OPCServiceClient client = new OPCServiceClient.OPCServiceClient(_server, _port);
            if (client.Connect())
            {
                while (true)
                {
                    Random rand = new Random();
                    int    n    = rand.Next(0, tags.Length);
                    string tag  = tags[n];

                    if (DateTime.Now.Second % 2 == 0)
                    {
                        string value = client.GetValue(tag);
                        Console.WriteLine("read " + tag + "=" + value);
                    }
                    else
                    {
                        string value = (DateTime.Now.Millisecond).ToString();
                        client.SetValue(tag, value);
                        Console.WriteLine("write " + tag + "=" + value);
                    }

                    Thread.Sleep(_gap);
                }
            }
            else
            {
                Console.WriteLine("无法连接服务器");
            }
        }
        public string GetValue(string blockName)
        {
            if (!this.Connected)
            {
                throw new Exception("还未连接到OPC服务");
            }

            FlashLamp();
            return(_client.GetValue(blockName));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            OPCServiceClient.OPCServiceClient client = new OPCServiceClient.OPCServiceClient("127.0.0.1", 9100);

            client.BadBlockDetected += Client_BadBlockDetected;
            if (client.Connect())
            {
                client.SetValue("tag1", "1");
                string tagValue1 = client.GetValue("tag1");

                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("tag2", "20");
                dic.Add("tag3", "0");
                client.SetValues(dic);

                dic = client.GetValues(new List <string>()
                {
                    "tag2", "tag3"
                });
                client.Disconnect();
            }
        }