Beispiel #1
0
 public DiscreteSubscription(IDiscretMeasuringElement discretMeasuringElement,
                             IDiscretMeasuringElementViewModel discretMeasuringElementViewModel, DeviceContext deviceContext,
                             string groupName)
 {
     DiscretMeasuringElement           = discretMeasuringElement;
     _discretMeasuringElementViewModel = discretMeasuringElementViewModel;
     _deviceContext = deviceContext;
     GroupName      = groupName;
 }
Beispiel #2
0
        private IDiscretMeasuringElement CreateDiscretMeasuringElement(
            IDiscretMeasuringElementEditorViewModel discretMeasuringElementEditorViewModel)
        {
            IDiscretMeasuringElement discretMeasuringElement =
                StaticContainer.Container.Resolve <IDiscretMeasuringElement>();

            InitDefaults(discretMeasuringElementEditorViewModel, discretMeasuringElement);
            discretMeasuringElement.AddressOfBit = new BitAddressSaver().GetAddressOfBitFromEditor(discretMeasuringElementEditorViewModel.BitAddressEditorViewModel);

            return(discretMeasuringElement);
        }
        public IMeasuringElementEditorViewModel CreateDiscretMeasuringElementEditorViewModel(
            IDiscretMeasuringElement discretMeasuringElement = null)
        {
            if (discretMeasuringElement == null)
            {
                discretMeasuringElement = _measuringElementFactory.CreateDiscretMeasuringElement();
            }

            IDiscretMeasuringElementEditorViewModel discretMeasuringElementEditorViewModel =
                _container.Resolve <IMeasuringElementEditorViewModel>(MeasuringKeys.DISCRET_MEASURING_ELEMENT +
                                                                      ApplicationGlobalNames.CommonInjectionStrings
                                                                      .EDITOR_VIEWMODEL) as
                IDiscretMeasuringElementEditorViewModel;

            discretMeasuringElementEditorViewModel.BitAddressEditorViewModel =
                new BitAddressEditorViewModelFactory().CreateBitAddressEditorViewModel(discretMeasuringElement
                                                                                       .AddressOfBit);
            InitDefaults(discretMeasuringElementEditorViewModel, discretMeasuringElement);
            return(discretMeasuringElementEditorViewModel);
        }
Beispiel #4
0
        public static async Task <Result <bool> > GetDiscretElementValue(
            this IDiscretMeasuringElement discretMeasuringElement,
            DeviceContext deviceContext)
        {
            if (discretMeasuringElement.AddressOfBit.NumberOfFunction == 3)
            {
                if (deviceContext.DeviceMemory.DeviceMemoryValues.ContainsKey(discretMeasuringElement.AddressOfBit
                                                                              .Address))
                {
                    var result = deviceContext.DeviceMemory.DeviceMemoryValues[discretMeasuringElement
                                                                               .AddressOfBit
                                                                               .Address];
                    return(Result <bool> .Create(
                               result.GetBoolArrayFromUshort()[discretMeasuringElement.AddressOfBit.BitAddressInWord], true));
                }
                else
                {
                    if (deviceContext.DataProviderContainer.DataProvider.IsSuccess)
                    {
                        var res =
                            await deviceContext.DataProviderContainer.DataProvider.Item.ReadHoldingResgistersAsync(
                                discretMeasuringElement.AddressOfBit
                                .Address, discretMeasuringElement.NumberOfPoints,
                                "Read discret: " + discretMeasuringElement.Name);

                        if (res.IsSuccessful)
                        {
                            return(Result <bool> .Create(
                                       res.Result.First().GetBoolArrayFromUshort()[
                                           discretMeasuringElement.AddressOfBit.BitAddressInWord], true));
                        }
                    }
                }
            }

            if (discretMeasuringElement.AddressOfBit.NumberOfFunction == 1)
            {
                if (deviceContext.DeviceMemory.DeviceBitMemoryValues.ContainsKey(discretMeasuringElement.AddressOfBit
                                                                                 .Address))
                {
                    return(Result <bool> .Create(deviceContext.DeviceMemory.DeviceBitMemoryValues[discretMeasuringElement
                                                                                                  .AddressOfBit
                                                                                                  .Address], true));
                }
                else
                {
                    if (deviceContext.DataProviderContainer.DataProvider.IsSuccess)
                    {
                        var res = await deviceContext.DataProviderContainer.DataProvider.Item.ReadCoilStatusAsync(
                            discretMeasuringElement.AddressOfBit.Address,
                            "Read discret: " + discretMeasuringElement.Name);

                        if (res.IsSuccessful)
                        {
                            deviceContext.DeviceMemory.DeviceBitMemoryValues.Add(discretMeasuringElement
                                                                                 .AddressOfBit
                                                                                 .Address, res.Result);
                            return(Result <bool> .Create(deviceContext.DeviceMemory.DeviceBitMemoryValues[
                                                             discretMeasuringElement.AddressOfBit
                                                             .Address], true));
                        }
                    }
                }
            }

            return(Result <bool> .Create(false));
        }