static void Browser() { OPCBrowser browser = _opcServer.CreateBrowser(); OPCNamespaceTypes type = (OPCNamespaceTypes)(browser.Organization); PrintInfo("browser Type", type.ToString()); browser.ShowBranches(); for (int i = 1; i <= browser.Count; i++) { Console.WriteLine(browser.Item(i)); browser.MoveDown(browser.Item(i)); browser.ShowBranches(); for (int j = 1; j <= browser.Count; j++) { Console.WriteLine(string.Format(" {0}", browser.Item(j))); browser.MoveDown(browser.Item(j)); browser.ShowLeafs(); for (int k = 1; k <= browser.Count; k++) { Console.WriteLine(string.Format(" {0} ItemID = {1}", browser.Item(k), browser.GetItemID(browser.Item(k)))); } } } }
private void browseBranch(Branch Parent) { _OPCBrowser.ShowBranches(); if (_OPCBrowser.Count > 0) { for (int i = 1; i <= _OPCBrowser.Count; i++) { _OPCBrowser.MoveDown(_OPCBrowser.Item(i)); //string BranchName = _OPCBrowser.CurrentPosition; //while(BranchName.Contains(".")) //{ // BranchName = BranchName.Substring(_OPCBrowser.CurrentPosition.IndexOf(".") + 1); //} Branch b = new Branch(Name: _OPCBrowser.CurrentPosition, Server: this._OPCServer, Parent: Parent); browseBranch(b); browseLeaf(b); _OPCBrowser.MoveUp(); _OPCBrowser.ShowBranches(); } } }
/// <summary> /// 展开OPC服务器的节点 /// </summary> /// <param name="opcServer">OPC服务器</param> /// <returns>返回展开后的节点数据</returns> public List <string> RecurBrowse() { OPCBrowser opcBrowser = opcServer.CreateBrowser(); //展开分支 opcBrowser.ShowBranches(); //展开叶子 opcBrowser.ShowLeafs(true); List <string> browserNames = new List <string>(); for (int i = 1; i <= opcBrowser.Count; i++) { browserNames.Add(opcBrowser.Item(i)); } return(browserNames); }
/// <summary> /// 读取所有的标签值 /// </summary> /// <returns></returns> private static bool readallitem() { try { if (connected == true) { opcb = OPC_server.CreateBrowser(); opcb.ShowLeafs(true); for (int i = 1; i < opcb.Count + 1; i++) { allitem.Add(opcb.Item(i)); } return(true); } allitem = null; return(false); } catch (Exception ex) { connected = false; MessageBox.Show("获取标签列表失败\n" + ex.Message); return(false); } }
public void GetOPCTags(OPCType opc, bool SyncData) { string server = ""; string filter1 = ""; string filter2 = ""; string sep = ""; string device = ""; type = opc; switch (type) { case OPCType.Kepware: server = "Kepware.KEPServerEX.V6"; filter1 = "A3*"; filter2 = "R*"; sep = "."; device = "KEPWARE"; break; case OPCType.Matrikon: server = "Matrikon.OPC.AllenBradleyPLCs.1"; filter1 = "A3*"; filter2 = ""; sep = ":"; device = "MATRIKON"; break; } Plcs.Clear(); this.Sync = SyncData; List <string> sChannels = new List <string>(); oServer.Connect(server); oServer.OPCGroups.DefaultGroupIsActive = true; int iChannels; oGroup = oServer.OPCGroups.Add(sGroup); oGroup.IsSubscribed = true; oGroup.OPCItems.DefaultIsActive = true; oGroup.AsyncReadComplete += OCPCallBack; oBrowser = oServer.CreateBrowser(); oBrowser.Filter = filter1; oBrowser.ShowBranches(); iChannels = oBrowser.Count; for (int i = 0; i < iChannels; i++) { sChannels.Add(oBrowser.Item(i + 1)); } foreach (string sChannel in sChannels) { oBrowser.MoveDown(sChannel); oBrowser.Filter = filter2; oBrowser.ShowBranches(); for (int j = 0; j < oBrowser.Count; j++) { this.AddPLC(sChannel + sep + oBrowser.Item(j + 1), device); } oBrowser.MoveUp(); } }
private void GetDelimiter() { //OPCNamespaceTypes Organization = (OPCNamespaceTypes)oPCBrowser.Organization; //Console.WriteLine("Organization is: " + Organization); //if (Organization == OPCNamespaceTypes.OPCHierarchical) //{ //Console.WriteLine("Organization is: Hierarchical"); //} //else if (Organization == OPCNamespaceTypes.OPCFlat) //{ //Console.WriteLine("Organization is: Flat"); //} //string CurrentPosition = oPCBrowser.CurrentPosition; //Console.WriteLine("CurrentPosition is: " + CurrentPosition); //oPCBrowser.ShowBranches(); //oPCBrowser.ShowLeafs(true); //for (int i = 1; i <= oPCBrowser.Count; i++) //{ //string name = oPCBrowser.Item(i); //Console.WriteLine("name is: " + name); //if (name != "") //{ //foreach(char c in name){ //if (IsCharAlphaNumeric(c)) //{ //if (c.IsSymbol()) //{ //Delimiter = c.ToString(); //return; ////break; //} //} //} //} //} string root = ""; string name; oPCBrowser.ShowBranches(); if (oPCBrowser.Count >= 1) { root = oPCBrowser.Item(1); Console.WriteLine("root is: " + root); if (root != "") { oPCBrowser.ShowLeafs(true); for (int i = 1; i <= oPCBrowser.Count; i++) { name = oPCBrowser.Item(i); Console.WriteLine("name is: " + name); if (name != "") { if (root != name) { // pos 应该是0 int pos = name.IndexOf(root); string delimier = name.Substring(root.Length, 1); Console.WriteLine("delimier is: " + delimier); if (!Char.IsLetterOrDigit(System.Convert.ToChar(delimier))) { Delimiter = delimier; return; //break; } } else { } } else { } } //foreach ( string x in oPCBrowser) //{ //} } else { } } }