private void RecurBrowse(OPCBrowser oPcBrowser) { //展开分支 oPcBrowser.ShowBranches(); //展开叶子 oPcBrowser.ShowLeafs(true); foreach (object turn in oPcBrowser) { ListBox1.Items.Add(turn.ToString()); } }
/// <summary> /// OPCBrowser遍历组下一层节点,并构建Tree节点 /// </summary> /// <param name="nodeId"></param> public List <OpcNode> ShowBranches(string nodeId = "") { if (nodeId.IsNullOrEmpty()) { //返回根节点,需要顺序执行下列3个函数。 oPCBrowser.MoveTo(oPCBrowser.CurrentPosition.Split('.')); oPCBrowser.ShowLeafs(true); oPCBrowser.MoveToRoot(); } else { oPCBrowser.MoveTo(nodeId.Split('.')); } oPCBrowser.ShowBranches(); List <OpcNode> listNode = Task.Run(() => { List <OpcNode> list = new List <OpcNode>(); foreach (object branch in oPCBrowser) { string key = "ClassIcon"; bool isExpand = false; string branchNodeId = ""; //拼接nodeId if (nodeId.IsNullOrEmpty()) { branchNodeId = branch.ToString(); } else { branchNodeId = nodeId + "." + branch.ToString(); } oPCBrowser.MoveDown(branch.ToString()); oPCBrowser.ShowBranches(); if (oPCBrowser.Count > 0) { isExpand = true; } var child = new OpcNode(branch.ToString(), branchNodeId, key, isExpand); list.Add(child); oPCBrowser.MoveUp(); } return(list); } ).Result; oPCBrowser.MoveToRoot(); return(listNode); }
/// <summary> /// 获取对应的分支点 /// </summary> /// <param name="filter">点名字</param> public List <OpcData> RecurBrowse(string[] filter) { OPCBrowser opcBrowser = _opcSerialInfo.OpcServer.CreateBrowser(); List <OpcData> datas = new List <OpcData>(); //展开分支 opcBrowser.ShowBranches(); //展开叶子 opcBrowser.ShowLeafs(true); foreach (object turn in opcBrowser) { foreach (var r in filter) { if (turn.ToString().ToUpper().Contains(r.ToUpper())) { OpcData data = new OpcData { OpcName = turn.ToString(), OpcValue = "null", OpcTime = DateTime.Now.ToString() }; datas.Add(data); } } } return(datas); }
/// <summary> /// 列出OPC服务端分组下所有标签名称 /// </summary> /// <param name="groupName"></param> public List <string> ShowLeafs(string groupName) { try { leafs = new List <string>(); oPCBrowser.MoveDown(groupName); //oPCBrowser.ShowBranches(); //true 显示父节点 oPCBrowser.ShowLeafs(true); foreach (object turn in oPCBrowser) { if (turn.ToString().Contains("_Hints") || turn.ToString().Contains("_System"))//排除这两项 { } else { leafs.Add(turn.ToString()); } } oPCBrowser.MoveUp(); return(leafs); } catch (Exception) { throw; } }
public List <string> ConnRemoteAndGetRecurBrowse( string remoteServerIP, string remoteServerName) { List <string> rlt = new List <string>(); string connRlt = ConnectRemoteServer(remoteServerIP, remoteServerName); if (connRlt != "") { return(rlt); } OPCBrowser browser = server.CreateBrowser(); // 展开分支 browser.ShowBranches(); // 展开叶子 browser.ShowLeafs(true); foreach (object turn in browser) { string strTurn = turn.ToString(); if (!(strTurn.Contains("._Statistics._") || strTurn.Contains("_System._") || strTurn.Contains("_DataLogger._"))) { rlt.Add(strTurn); } } return(rlt); }
public TKepwareServer(string address, string name) { try { server.Connect(name, address); } catch (Exception error) { Exception err = new Exception( $"无法连接到KEPServer[{name}({address})],[{error.Message}]"); err.Data.Add("ErrCode", 900103); err.Data.Add("ErrText", err.Message); throw err; } this.address = address; this.name = name; OPCBrowser browser = server.CreateBrowser(); browser.ShowBranches(); browser.ShowLeafs(true); foreach (object tag in browser) { devices.Add( address, name, tag.ToString()); } }
private void RecurBrowse(OPCBrowser opcBrowser, string[] filter) { //展开分支 opcBrowser.ShowBranches(); //展开叶子 opcBrowser.ShowLeafs(true); foreach (object turn in opcBrowser) { foreach (var r in filter) { if (turn.ToString().ToUpper().Contains(r.ToUpper())) { OpcData data = new OpcData { OpcName = turn.ToString(), OpcValue = "null", OpcTime = DateTime.Now.ToString() }; Log.Info($"绑定的数据{data.OpcName}"); _bindingData.Add(data); } } } }
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)))); } } } }
/// <summary> /// 展开OPC服务器的节点 /// </summary> /// <param name="opcServer">OPC服务器</param> /// <returns>返回展开后的节点数据</returns> public OPCBrowser RecurBrowse(OPCServer opcServer) { OPCBrowser opcBrowser = opcServer.CreateBrowser(); //展开分支 opcBrowser.ShowBranches(); //展开叶子 opcBrowser.ShowLeafs(true); return(opcBrowser); }
private void LoadDataToTreeFlat(OPCBrowser oPCBrowser, TreeNodeCollection treeNodeCollection, string root) { oPCBrowser.Organization.ToString(); oPCBrowser.ShowBranches(); opcBrowser.ShowLeafs(true); foreach (object turn in opcBrowser) { File.AppendAllText(path, root + "\\" + turn.ToString() + "\r\n", Encoding.UTF8); } }
/// <summary> /// OPC分支展开 /// </summary> /// <param name="oPCBrowser"></param> public void RecurBrowse(OPCBrowser oPCBrowser) { //展开分支 oPCBrowser.ShowBranches(); //展开叶子 oPCBrowser.ShowLeafs(true); foreach (object turn in oPCBrowser) { Console.WriteLine(turn.ToString()); } }
/// <summary> /// 列出OPC服务器中所有节点 /// </summary> /// <param name="oPCBrowser"></param> private void RecurBrowse(OPCBrowser oPCBrowser) { //展开分支 oPCBrowser.ShowBranches(); //展开叶子 oPCBrowser.ShowLeafs(true); foreach (object turn in oPCBrowser) { listBox1.Items.Add(turn.ToString()); } }
/// <summary> /// 列出opc服务器中所有节点 /// </summary> /// <param name="TransactionID"></param> /// <param name="NumItems"></param> /// <param name="ClientHandles"></param> /// <param name="Errors"></param> private void RecurBrowse(OPCBrowser oPCBrowser) { //写入接到treeview LoadDataToTree(oPCBrowser, treeView1.Nodes[0].Nodes); oPCBrowser.ShowBranches(); oPCBrowser.ShowLeafs(true); foreach (object turn in oPCBrowser) { listBox1.Items.Add(turn.ToString()); } }
/// <summary> /// 列出OPC服务器中所有节点 /// </summary> /// <param name="oPCBrowser"></param> private void RecurBrowse(OPCBrowser oPCBrowser) { //展开分支 oPCBrowser.ShowBranches(); //展开叶子 oPCBrowser.ShowLeafs(true); foreach (object turn in oPCBrowser) { //OPCItemDic2.Add(turn.ToString(), ); OPCItemNames.Add(turn.ToString()); } }
private void browseLeaf(Branch Parent) { _OPCBrowser.ShowLeafs(); if (_OPCBrowser.Count > 0) { for (int i = 1; i <= _OPCBrowser.Count; i++) { Leaf l = new Leaf(Parent: Parent, Name: _OPCBrowser.Item(i), ClientHandle: this.ClientHandle, Browser: this._OPCBrowser); } } }
/// <summary> /// 获取listview中相应的值 /// </summary> /// <param name="opcbrowser"></param> public List <string> RecurBrowse(OPCBrowser opcbrowser) { // OPCBrowser opcbrowser = ServerConnect.KepServer.CreateBrowser(); opcbrowser.ShowBranches(); opcbrowser.ShowLeafs(true); list = new List <string>(); foreach (object turn in opcbrowser) { list.Add(turn.ToString()); //lv = new ListViewItem(turn.ToString()); //listView1.Items.Add(lv); } return(list); }
public List <String> GetLeaf(string path) { List <string> list = new List <string>(); Array branches = path.Substring(path.IndexOf("/") + 1, path.Length - path.IndexOf("/") - 1).Split('/'); opcBrowser.MoveTo(branches); opcBrowser.ShowLeafs(false); foreach (var branch in opcBrowser) { list.Add(branch.ToString()); } opcBrowser.MoveToRoot(); return(list); }
public List <string> RecurBrowse(OPCBrowser opcBrowser) { List <string> opcNodeNameList = new List <string>(); //展开分支 opcBrowser.ShowBranches(); //展开叶子 opcBrowser.ShowLeafs(true); foreach (object item in opcBrowser) { opcNodeNameList.Add(item.ToString()); } return(opcNodeNameList); }
/// <summary> /// 列出OPC服务器中所有节点 /// </summary> /// <param name="oPCBrowser"></param> public OPCBrowser RecurBrowse() { OPCBrowser oPCBrowser = KepServer.CreateBrowser(); //展开分支 oPCBrowser.ShowBranches(); //展开叶子 oPCBrowser.ShowLeafs(true); // foreach (object turn in oPCBrowser) // { // lsbGroups.Items.Add(turn.ToString()); // } return(oPCBrowser); }
//获取PLC对象中所有的Item public string ItemList() { browser = myOpcServer.CreateBrowser(); browser.ShowBranches(); browser.ShowLeafs(true); string i = ""; foreach (var item in browser) { if (item.ToString().Contains(str)) { i += item.ToString() + "|"; } } return(i); }
/// <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); }
public void GetItemsNames(string RemoteServerName, string RemoteServerIp, string pass, string pattern, string patternRe) { try { _kepServer.Connect(RemoteServerName, RemoteServerIp); OPCBrowser browser = _kepServer.CreateBrowser(); //browser.Filter = "[\u4e00-\u9fa5]+.PLC.[\u4e00-\u9fa5]+[A|B|C]"; browser.ShowBranches(); browser.ShowLeafs(true); dicItems.Clear(); //string pattern = @"[\u4e00-\u9fa5]+\d+\-" + pass + @".PLC.[\u4e00-\u9fa5]+[A-Z]+\d+";//匹配 设备001.PLC.配置参数A1 //string patternRe = @".PLC.[\u4e00-\u9fa5]+[A-Z]+\d+"; //string pattern = "[A-Z|a-z]+.PLC." + @"[AI|BI]+\d"; //string patternRe = @".PLC.[AI|BI]+\d"; foreach (object item in browser) { if (Regex.IsMatch(item.ToString(), pattern, RegexOptions.IgnoreCase)) { ItemsNames.Add(item.ToString()); Regex rgx = new Regex(patternRe);//获取GroupName(组名) string key = rgx.Replace(item.ToString(), " "); IList <string> items = new List <string> { item.ToString() }; if (!dicItems.ContainsKey(key)) { dicItems.Add(key, items); } else { dicItems[key].Add(item.ToString()); } } } } catch (Exception ex) { LogHelper.WriteLog(typeof(OpcClient), ex.Message); } }
private void btnGetGrps_Click(object sender, EventArgs e) { //实例化Tag浏览器 myOPCBrowser = myServer.CreateBrowser(); //展开分组 myOPCBrowser.ShowBranches(); //展开标签 myOPCBrowser.ShowLeafs(true); //将所有分支和叶子节点显示到ListBox lstItems.Items.Clear(); foreach (object turn in myOPCBrowser) { lstItems.Items.Add(turn.ToString()); } //开启定位标签按钮 btnSetItem.Enabled = true; }
/// <summary> /// 将数据获取到treeview /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LoadDataToTree(OPCBrowser oPCBrowser, TreeNodeCollection treeNodeCollection) { oPCBrowser.Organization.ToString(); oPCBrowser.ShowBranches(); foreach (object turn in oPCBrowser) { TreeNode node = treeNodeCollection.Add(turn.ToString()); treeView1.SelectedNode = node; oPCBrowser.MoveDown(turn.ToString()); LoadDataToTree(oPCBrowser, node.Nodes); oPCBrowser.MoveUp(); } oPCBrowser.ShowLeafs(false); foreach (object turn in oPCBrowser) { treeView1.SelectedNode.Nodes.Add(turn.ToString()); } }
private bool CreateGroup() { try { opcGroups = opcServer.OPCGroups; opcGroup = opcGroups.Add(base.deviceName); SetGroupProperty(); OPCItems kepItems = opcGroup.OPCItems; opcGroup.DataChange += KepGroup_DataChange; OPCBrowser oPCBrowser = opcServer.CreateBrowser(); //展开分支 oPCBrowser.ShowBranches(); //展开叶子 oPCBrowser.ShowLeafs(true); foreach (object turn in oPCBrowser) { ///客户端句柄 int itmHandleClient = 1; string[] strTem; string str; string Tem; Tem = turn.ToString().Split('.')[turn.ToString().Split('.').Length - 1]; strTem = Tem.ToString().Split('_'); if (strTem.Length >= 2) { str = strTem[strTem.Length - 2]; if (str == deviceName) { OPCItem kepItem = kepItems.AddItem(turn.ToString(), itmHandleClient); itmHandleClient += 1; // OPCItem Item = (OPCItem)turn; } } } // myEnumBuilder.CreateType(); opcGroup.AsyncWriteComplete += new DIOPCGroupEvent_AsyncWriteCompleteEventHandler(KepGroup_AsyncWriteComplete); } catch (Exception err) { return(false); } return(true); }
public List <string> GetLeafs(string position) { List <string> leafs = new List <string>(); string[] desName = position.ToString().Split('.'); Browser.MoveTo(desName); Browser.ShowLeafs(); IEnumerator enumerator = Browser.GetEnumerator(); //树 while (enumerator.MoveNext()) { if (enumerator.Current != null) { leafs.Add(enumerator.Current.ToString()); } } Browser.MoveToRoot(); return(leafs); }
/// <summary> /// Рекурсивно обходит содержимое OPC-сервера. /// </summary> /// <param name="aBrowser">Браузер OPC-сервера.</param> /// <param name="aPrefix">Префикс для построения дерева.</param> private static void ShowOpcTagsRecurcive(OPCBrowser aBrowser, string aPrefix = "") { var isError = false; try { aBrowser.ShowBranches(); } catch (Exception ex) { Console.WriteLine("Ошибка при отображении ветки."); isError = true; } if (!isError) { foreach (var item in aBrowser) { Console.WriteLine(aPrefix + "Ветвь: " + item); aBrowser.MoveDown(item.ToString()); ShowOpcTagsRecurcive(aBrowser, aPrefix + "-"); aBrowser.MoveUp(); } } isError = false; try { aBrowser.ShowLeafs(); } catch (Exception ex) { Console.WriteLine("Ошибка при отображении листа."); isError = true; } if (!isError) { foreach (var item in aBrowser) { Console.WriteLine(aPrefix + "Лист:" + item); } } }
private void lsbGroups_SelectedIndexChanged(object sender, EventArgs e) { OPCBrowser oPCBrowser = KepServer.CreateBrowser(); //lsbGroups.SelectedItem.ToString()) //展开分支 //oPCBrowser.Filter = lsbGroups.SelectedItem.ToString(); oPCBrowser.ShowBranches(); //KepGroups = KepServer.OPCGroups; //string str = KepGroup.Name; //oPCBrowser.Item //myKepGroup. lsbGroups.SelectedItem.ToString() //string str = oPCBrowser.Item(gp); //MessageBox.Show(str); // return; //int index = 2; //展开叶子 oPCBrowser.ShowLeafs(true); foreach (object turn in oPCBrowser) { //if (turn.ToString() == lsbGroups.SelectedItem.ToString()) //{ // MessageBox.Show(turn.ToString()); //} listBox1.Items.Add(turn.ToString()); } // OPCGroup myKepGroup = KepGroups.Item(1); // int c= KepGroups.Count; //OPCItems myitems = myKepGroup.OPCItems; //foreach (object it in myitems) //{ // listBox1.Items.Add(it.ToString()); //} //MessageBox.Show(c.ToString()); }
/// <summary> /// 列出OPC组下所有点 /// </summary> /// <param name="oPCBrowser"></param> private void RecurBrowseItems(OPCBrowser oPCBrowser, string groupName) { //int len = groupName.Length; //ArrayList al = new ArrayList(); ////展开分支 //oPCBrowser.ShowBranches(); ////展开叶子 //oPCBrowser.ShowLeafs(true); //listBoxItems.Items.Clear(); //listView1.Items.Clear(); //foreach (object turn in oPCBrowser) //{ // if (turn.ToString().Contains(groupName)) // { // al.Add(turn); // } //} //foreach (var item in al) //{ // if (!item.ToString().Contains("._")) // { // listBoxItems.Items.Add(item.ToString()); // listView1.Items.Add(item.ToString()); // } //} listView1.Items.Clear(); oPCBrowser.MoveDown(groupName); oPCBrowser.ShowBranches(); oPCBrowser.ShowLeafs(true); listBoxItems.Items.Clear(); listView1.Items.Clear(); foreach (object turn in oPCBrowser) { listView1.Items.Add(turn.ToString()); listBoxItems.Items.Add(turn.ToString()); } oPCBrowser.MoveUp(); }
/// <summary> /// 遍历该分支节点下所有的叶节点 /// </summary> /// <param name="node"></param> /// <param name="oPCBrowser"></param> private void ListLeaf(ref TreeNode node, OPCBrowser oPCBrowser) { if (null == node) { oPCBrowser.MoveToRoot(); node = ItemTreeNode.Nodes.Add("Root"); } else {//剔除无意义的Root根节点 List <string> BranchesList = new List <string>(); BranchesList.AddRange(node.FullPath.Split('\\')); BranchesList.RemoveAt(0); Array Branches = BranchesList.ToArray(); oPCBrowser.MoveTo(ref Branches); } oPCBrowser.ShowLeafs(false);//false不展开子集叶,true展开所有子集叶 foreach (object item in oPCBrowser) { node.Nodes.Add(item.ToString()); } oPCBrowser.ShowBranches(); }
/// <summary> /// 列出OPC服务器中所有节点 /// </summary> private int RecurBrowse(OPCBrowser oPCBrowser, bool initFlag) { //展开分支 oPCBrowser.ShowBranches(); //展开叶子 oPCBrowser.ShowLeafs(true); byte idx = 0; foreach (object turn in oPCBrowser) { //if (string.Compare(turn.ToString(),"Tags")==0)// //if ((turn.ToString().IndexOf(cTagName)) > -1) { tagList[idx] = turn.ToString(); if (initFlag) { BeginUpdate(turn.ToString()); } ++idx; } } return(idx); }