public static string GetPointerlessFullName(this Tag tag) { string fullName = tag.FullName(); int idxPointerSign = -1; int idxPointBefore = -1; var determineIndex = new Func <string, bool>(value => { idxPointerSign = value.IndexOf('^'); if (idxPointerSign != -1) { idxPointBefore = value.LastIndexOf(".", idxPointerSign); } else { idxPointBefore = -1; } return(idxPointBefore != -1 && idxPointerSign != -1); }); while (determineIndex(fullName)) { var pointerName = fullName.Substring(idxPointBefore, idxPointerSign - idxPointBefore + 1); fullName = fullName.Replace(pointerName, string.Empty); } return(fullName); }
public void ReadTagSynchronously(Tag tag) { tag.LockValue(); try { var logixTag = GetLogixTag(tag.FullName()); _controlLogix.ReadTag(new[] { logixTag }); // handle special DataTypes like UDTs object convertedValue; if (TryConvertToCustomValue(tag, logixTag, out convertedValue)) { tag.Value = convertedValue; } else { tag.Value = logixTag.Value; } if (TagChanged != null) { TagChanged(this, new TagChangedEventArgs(tag)); } } finally { tag.ReleaseValue(); } }
public void AddTag(Tag tag) { if (_tags.Contains(tag)) { return; } var logixTag = new Logix.Tag(_controlLogix) { Name = tag.FullName(), DataType = IngearHelper.ParseNetLogixDataType(tag.DataType) }; logixTag.Changed += TagDataChanged; tag.ValueChanged += TagValueChanged; _tags.Add(tag); _tagGroup.AddTag(logixTag); }
public Task WriteTag(Tag tag, object value) { if (tag.Value == null && value == null) { return(Task.FromResult(true)); } var task = _writeTaskScheduler.Schedule(() => { tag.LockValue(); try { tag.DetectDataTypeForValue(value); if (!IsConnected) { throw new PlcCommunicationException( "IngearTagController can't write tag because there is no connection established!", _controlLogix.IPAddress, string.Empty); } var logixTag = new Logix.Tag(_controlLogix) { Name = tag.FullName(), DataType = IngearHelper.ParseNetLogixDataType(tag.DataType) }; // for some reason we must read the tag at least once if (logixTag.ErrorCode != 0) { _controlLogix.ReadTag(logixTag); } // handle special DataTypes like UDTs ConvertToLogixTagValueFunction convertFunction; if (_tagValueConverters != null && _tagValueConverters.TryGetValue(tag.DataType, out convertFunction)) { logixTag.Value = convertFunction(value); } else { if (tag.DataType.Equals(IEC61131_3_DataTypes.Boolean)) { if ((bool)value) { logixTag.Value = "True"; } else { logixTag.Value = "False"; } } else { logixTag.Value = value; } } var result = _controlLogix.WriteTag(logixTag); if (result != ResultCode.E_SUCCESS) { throw new PlcCommunicationException("Can't write value to ControlLogix.", _controlLogix.IPAddress, _controlLogix.Path, logixTag.ErrorString); } } finally { tag.ReleaseValue(); } }); return(task); }