private bool SetOneOPCTag(IOPCTag opcTag, VarEnum dataType) { var items = new OPCItemDef[1]; items[0] = new OPCItemDef(opcTag.FullName, true, 0, dataType); OPCItemResult[] addRslt; int rtc = OPCWriteGroup.AddItems(items, out addRslt); if (HRESULTS.Failed(rtc)) { return(false);// "Error at AddItem"; } var iHnd = new Int32[addRslt.Length]; for (int i = 0; i < addRslt.Length; ++i) { iHnd[i] = addRslt[i].HandleServer; } int[] err; var val = new object[addRslt.Length]; val[0] = opcTag.ObjectValue; rtc = OPCWriteGroup.Write(iHnd, val, out err); //string errTxt = "OK"; if (HRESULTS.Failed(rtc)) { return(false); //errTxt = srv.GetErrorString(rtc, 0); } // succeeded // check item error codes if (err.Any(HRESULTS.Failed)) { return(false); } OPCWriteGroup.RemoveItems(iHnd, out err); return(true); // return errTxt; }
public bool CreateReadOPCTag(IOPCTag opcTag) { if (opcTag.Type == typeof(int)) { return(CreateReadOPCTag(opcTag.FullName, VarEnum.VT_I4)); } if (opcTag.Type == typeof(bool)) { return(CreateReadOPCTag(opcTag.FullName, VarEnum.VT_BOOL)); } if (opcTag.Type == typeof(string)) { return(CreateReadOPCTag(opcTag.FullName, VarEnum.VT_BSTR)); } if (opcTag.Type == typeof(DateTime)) { return(CreateReadOPCTag(opcTag.FullName, VarEnum.VT_DATE)); } if (opcTag.Type == typeof(double)) { return(CreateReadOPCTag(opcTag.FullName, VarEnum.VT_R8)); } if (opcTag.Type == typeof(float)) { return(CreateReadOPCTag(opcTag.FullName, VarEnum.VT_R4)); } if (opcTag.Type == typeof(string[])) { return(CreateReadOPCTag(opcTag.FullName, VarEnum.VT_BSTR | VarEnum.VT_ARRAY)); } if (opcTag.Type == typeof(int[])) { return(CreateReadOPCTag(opcTag.FullName, VarEnum.VT_I4 | VarEnum.VT_ARRAY)); } return(false); }
public bool SetOneOPCTag(IOPCTag opcTag) { return(SetOneOPCTag(opcTag, VarEnum.VT_I4)); }