public override int TryReadArrayElementValue(ISymbol arraySymbol, int[] indices, out byte[] value, out DateTime readTime) { AdsErrorCode code; if (arraySymbol == null) { throw new ArgumentNullException("arraySymbol"); } IArrayType dataType = arraySymbol.DataType as IArrayType; if (dataType == null) { throw new ArgumentException("Parameter 'arraySymbol' doesn't represent an array!", "arraySymbol"); } ValueAccessMode mode = this.calcAccessMethod(arraySymbol); readTime = DateTime.MinValue; if ((indices == null) || (indices.Length == 0)) { int byteSize = dataType.ByteSize; value = new byte[byteSize]; int read = 0; if (mode != ValueAccessMode.IndexGroupOffset) { code = this.TryReadSymbolic(arraySymbol, byteSize, value, out read); } else { IAdsSymbol symbol2 = (IAdsSymbol)Symbol.Unwrap(arraySymbol); code = this.Connection.RawInterface.Read(symbol2.IndexGroup, symbol2.IndexOffset, 0, byteSize, value, false, out read); } } else { ArrayType.CheckIndices(indices, dataType, false); int elementOffset = ArrayType.GetElementOffset(indices, dataType); int byteSize = dataType.ElementType.ByteSize; value = new byte[byteSize]; int read = 0; if (mode != ValueAccessMode.IndexGroupOffset) { code = this.TryReadSymbolic(arraySymbol, byteSize, value, out read); } else { IAdsSymbol symbol = (IAdsSymbol)Symbol.Unwrap(arraySymbol); code = this.Connection.RawInterface.Read(symbol.IndexGroup, symbol.IndexOffset + ((uint)elementOffset), 0, byteSize, value, false, out read); } } if (code == AdsErrorCode.NoError) { readTime = DateTime.UtcNow; } else { value = null; } return((int)code); }
public override int TryWriteArrayElementValue(ISymbol arraySymbol, int[] indices, byte[] value, int valOffset, out DateTime writeTime) { if (this.Connection == null) { throw new AdsException("Connection not established!"); } if (arraySymbol == null) { throw new ArgumentNullException("arraySymbol"); } AdsErrorCode noError = AdsErrorCode.NoError; IArrayType arrayType = null; IResolvableType dataType = arraySymbol.DataType as IResolvableType; arrayType = (dataType == null) ? (arraySymbol.DataType as IArrayType) : (dataType.ResolveType(DataTypeResolveStrategy.AliasReference) as IArrayType); if (arrayType == null) { throw new ArgumentException("Is not an array type", "arraySymbol"); } ValueAccessMode mode = this.calcAccessMethod(arraySymbol); writeTime = DateTime.MinValue; if ((indices == null) || (indices.Length == 0)) { int byteSize = arraySymbol.ByteSize; IAdsSymbol symbol2 = (IAdsSymbol)Symbol.Unwrap(arraySymbol); if (value.Length != byteSize) { throw new ArgumentException("Value array size mismatch!", "value"); } if (mode == ValueAccessMode.IndexGroupOffset) { noError = this.Connection.RawInterface.Write(symbol2.IndexGroup, symbol2.IndexOffset, valOffset, byteSize, value, false); } } else { ArrayType.CheckIndices(indices, arrayType, false); int elementOffset = ArrayType.GetElementOffset(indices, arrayType); int byteSize = arrayType.ElementType.ByteSize; if (mode != ValueAccessMode.IndexGroupOffset) { noError = this.TryWriteSymbolic(arraySymbol, valOffset, byteSize, value); } else { IAdsSymbol symbol = (IAdsSymbol)Symbol.Unwrap(arraySymbol); noError = this.Connection.RawInterface.Write(symbol.IndexGroup, symbol.IndexOffset + ((uint)elementOffset), valOffset, byteSize, value, false); } } if (noError != AdsErrorCode.NoError) { writeTime = DateTime.UtcNow; } return((int)noError); }
internal AdsValueAccessor(IAdsConnection connection, ValueAccessMode accessMethod, IAccessorValueFactory valueFactory, NotificationSettings defaultSettings) : base(valueFactory, connection, defaultSettings) { this._converter = new DynamicValueConverter(); this._syncNotification = new object(); this._accessMethod = ValueAccessMode.IndexGroupOffsetPreferred; this._notificationTable = new AdsNotificationCache(); this._notificationStream = new AdsStream(); this._address = connection.Address; this._accessMethod = accessMethod; base._notificationSettings = defaultSettings; connection.AdsNotification += new AdsNotificationEventHandler(this.adsClient_AdsNotification); connection.AdsNotificationError += new AdsNotificationErrorEventHandler(this.adsClient_AdsNotificationError); }
public override int TryWriteValue(ISymbol symbol, byte[] value, int offset, out DateTime utcWriteTime) { AdsErrorCode deviceInvalidSize; if (symbol == null) { throw new ArgumentNullException("symbol"); } if (this.Connection == null) { throw new AdsException("Connection not established!"); } int byteSize = 0; IAdsSymbol symbol2 = (IAdsSymbol)Symbol.Unwrap(symbol); ValueAccessMode mode = this.calcAccessMethod(symbol2); if (!symbol2.IsBitType) { byteSize = symbol2.Size; } else { byteSize = symbol2.Size / 8; if ((symbol2.Size % 8) > 0) { byteSize++; } } utcWriteTime = DateTime.MinValue; if ((value.Length - offset) > byteSize) { deviceInvalidSize = AdsErrorCode.DeviceInvalidSize; } else { using (new AdsConnectionRestore(this)) { deviceInvalidSize = (mode != ValueAccessMode.IndexGroupOffset) ? this.TryWriteSymbolic(symbol2, offset, byteSize, value) : this.Connection.RawInterface.Write(symbol2.IndexGroup, symbol2.IndexOffset, offset, byteSize, value, false); if (deviceInvalidSize == AdsErrorCode.NoError) { utcWriteTime = DateTime.UtcNow; } } } return((int)deviceInvalidSize); }
public override int TryReadValue(ISymbol symbol, out byte[] value, out DateTime utcReadTime) { if (symbol == null) { throw new ArgumentNullException("symbol"); } if (this.Connection == null) { throw new AdsException("Connection not established!"); } IAdsSymbol symbol2 = (IAdsSymbol)Symbol.Unwrap(symbol); IProcessImageAddress address = symbol2; ValueAccessMode mode = this.calcAccessMethod(symbol2); int byteSize = address.ByteSize; if (symbol.IsReference) { byteSize = ((DataType)symbol.DataType).ResolveType(DataTypeResolveStrategy.AliasReference).ByteSize; } value = new byte[byteSize]; int read = 0; utcReadTime = DateTime.MinValue; AdsErrorCode noError = AdsErrorCode.NoError; using (new AdsConnectionRestore(this)) { noError = (mode != ValueAccessMode.IndexGroupOffset) ? this.TryReadSymbolic(symbol, byteSize, value, out read) : this.Connection.RawInterface.Read(address.IndexGroup, address.IndexOffset, 0, byteSize, value, false, out read); if (noError == AdsErrorCode.NoError) { utcReadTime = DateTime.UtcNow; } else { value = null; } } return((int)noError); }
private void RegisterNotification(ISymbol symbol, SymbolNotificationType type, NotificationSettings settings) { if (symbol == null) { throw new ArgumentNullException("symbol"); } if (this.Connection == null) { throw new AdsException("Connection not established!"); } int byteSize = symbol.ByteSize; int length = Math.Max(byteSize, this._notificationTable.GetLargestSymbolSize()); this.resizeNotificationStream(length); if (!this._notificationTable.Contains(symbol)) { IAdsSymbol symbol2 = (IAdsSymbol)Symbol.Unwrap(symbol); ValueAccessMode mode = this.calcAccessMethod(symbol2); int handle = 0; using (new AdsConnectionRestore(this)) { if (mode == ValueAccessMode.IndexGroupOffset) { handle = this.Connection.AddDeviceNotification(symbol2.IndexGroup, symbol2.IndexOffset, this._notificationStream, 0, byteSize, settings.NotificationMode, settings.CycleTime, settings.MaxDelay, symbol); } else { if (mode != ValueAccessMode.Symbolic) { throw new NotSupportedException("Value access mode not supported!"); } handle = this.Connection.AddDeviceNotification(symbol.InstancePath, this._notificationStream, 0, byteSize, settings.NotificationMode, settings.CycleTime, settings.MaxDelay, symbol); } this._notificationTable.Add(symbol, handle, type, settings); return; } } this._notificationTable.Update(symbol, type, settings); }
private ValueAccessMode calcAccessMethodByAddress(IProcessImageAddress symbolAddress) { ValueAccessMode indexGroupOffset = this._accessMethod; switch (this._accessMethod) { case ValueAccessMode.IndexGroupOffset: indexGroupOffset = ValueAccessMode.IndexGroupOffset; break; case ValueAccessMode.Symbolic: indexGroupOffset = ValueAccessMode.Symbolic; break; case ValueAccessMode.IndexGroupOffsetPreferred: switch (symbolAddress.IndexGroup) { case 0xf014: case 0xf016: case 0xf017: case 0xf019: case 0xf01a: case 0xf01b: indexGroupOffset = ValueAccessMode.Symbolic; break; default: indexGroupOffset = ValueAccessMode.IndexGroupOffset; break; } break; default: throw new NotSupportedException($"'{this._accessMethod.ToString()}' not supported"); } return(indexGroupOffset); }
protected SumSymbolCommand(IAdsConnection connection, IList <ISymbol> symbols) { this.mode = ValueAccessMode.IndexGroupOffsetPreferred; this.connection = connection; this.symbols = symbols; }