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 RemoveTag(Tag tag) { tag.ValueChanged -= TagValueChanged; _tags.Remove(tag); // TODO: remove logix tag from _tagGroup }
private void TagValueChanged(Tag sender, TagValueChangedEventArgs e) { _subject.OnNext(sender); if (TagChanged != null) { TagChanged(this, new TagChangedEventArgs(sender)); } }
public void AddTagsRecursively(Tag rootTag) { AddTag(rootTag); foreach (var child in rootTag.Childs) { AddTagsRecursively(child); } }
public Task WriteTag(Tag tag, object[] values) { if (tag.Value == null && values == null) { return(Task.FromResult(true)); } tag.LockValue(); try { throw new NotImplementedException(); } 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); }
private bool TryConvertToCustomValue(Tag tag, Logix.Tag logixTag, out object convertedValue) { ConvertToCustomValueConverterFunction convertFunction; if (_tagValueConverters != null && _tagValueConverters.TryGetValue(tag.DataType, out convertFunction)) { try { var cipStruct = _encoding.ToType(logixTag, _cipStructTypes[tag.DataType]); convertedValue = convertFunction(cipStruct); } catch (Exception exception) { throw new PlcCommunicationException("Error occured when converting INGEAR Tag value into " + tag.DataType, _controlLogix.IPAddress, exception); } return(true); } convertedValue = null; return(false); }
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); }