public void BrowseOPCItemIDs(OPCBROWSETYPE filterType, string filterCriteria, VarEnum dataTypeFilter, OPCACCESSRIGHTS accessRightsFilter, out UCOMIEnumString stringEnumerator) { stringEnumerator = null; object enumtemp; ifBrowse.BrowseOPCItemIDs(filterType, filterCriteria, (short)dataTypeFilter, accessRightsFilter, out enumtemp); stringEnumerator = (UCOMIEnumString)enumtemp; enumtemp = null; }
public bool ViewItem(string opcid) { try { RemoveItem(); // first remove previous item if any itmHandleClient = 1234; OPCItemDef[] aD = new OPCItemDef[1]; aD[0] = new OPCItemDef(opcid, true, itmHandleClient, VarEnum.VT_EMPTY); OPCItemResult[] arrRes; theGrp.AddItems(aD, out arrRes); if (arrRes == null) { return(false); } if (arrRes[0].Error != HRESULTS.S_OK) { return(false); } btnItemMore.Enabled = true; itmHandleServer = arrRes[0].HandleServer; itmAccessRights = arrRes[0].AccessRights; itmTypeCode = VT2TypeCode(arrRes[0].CanonicalDataType); txtItemID.Text = opcid; txtItemDataType.Text = DUMMY_VARIANT.VarEnumToString(arrRes[0].CanonicalDataType); if ((itmAccessRights & OPCACCESSRIGHTS.OPC_READABLE) != 0) { int cancelID; theGrp.Refresh2(OPCDATASOURCE.OPC_DS_DEVICE, 7788, out cancelID); } else { txtItemValue.Text = "no read access"; } if (itmTypeCode != TypeCode.Object) // Object=failed! { // check if write is premitted if ((itmAccessRights & OPCACCESSRIGHTS.OPC_WRITEABLE) != 0) { btnItemWrite.Enabled = true; } } } catch (COMException) { MessageBox.Show(this, "AddItem OPC error!", "ViewItem", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } return(true); }
public void ViewItem(string opcid) { RemoveItem(); // first remove previous item if any _itmHandleClient = 1234; OPCItemDef[] aD = new OPCItemDef[1]; aD[0] = new OPCItemDef(opcid, true, _itmHandleClient, VarEnum.VT_EMPTY); OPCItemResult[] arrRes; _theGrp.AddItems(aD, out arrRes); if (arrRes == null) { throw new Exception(string.Format("arrRes == null opcid:{0}", opcid)); } if (arrRes[0].Error != HRESULTS.S_OK) { throw new Exception(string.Format("arrRes[0].Error != HRESULTS.S_OK opcid:{0}", opcid)); } _itmHandleServer = arrRes[0].HandleServer; ItmAccessRights = arrRes[0].AccessRights; ItmTypeCode = Vt2TypeCode(arrRes[0].CanonicalDataType); GrpRefresh2(); //else // //txtItemValue.Text = "no read access"; // if (ItmTypeCode != TypeCode.Object) // Object=failed! // { // // check if write is premitted // if ((ItmAccessRights & OPCACCESSRIGHTS.OPC_WRITEABLE) != 0) // { } // //btnItemWrite.Enabled = true; // } }
/// <summary> /// Browse items /// </summary> /// <param name="filterType"><see cref="OPCBROWSETYPE"/> filter, ignored for <see cref="OPCNAMESPACETYPE.OPC_NS_FLAT"/> address space.</param> /// <param name="filterCriteria">A server specific filter string.</param> /// <param name="dataTypeFilter">Data type filter or <see cref="VarEnum.VT_EMPTY"/></param> /// <param name="accessRightsFilter"><see cref="OPCACCESSRIGHTS"/> filter.</param> /// <returns></returns> public string[] BrowseItemIDs(OPCBROWSETYPE filterType, string filterCriteria, VarEnum dataTypeFilter, OPCACCESSRIGHTS accessRightsFilter) { ThrowIfDisposed(); object enumerator = null; try { opcBrowseServer.BrowseOPCItemIDs(filterType, filterCriteria, (short)dataTypeFilter, accessRightsFilter, out enumerator); return(IEnumStringToArray((IEnumString)enumerator)); } finally { if (enumerator != null) { Marshal.ReleaseComObject(enumerator); } } }
public void BrowseOPCItemIDs(OPCBROWSETYPE filterType, string filterCriteria, VarEnum dataTypeFilter, OPCACCESSRIGHTS accessRightsFilter, out IEnumString stringEnumerator) { object obj2; stringEnumerator = null; this.ifBrowse.BrowseOPCItemIDs(filterType, filterCriteria, (short)dataTypeFilter, accessRightsFilter, out obj2); stringEnumerator = (IEnumString)obj2; obj2 = null; }
public List <string> Browse(OPCBROWSETYPE type = OPCBROWSETYPE.OPC_FLAT, string szFilter = "", short typeFilter = 0, OPCACCESSRIGHTS rightFilter = 0) { if (_opcBrowser == null) { return(null); } List <string> list = new List <string>(14000); OPC.Data.Interface.IEnumString enumerator; _opcBrowser.BrowseOPCItemIDs(type, szFilter, typeFilter, rightFilter, out enumerator); if (enumerator == null) { return(list); } int cft = 0; string[] strF = new string[1000]; do { enumerator.RemoteNext(1000, strF, out cft); for (int i = 0; i < cft; i++) { list.Add(strF[i]); } } while (cft > 0); Marshal.ReleaseComObject(enumerator); enumerator = null; list.TrimExcess(); return(list); }
public void getValueFormHX() { try { DoInit(); int itemsValueCount = itemsValue.Count; OPCItemDef[] aD = new OPCItemDef[itemsValueCount]; for (int i = 0; i < itemsValueCount; i++) { itmHandleClient = i; aD[i] = new OPCItemDef(itemsValue[i][0], true, itmHandleClient, VarEnum.VT_EMPTY); } //int[] ids; //this.theSrv.QueryAvailableLocaleIDs(out ids); //string strtmp; //strtmp = theSrv.GetItemProperties((ids[0].ToString()); SERVERSTATUS status; theSrv.GetStatus(out status); OPCItemResult[] arrRes; theGrp.AddItems(aD, out arrRes); if (arrRes == null) { return; } if (arrRes[0].Error != HRESULTS.S_OK) { return; } //btnItemMore.Enabled = true; itmHandleServer = arrRes[0].HandleServer; itmAccessRights = arrRes[0].AccessRights; itmTypeCode = VT2TypeCode(arrRes[0].CanonicalDataType); // txtItemID.Text = opcid; // txtItemDataType.Text = DUMMY_VARIANT.VarEnumToString(arrRes[0].CanonicalDataType); if ((itmAccessRights & OPCACCESSRIGHTS.OPC_READABLE) != 0) { int cancelID; theGrp.Refresh2(OPCDATASOURCE.OPC_DS_DEVICE, 7788, out cancelID); } else { ; } //txtItemValue.Text = "no read access"; if (itmTypeCode != TypeCode.Object) // Object=failed! { // check if write is premitted //if ((itmAccessRights & OPCACCESSRIGHTS.OPC_WRITEABLE) != 0) // btnItemWrite.Enabled = true; } } catch (COMException) { //MessageBox.Show(this, "AddItem OPC error!", "ViewItem", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
int IOPCBrowseServerAddressSpace.BrowseOPCItemIDs([In, MarshalAs(UnmanagedType.U4)] OPCBROWSETYPE dwBrowseFilterType, [In, MarshalAs(UnmanagedType.LPWStr)] string szFilterCriteria, [In, MarshalAs(UnmanagedType.U2)] short vtDataTypeFilter, [In, MarshalAs(UnmanagedType.U4)] OPCACCESSRIGHTS dwAccessRightsFilter, [MarshalAs(UnmanagedType.IUnknown)] out object ppUnk) { string currentTestMethod = Dottest.Framework.Stubs.CurrentTestMethod.Name; if (currentTestMethod.Equals("TestBrowse01")) { EnumString enumStr = new EnumString(); enumStr.Add("DP1"); enumStr.Add("DP2"); ppUnk = enumStr; } else { ppUnk = null; } return(1); }
/// <summary> /// Add unique OPC item to group /// </summary> /// <param name="opcID">OPC Item name</param> /// <returns>false - not added to OPC group, true - added successfully</returns> public bool AddOPCItem(string opcID) { string Function_Name = "AddOPCItem"; LogHelper.Trace(CLASS_NAME, Function_Name, string.Format("Function_Entered for datapoint {0}", opcID)); if (opcID.Trim() == "") { LogHelper.Debug(CLASS_NAME, Function_Name, "New Datapoint name is empty.Function_Exited with return value false."); return(false); } int currentSeq = 0; OPCDataItem opcDataItemVar = null; lock (m_opcDataDicObj) { if (m_opcDataIndexDic.ContainsKey(opcID)) { LogHelper.Info(CLASS_NAME, Function_Name, "Already the datapoint is added.Function_Exited"); return(true); } currentSeq = m_OPCDataSeqNum++; opcDataItemVar = new OPCDataItem(opcID, currentSeq); //add to internal map m_opcDataIndexDic.Add(opcID, currentSeq); m_opcDataDic.Add(currentSeq, opcDataItemVar); } if (!IsOPCServerConnected()) { LogHelper.Debug(CLASS_NAME, Function_Name, "OPC Server is not connect. Reconnect before adding datapoints."); return(false); } try { LogHelper.Trace(CLASS_NAME, Function_Name, "Connect to OPC Group"); //connect to OPC Group OPCItemDef[] aD = new OPCItemDef[1]; aD[0] = new OPCItemDef(opcID, true, currentSeq, VarEnum.VT_EMPTY); OPCItemResult[] arrRes; { lock (m_opcDataDicObj) { m_OPCGroup.AddItems(aD, out arrRes); } } if (arrRes == null) { LogHelper.Info(CLASS_NAME, Function_Name, "OPC Group AddItems() return null(cant not find handle server). Function Exited with return value false."); return(false); } if (arrRes[0].Error != HRESULTS.S_OK) { LogHelper.Info(CLASS_NAME, Function_Name, string.Format("OPC Group AddItems() return Error code({0}, not OK) for DataPoint = {1}. Function Exited with return value false.", arrRes[0].Error, opcID)); lock (m_opcDataDicObj) { m_OPCDataSeqNum--; m_opcDataIndexDic.Remove(opcID); m_opcDataDic.Remove(currentSeq); m_TotryQuene.Add(opcID); } return(false); } opcDataItemVar.HandleServer = arrRes[0].HandleServer; OPCACCESSRIGHTS itmAccessRights = arrRes[0].AccessRights; TypeCode itmTypeCode = VT2TypeCode(arrRes[0].CanonicalDataType); if ((itmAccessRights & OPCACCESSRIGHTS.OPC_READABLE) != 0) { int cancelID; lock (m_opcDataDicObj) { m_OPCGroup.Refresh2(OPCDATASOURCE.OPC_DS_DEVICE, 7788, out cancelID); } } else { LogHelper.Info(CLASS_NAME, Function_Name, "Can find a handle server, but not have access right.Function Exited with return value false."); return(false); } } catch (COMException localException) { LogHelper.Error(CLASS_NAME, Function_Name, string.Format("{0} for DataPoint - {1}", localException.ToString(), opcID)); // if (localException.Message.Contains("The RPC server is unavailable.")) // Fixed issue - related to System Language, to avoid it used Error code if (localException.Message.Contains("0x800706BA")) { lock (m_opcDataDicObj) { m_opcSrvConnectFlag = false; } } return(false); } catch (Exception exception) { LogHelper.Error(CLASS_NAME, Function_Name, string.Format("{0} for DataPoint - {1}", exception.ToString(), opcID)); return(false); } LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited"); return(true); }
//------------------------ ��� ������ ���� 1 ����� � ������ !!! // opcid "S7:[PLC31]db2,int12" public bool ViewItem(string opcid) { try { RemoveItem(); // first remove previous item if any itmHandleClient = 1234; OPCItemDef[] aD = new OPCItemDef[1]; aD[0] = new OPCItemDef(opcid,true,itmHandleClient,VarEnum.VT_EMPTY); OPCItemResult[] arrRes; theGrp.AddItems(aD,out arrRes); if (arrRes == null) return false; if (arrRes[0].Error != HRESULTS.S_OK) return false; itmHandleServer = arrRes[0].HandleServer; itmAccessRights = arrRes[0].AccessRights; itmTypeCode = VT2TypeCode(arrRes[0].CanonicalDataType); txtItemDataType.Text = DUMMY_VARIANT.VarEnumToString(arrRes[0].CanonicalDataType); if ((itmAccessRights & OPCACCESSRIGHTS.OPC_READABLE) != 0) { int cancelID; theGrp.Refresh2(OPCDATASOURCE.OPC_DS_DEVICE,7788,out cancelID); } else txtItemValue.Text = "no read access"; if (itmTypeCode != TypeCode.Object) // Object=failed! { // check if write is premitted //if ((itmAccessRights & OPCACCESSRIGHTS.OPC_WRITEABLE) != 0) //btnItemWrite.Enabled = true; } } catch (COMException) { MessageBox.Show(this,"AddItem " + opcid + " OPC error!","ViewItem",MessageBoxButtons.OK,MessageBoxIcon.Warning); return false; } return true; }
public bool DoInit() { string[] itemstrings = new string[5]; string sPLC_Adr = "*UnDef*",sAlias = "*UnDef*",sGroup = "",sDesc = ""; int iPLCDataLength; sAliasToControl = "ACT_C1_STAHLMARKE0"; itemstrings[2] = itemstrings[3] = itemstrings[4] = "-"; try { selectedOpcSrv = "OPC.SimaticNET.1"; // ����� ���� �������� AddLogg("������� �� " + sCompName); AddLogg("LoadDefinitions()-Start"); LoadDefinitions(); AddLogg("LoadDefinitions()-End"); theSrv = new OpcServer(); if (!DoConnect(selectedOpcSrv)) { AddLogg("DoConnect(" + selectedOpcSrv + ")=false"); //////////return false; } // add event handler for server shutdown theSrv.ShutdownRequested += new ShutdownRequestEventHandler(this.theSrv_ServerShutDown); // precreate the only OPC group in this example if (!CreateGroup()) { AddLogg("CreateGroup()=false"); //////////return false; } AddLogg("DoInit: Start"); RemoveItem(); // first remove previous item if any cbCtrlAliases.Items.Clear(); groupLi = new List<clsGroupInfo>(); pointLi = new List<clsPointInfo>(); j = 0; for (i = 0; i < strItems_Alias.Count; i++) { try { itemclsPointInfo = new clsPointInfo(); itmHandleClient = j; sPLC_Adr = strItems_adrPLC[i]; // "LOCATION0 PLC13:DB2,STRING66,8" // S7:[PLC13]DB2,STRING66,8 sAlias = strItems_Alias[i]; sGroup = strItems_Groups[i]; sDesc = strItems_Desc[i]; //k = sPLC_Adr.IndexOf("STRING"); k = sPLC_Adr.IndexOf("CHAR"); if (k < 0) { itemclsPointInfo.iDataLength = 0; } else { string[] sSplitted = sPLC_Adr.Trim().Split(','); itemclsPointInfo.iDataLength = Convert.ToInt32(sSplitted[sSplitted.GetLength(0) - 1].Trim()); } OPCItemDef[] aD = new OPCItemDef[1]; aD[0] = new OPCItemDef(sPLC_Adr,true,itmHandleClient,VarEnum.VT_EMPTY); OPCItemResult[] arrRes; theGrp.AddItems(aD,out arrRes); if (arrRes == null) { AddLogg("DoInit:AddItem" + i + " " + sPLC_Adr + " arrRes == null"); //continue; } else { if (arrRes[0].Error != HRESULTS.S_OK) { AddLogg("DoInit:AddItem" + i + " " + sPLC_Adr + " arrRes[0].Error != HRESULTS.S_OK"); //continue; } else { itmHandleServer = arrRes[0].HandleServer; itmAccessRights = arrRes[0].AccessRights; itmTypeCode = VT2TypeCode(arrRes[0].CanonicalDataType); txbActPoint.Text = sPLC_Adr; txtItemDataType.Text = DUMMY_VARIANT.VarEnumToString(arrRes[0].CanonicalDataType); //if ((itmAccessRights & OPCACCESSRIGHTS.OPC_READABLE) != 0) { // int cancelID; // theGrp.Refresh2(OPCDATASOURCE.OPC_DS_DEVICE,7788,out cancelID); // } //else { // txtItemValue.Text = "no read access"; // AddLogg("DoInit:AddItem" + i + " " + sPLC_Adr + " no read access"); // } if (itmTypeCode != TypeCode.Object) { // Object=failed! ////AddLogg("DoInit:AddItem" + i + " " + sPLC_Adr + " Object=failed"); // check if write is permitted if ((itmAccessRights & OPCACCESSRIGHTS.OPC_WRITEABLE) != 0) { //btnItemWrite.Enabled = true; ////AddLogg("DoInit:AddItem" + i + " " + sPLC_Adr + " write is permitted"); } } itemstrings[0] = sAlias; itemstrings[1] = sPLC_Adr; //listOpcView.Items.Add(new ListViewItem(itemstrings,0)); itemclsPointInfo.sAlias = sAlias; string[] sEvtNameSplitted = sAlias.Split('_'); //for (k = 0; k < sEvtNameSplitted.GetLength(0); k++){ // AddLogg("DEBUG sEvtNameSplitted[" + k + "] = '" + sEvtNameSplitted[k]+"'"); //} if (sEvtNameSplitted[0] == "ACT" || sEvtNameSplitted[0] == "SP") { // Fool-Proof if (sEvtNameSplitted[1] == "C1" || sEvtNameSplitted[1] == "C2" || sEvtNameSplitted[1] == "C3") { itemclsPointInfo.iCnvNr = Convert.ToInt32(sEvtNameSplitted[1].Substring(1,1)); if (sEvtNameSplitted[0] == "SP"){ itemclsPointInfo.sAliasInfoTeil = itemclsPointInfo.sAlias.Substring(6,itemclsPointInfo.sAlias.Length -6); } else{ itemclsPointInfo.sAliasInfoTeil = itemclsPointInfo.sAlias.Substring(7,itemclsPointInfo.sAlias.Length - 7); } } else { itemclsPointInfo.iCnvNr = 0; if (sEvtNameSplitted[0] == "SP"){ itemclsPointInfo.sAliasInfoTeil = itemclsPointInfo.sAlias.Substring(3,itemclsPointInfo.sAlias.Length -3); } else{ itemclsPointInfo.sAliasInfoTeil = itemclsPointInfo.sAlias.Substring(4,itemclsPointInfo.sAlias.Length - 4); } } if (sEvtNameSplitted[0] == "SP"){ itemclsPointInfo.bIsSetPoint = true; } } else { AddLogg("DoInit:AddItem" + i + " " + sAlias + " �� ���������� � 'ACT_'/'SP_'"); } itemclsPointInfo.sPLC_Adr = sPLC_Adr; itemclsPointInfo.sDesc = sDesc; itemclsPointInfo.CanonicalDataType = arrRes[0].CanonicalDataType; itemclsPointInfo.sCanonicalDataType = DUMMY_VARIANT.VarEnumToString(arrRes[0].CanonicalDataType); itemclsPointInfo.AccessRights = arrRes[0].AccessRights; itemclsPointInfo.itmTypeCode = itmTypeCode; pointLi.Add(itemclsPointInfo); cbCtrlAliases.Items.Add(sAlias + " " + sPLC_Adr); // ���� � ������ ���� //k = groupLi.FindIndex(delegate(clsGroupInfo lfdGroupInfo) { // ** ��� ��������� // return lfdGroupInfo.sName == sGroup; // } // ); string @group = sGroup; // ** ����� !!! k = groupLi.FindIndex(lfdGroupInfo => lfdGroupInfo.sName == group); if (k < 0) { // ��� ������ ����� ������, ��������������, ��� TAKE_OVER !! itemclsGroupInfo = new clsGroupInfo(); itemclsGroupInfo.sName = sGroup; groupLi.Add(itemclsGroupInfo); pointLi[pointLi.Count - 1].bIsTakeOver = true; // rueckwerts in PointLi schreiben } k = pointLi.Count - 1; // wegen DEBUG pointLi[k].iIdxInGroupLi = groupLi.Count - 1; // gehoert zu dieser Gruppe;rueckwerts in PointLi schreiben k = groupLi.Count - 1; // wegen DEBUG groupLi[k].iItemsCnt++; // so viele Punkte in der Gruppe groupLi[k].iIdxInPointLi.Add(pointLi.Count - 1); // eigentlisch Punkte(als pointLi[Index]) DoStoreToOracle(j); // AnfangsZustand in Oracle generieren AddLogg("�������� Pkt" + j + " group '" + groupLi[k].sName + "',Alias'" + sAlias + "' " + sPLC_Adr); j++; } } } catch (/*COMException*/ Exception comExc) { //MessageBox.Show(this,"AddItem " + sPLC_Adr + " OPC error!","DoInit",MessageBoxButtons.OK,MessageBoxIcon.Warning); AddLogg("DoInit:AddItem" + i + " '" + sPLC_Adr + "' OPC exception:" + comExc.Message); //return false; continue; } } int cancelID; theGrp.Refresh2(OPCDATASOURCE.OPC_DS_DEVICE,7788,out cancelID); } catch (Exception e) { // exceptions MUST be handled //MessageBox.Show(this,"init error! " + e.ToString(),"Exception",MessageBoxButtons.OK,MessageBoxIcon.Warning); AddLogg("DoInit:AddItem" + i + " '" + sPLC_Adr + "' init error! " + e.Message); AddLogg("DoInit: Ende - false"); return false; } AddLogg("DoInit: Ende-true,� pointLi " + pointLi.Count + " � groupLi " + groupLi.Count); mainGate = new MainGateClient(new InstanceContext(new DummyListener())); return true; }
public void BrowseOPCItemIDs( OPCBROWSETYPE filterType, string filterCriteria, VarEnum dataTypeFilter, OPCACCESSRIGHTS accessRightsFilter, out UCOMIEnumString stringEnumerator) { stringEnumerator = null; object enumtemp; ifBrowse.BrowseOPCItemIDs( filterType, filterCriteria, (short) dataTypeFilter, accessRightsFilter, out enumtemp ); stringEnumerator = (UCOMIEnumString) enumtemp; enumtemp = null; }