private void ReadTagValueFromKepServer( string kepServerName, TDeviceTagValueRWReqBodyTags read, out int errCode, out string errText) { errCode = 0; errText = ""; for (int i = 0; i < read.Tags.Count; i++) { TIRAPOPCTag opcTag = TIRAPOPCDevices.Instance.FindOPCTagItem( string.Format( "{0}.{1}", kepServerName, read.Tags[i].TagName)); if (opcTag == null) { errCode = 903341; errText = string.Format("读取失败:标签[{0}]在 KepServer 中未定义", read.Tags[i].TagName); return; } else { content.Response.ReadTags.Add( new TDeviceTagValueRWRspBodyTag() { TagName = read.Tags[i].TagName, TagValue = opcTag.TagValue, }); } } }
private void WriteTagValueToKepServer( string kepServerName, TDeviceTagValueRWReqBodyTags write, out int errCode, out string errText) { errCode = 0; errText = ""; for (int i = 0; i < write.Tags.Count; i++) { TIRAPOPCTag opcTag = TIRAPOPCDevices.Instance.FindOPCTagItem( string.Format( "{0}.{1}", kepServerName, write.Tags[i].TagName)); if (opcTag == null) { errCode = 903341; errText = string.Format("回写失败:标签[{0}]在 KepServer 中未定义", write.Tags[i].TagName); return; } else { try { opcTag.WriteTagValueBack(write.Tags[i].TagValue, out errCode, out errText); if (errCode != 0) { errCode = 903341; errText = string.Format( "标签[{0}]回写失败:[{1}]", write.Tags[i].TagName, errText); return; } } catch (Exception error) { errCode = 903341; errText = string.Format( "标签[{0}]回写失败:[{1}]", write.Tags[i].TagName, error.Message); return; } } } }