private ushort[] GetLocalUshortsForProp() { var newUshorts = MemoryAccessor.GetUshortsFromMemory(_deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, true); if (_property.IsFromBits) { var boolArray = newUshorts.GetBoolArrayFromUshortArray(); bool[] subPropertyBools = new bool[16]; int counter = 0; for (ushort i = 0; i < 16; i++) { if (_property.BitNumbers.Contains(i)) { subPropertyBools[counter] = boolArray[i]; counter++; } } var subPropertyUshort = subPropertyBools.BoolArrayToUshort(); return(new[] { subPropertyUshort }); } else { return(newUshorts); } }
public async Task <Result <ushort[]> > GetUshortsOfProperty(object propertyMaybe, DeviceContext deviceContext, bool cacheAllowed, bool isLocal) { IProperty property = propertyMaybe as IProperty; if (property == null || !deviceContext.DataProviderContainer.DataProvider.IsSuccess) { return(Result <ushort[]> .Create(false)); } if (cacheAllowed && deviceContext.DeviceMemory != null && MemoryAccessor.IsMemoryContainsAddresses( deviceContext.DeviceMemory, property.Address, property.NumberOfPoints, isLocal)) { return(MemoryAccessor.GetUshortsFromMemory(deviceContext.DeviceMemory, property.Address, property.NumberOfPoints, isLocal)); } var ushorts = await deviceContext.DataProviderContainer.DataProvider.Item.ReadHoldingResgistersAsync(property.Address, property.NumberOfPoints, "Read property"); if (ushorts.IsSuccessful) { MemoryAccessor.SetUshortsInMemory(deviceContext.DeviceMemory, property.Address, ushorts.Result, isLocal); return(ushorts.Result); } return(Result <ushort[]> .Create(false)); }
public async void Execute() { if (_property.IsFromBits) { IFormattingService formattingService = StaticContainer.Container.Resolve <IFormattingService>(); var formatterForProperty = _property?.UshortsFormatter; if (!MemoryAccessor.IsMemoryContainsAddresses(_deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, false)) { return; } var ushortsFromDevice = MemoryAccessor.GetUshortsFromMemory( _deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, false); var boolArray = ushortsFromDevice.GetBoolArrayFromUshortArray().ToArray(); List <bool> subPropertyBools = new List <bool>(); foreach (var bitNumber in _property.BitNumbers) { subPropertyBools.Add(boolArray[bitNumber]); } subPropertyBools.Reverse(); var subPropertyUshort = subPropertyBools.BoolArrayToUshort(); if (_property?.Dependencies?.Count > 0) { formatterForProperty = await DependentSubscriptionHelpers.GetFormatterConsideringDependencies( _property.Dependencies, _deviceContext, formattingService, _property?.UshortsFormatter, _offset, false); } var value = await formattingService.FormatValueAsync(formatterForProperty, subPropertyUshort.AsCollection(), new FormattingContext(_localAndDeviceValueContainingViewModel, _deviceContext, false)); _localAndDeviceValueContainingViewModel.DeviceValue = _valueViewModelFactory.CreateFormattedValueViewModel(value); } else { IFormattingService formattingService = StaticContainer.Container.Resolve <IFormattingService>(); var formatterForProperty = _property?.UshortsFormatter; if (_property?.Dependencies?.Count > 0) { formatterForProperty = await DependentSubscriptionHelpers.GetFormatterConsideringDependencies( _property.Dependencies, _deviceContext, formattingService, _property?.UshortsFormatter, _offset, false); } if (MemoryAccessor.IsMemoryContainsAddresses( _deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, false)) { var value = await formattingService.FormatValueAsync(formatterForProperty, MemoryAccessor.GetUshortsFromMemory( _deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, false), new FormattingContext(_localAndDeviceValueContainingViewModel, _deviceContext, false)); _localAndDeviceValueContainingViewModel.DeviceValue = _valueViewModelFactory.CreateFormattedValueViewModel(value); } } }
private static async Task <Result <ushort[]> > GetConditionPropertyUshort(string resourceName, DeviceContext deviceContext, IFormattingService formattingService, bool isLocal, ushort addressOffset, IProperty resourceProperty) { if (!MemoryAccessor.IsMemoryContainsAddresses(deviceContext.DeviceMemory, (ushort)(resourceProperty.Address + addressOffset), resourceProperty.NumberOfPoints, isLocal)) { return(Result <ushort[]> .Create(false)); } var propertyUshorts = MemoryAccessor.GetUshortsFromMemory( deviceContext.DeviceMemory, (ushort)(resourceProperty.Address + addressOffset), resourceProperty.NumberOfPoints, isLocal); if (resourceProperty is ISubProperty subProperty) { var x = deviceContext.DeviceSharedResources.SharedResourcesInContainers.FirstOrDefault( container => container.ResourceName == resourceName) .Resource; var resultBitArray = new bool[16]; var boolArray = propertyUshorts.GetBoolArrayFromUshortArray(); int counter = 0; for (int i = 0; i < 16; i++) { if (subProperty.BitNumbersInWord.Contains(i)) { resultBitArray[counter] = boolArray[i]; counter++; } } propertyUshorts = resultBitArray.BoolArrayToUshort().AsCollection(); } if (resourceProperty.IsFromBits) { var x = deviceContext.DeviceSharedResources.SharedResourcesInContainers.FirstOrDefault( container => container.ResourceName == resourceName) .Resource; var resultBitArray = new bool[16]; var boolArray = propertyUshorts.GetBoolArrayFromUshortArray(); int counter = 0; for (int i = 0; i < 16; i++) { if (resourceProperty.BitNumbers.Contains((ushort)i)) { resultBitArray[counter] = boolArray[i]; counter++; } } propertyUshorts = resultBitArray.BoolArrayToUshort().AsCollection(); } return(Result <ushort[]> .Create(propertyUshorts, true)); }