Exemplo n.º 1
0
        /// <summary>
        /// Acquisition thread
        ///		Awaits for trigger;
        ///		After configured period send appropriate command to MdbSim for each point type
        /// </summary>
        private void Acquisition_DoWork()
        {
            while (true)
            {
                try
                {
                    acquisitionTrigger.WaitOne();
                    DO_REG_sekunde++;

                    HR_INT_sekunde++;
                    if (DO_REG_sekunde == ConfigReader.Instance.GetAcquisitionInterval("DigOut"))
                    {
                        ModbusReadCommandParameters p = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_COILS, ConfigReader.Instance.GetStartAddress("DigOut"), ConfigReader.Instance.GetNumberOfRegisters("DigOut"));;
                        ModbusFunction fn             = FunctionFactory.CreateModbusFunction(p);
                        this.commandExecutor.EnqueueCommand(fn);
                        DO_REG_sekunde = 0;
                    }

                    if (HR_INT_sekunde == ConfigReader.Instance.GetAcquisitionInterval("AnaOut"))
                    {
                        ModbusReadCommandParameters p = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_HOLDING_REGISTERS, ConfigReader.Instance.GetStartAddress("AnaOut"), ConfigReader.Instance.GetNumberOfRegisters("AnaOut"));;
                        ModbusFunction fn             = FunctionFactory.CreateModbusFunction(p);
                        this.commandExecutor.EnqueueCommand(fn);
                        HR_INT_sekunde = 0;
                    }
                }
                catch (Exception ex)
                {
                    string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                    stateUpdater.LogMessage(message);
                }
            }
        }
Exemplo n.º 2
0
            public static Func <DbDataReader, ExpandoObject> Get(DbDataReader reader,
                                                                 string tableName,
                                                                 IDbConnection connection,
                                                                 IDbTransaction transaction)
            {
                var result = (Func <DbDataReader, ExpandoObject>)null;
                var key    = (long)Enumerable.Range(0, reader.FieldCount)
                             .Select(reader.GetName)
                             .Join(".")
                             .GetHashCode();

                if (tableName != null)
                {
                    key += tableName.GetHashCode();
                }
                if (string.IsNullOrEmpty(connection?.ConnectionString) == false)
                {
                    key += connection.ConnectionString.GetHashCode();
                }
                if (m_cache.TryGetValue(key, out result) == false)
                {
                    result = FunctionFactory.GetDataReaderToExpandoObjectConverterFunction(reader, tableName, connection, transaction);
                    m_cache.TryAdd(key, result);
                }
                return(result);
            }
Exemplo n.º 3
0
        /// <summary>
        /// Method that is executed when write button is clicked on control window;
        /// Method should create write command parameters and provide it to FunctionFactory
        /// </summary>
        /// <param name="obj">Not used</param>
        private void WriteCommand_Execute(object obj)
        {
            try
            {
                ModbusWriteCommandParameters mdb = null;
                switch (Type)
                {
                case PointType.DIGITAL_OUTPUT:
                    mdb = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_COIL, Address, commandedValue);
                    break;

                case PointType.ANALOG_OUTPUT:
                    mdb = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_REGISTER, Address, commandedValue);
                    break;
                }

                ModbusFunction fn = FunctionFactory.CreateModbusFunction(mdb);
                this.commandExecutor.EnqueueCommand(fn);
            }
            catch (Exception ex)
            {
                string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                this.stateUpdater.LogMessage(message);
            }
        }
Exemplo n.º 4
0
        private static void ReadEvaluationSchemeConfig(
            JsonElement configElem,
            out Func <double, double> fn,
            out ParamSamplingInfo paramSamplingInfo,
            out double gradientMseWeight)
        {
            // Get the customEvaluationSchemeConfig section.
            if (!configElem.TryGetProperty("customEvaluationSchemeConfig", out JsonElement evalSchemeElem))
            {
                throw new Exception("customEvaluationSchemeConfig not defined.");
            }

            // Read function ID.
            string     functionIdStr = JsonReadMandatoryUtils.ReadStringMandatory(evalSchemeElem, "functionId");
            FunctionId functionId    = (FunctionId)Enum.Parse(typeof(FunctionId), functionIdStr);

            fn = FunctionFactory.GetFunction(functionId);

            // Read sample interval min and max, and sample resolution.
            double sampleIntervalMin = JsonReadMandatoryUtils.ReadDoubleMandatory(evalSchemeElem, "sampleIntervalMin");
            double sampleIntervalMax = JsonReadMandatoryUtils.ReadDoubleMandatory(evalSchemeElem, "sampleIntervalMax");
            int    sampleResolution  = JsonReadMandatoryUtils.ReadIntMandatory(evalSchemeElem, "sampleResolution");

            paramSamplingInfo = new ParamSamplingInfo(sampleIntervalMin, sampleIntervalMax, sampleResolution);

            // Read the weight to apply to the gradientMse readings in the final fitness score.
            // 0 means don't use the gradient measurements, 1 means give them equal weight to the y position readings at each x sample point.
            gradientMseWeight = JsonReadMandatoryUtils.ReadDoubleMandatory(evalSchemeElem, "gradientMseWeight");
        }
Exemplo n.º 5
0
            public static Action <DbCommand, IList <TEntity> > Get(string cacheKey,
                                                                   IEnumerable <DbField> inputFields,
                                                                   IEnumerable <DbField> outputFields,
                                                                   int batchSize,
                                                                   IDbSetting dbSetting)
            {
                var key = (long)cacheKey.GetHashCode() + batchSize.GetHashCode();

                if (inputFields?.Any() == true)
                {
                    foreach (var field in inputFields)
                    {
                        key += field.GetHashCode();
                    }
                }
                if (outputFields?.Any() == true)
                {
                    foreach (var field in outputFields)
                    {
                        key += field.GetHashCode();
                    }
                }
                var func = (Action <DbCommand, IList <TEntity> >)null;

                if (m_cache.TryGetValue(key, out func) == false)
                {
                    func = FunctionFactory.GetDataEntitiesDbCommandParameterSetterFunction <TEntity>(inputFields, outputFields, batchSize, dbSetting);
                    m_cache.TryAdd(key, func);
                }
                return(func);
            }
Exemplo n.º 6
0
        /// <summary>
        /// Method that is executed when read button is clicked on control window;
        /// Method should create read command parameters and provide it to FunctionFactory
        /// </summary>
        /// <param name="obj">Not used</param>
        private void ReadCommand_Execute(object obj)
        {
            try
            {
                ConfigReader reader = ConfigReader.Instance;

                ModbusReadCommandParameters mdb = null;

                if (Type == PointType.ANALOG_INPUT)
                {
                    mdb = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_INPUT_REGISTERS, Address, 1);
                }
                if (Type == PointType.DIGITAL_OUTPUT)
                {
                    mdb = new ModbusReadCommandParameters(6, (byte)Type, Address, 1);
                }
                if (Type == PointType.DIGITAL_INPUT)
                {
                    mdb = new ModbusReadCommandParameters(6, (byte)Type, Address, 1);
                }
                if (Type == PointType.ANALOG_OUTPUT)
                {
                    mdb = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_HOLDING_REGISTERS, Address, 1);
                }

                ModbusFunction fn = FunctionFactory.CreateModbusFunction(mdb);
                this.commandExecutor.EnqueueCommand(fn);
            }
            catch (Exception ex)
            {
                string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                this.stateUpdater.LogMessage(message);
            }
        }
Exemplo n.º 7
0
            public static Action <DbCommand, TEntity> Get(string cacheKey,
                                                          IEnumerable <DbField> inputFields,
                                                          IEnumerable <DbField> outputFields)
            {
                var key  = (long)cacheKey.GetHashCode();
                var func = (Action <DbCommand, TEntity>)null;

                if (inputFields != null)
                {
                    foreach (var field in inputFields)
                    {
                        key += field.GetHashCode();
                    }
                }
                if (outputFields != null)
                {
                    foreach (var field in outputFields)
                    {
                        key += field.GetHashCode();
                    }
                }
                if (m_cache.TryGetValue(key, out func) == false)
                {
                    func = FunctionFactory.GetDataEntityDbCommandParameterSetterFunction <TEntity>(inputFields, outputFields);
                    m_cache.TryAdd(key, func);
                }
                return(func);
            }
Exemplo n.º 8
0
        private void ReadCommand_Execute(object obj)
        {
            try
            {
                // TODO implement
                ModbusReadCommandParameters p = null;
                switch (type)
                {
                case PointType.DO_REG:
                    p = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_COILS, address, 1);
                    break;

                case PointType.DI_REG:
                    p = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_DISCRETE_INPUTS, address, 1);
                    break;

                case PointType.IN_REG:
                    p = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_INPUT_REGISTERS, address, 1);
                    break;
                }
                ModbusFunction fn = FunctionFactory.CreateModbusFunction(p);
                this.commandExecutor.ExecuteCommand(fn);
            }
            catch (Exception ex)
            {
                string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                this.stateUpdater.LogMessage(message);
            }
        }
Exemplo n.º 9
0
        static ComplexExpressionTreeBuilderExtensionsTests()
        {
            var targetAssembly = Assembly.LoadFrom("TAlex.MathCore.ComplexExpressions.Extensions.dll");

            ConstantFactory = new ConstantFlyweightFactory <object>();
            ConstantFactory.LoadFromAssemblies(new List <Assembly> {
                targetAssembly
            });

            FunctionFactory = new FunctionFactory <object>();
            FunctionFactory.LoadFromAssemblies(new List <Assembly> {
                targetAssembly
            });

            ExpressionTreeBuilder = new ComplexExpressionTreeBuilder
            {
                ConstantFactory = ConstantFactory,
                FunctionFactory = FunctionFactory
            };

            FunctionsTestCasesData = FunctionFactory.GetMetadata().Select(x =>
            {
                var d = new TestCaseData(x);
                d.SetName(String.Format("ShouldContainsCorrectedExampleUsages: {0}", x.DisplayName));
                return(d);
            }).ToList();
        }
        /// <summary>
        /// Reads <see cref="Control"/> statement and modifies the context.
        /// </summary>
        /// <param name="statement">A statement to process.</param>
        /// <param name="context">Expression context.</param>
        /// <param name="validation">Validation.</param>
        /// <param name="validate">Validate.</param>
        public void Read(Control statement, EvaluationContext context, SpiceNetlistValidationResult validation, bool validate)
        {
            if (statement.Parameters == null)
            {
                throw new ArgumentNullException(nameof(statement));
            }

            foreach (Parameter param in statement.Parameters)
            {
                if (param is Models.Netlist.Spice.Objects.Parameters.AssignmentParameter assignmentParameter)
                {
                    if (!assignmentParameter.HasFunctionSyntax)
                    {
                        string parameterName       = assignmentParameter.Name;
                        string parameterExpression = assignmentParameter.Value;

                        try
                        {
                            SetParameter(parameterName, parameterExpression, context);
                        }
                        catch (Exception e)
                        {
                            if (validate)
                            {
                                validation.Add(
                                    new ValidationEntry(
                                        ValidationEntrySource.Reader,
                                        ValidationEntryLevel.Warning,
                                        $"Problem with setting param `{assignmentParameter.Name}` with expression =`{assignmentParameter.Value}`",
                                        statement.LineInfo,
                                        exception: e));
                            }
                        }
                    }
                    else
                    {
                        FunctionFactory factory = new FunctionFactory();

                        context.AddFunction(
                            assignmentParameter.Name,
                            assignmentParameter.Value,
                            assignmentParameter.Arguments,
                            factory.Create(
                                assignmentParameter.Name,
                                assignmentParameter.Arguments,
                                assignmentParameter.Value));
                    }
                }
                else
                {
                    validation.Add(
                        new ValidationEntry(
                            ValidationEntrySource.Reader,
                            ValidationEntryLevel.Warning,
                            ".PARAM supports only assignments",
                            statement.LineInfo));
                }
            }
        }
Exemplo n.º 11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddSingleton <IFunction>(FunctionFactory.BuildFunction(Configuration));
            services.AddSingleton <ICompiler>(new DefaultCompiler(new DefaultParser(), new DefaultReferencesManager()));
            services.AddSingleton <IInvoker>(new DefaultInvoker());
        }
Exemplo n.º 12
0
        /// <summary>
        /// Executes an analog write command.
        /// </summary>
        /// <param name="configItem">The configuration item.</param>
        /// <param name="transactionId">The transaction identifier.</param>
        /// <param name="remoteUnitAddress">The remote unit address.</param>
        /// <param name="pointAddress">The point address.</param>
        /// <param name="value">The value.</param>
        private void ExecuteAnalogCommand(IConfigItem configItem, ushort transactionId, byte remoteUnitAddress, ushort pointAddress, int value)
        {
            ushort raw = eguConverter.ConvertToRaw(configItem.ScaleFactor, configItem.Deviation, value);
            ModbusWriteCommandParameters p = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_REGISTER, pointAddress, (ushort)raw, transactionId, remoteUnitAddress);
            IModbusFunction fn             = FunctionFactory.CreateModbusFunction(p);

            this.functionExecutor.EnqueueCommand(fn);
        }
Exemplo n.º 13
0
 public static Func <DbDataReader, TEntity> Get(DbDataReader reader)
 {
     if (m_func == null)
     {
         m_func = FunctionFactory.GetDataReaderToDataEntityFunction <TEntity>(reader);
     }
     return(m_func);
 }
Exemplo n.º 14
0
 public static Func <DbDataReader, TEntity> Get(DbDataReader reader, IDbConnection connection, IDbTransaction transaction)
 {
     if (m_func == null)
     {
         m_func = FunctionFactory.GetDataReaderToDataEntityConverterFunction <TEntity>(reader, connection, transaction);
     }
     return(m_func);
 }
Exemplo n.º 15
0
        public void TestAve()
        {
            IFunction func = FunctionFactory.Create(CalcEnum.Ave);

            func.Add(100);
            func.Add(200);
            Assert.AreEqual(func.GetValue(), 150);
        }
Exemplo n.º 16
0
        public void TestCount()
        {
            IFunction func = FunctionFactory.Create(CalcEnum.Count);

            func.Add(1);
            func.Add(1);
            Assert.AreEqual(func.GetValue(), 2);
        }
Exemplo n.º 17
0
 public static Func <DbDataReader, ExpandoObject> Get(DbDataReader reader)
 {
     if (m_func == null)
     {
         m_func = FunctionFactory.GetDataReaderToExpandoObjectFunction(reader);
     }
     return(m_func);
 }
Exemplo n.º 18
0
        public static void CompileFunction(string language, string functionFileName, string moduleName, string functionHandler)
        {
            FunctionFactory factory      = new FunctionFactory(BASE_PATH, PACKAGES_SUBPATH);
            string          functionPath = factory.CreateEnvironmentPath(BASE_PATH, language, functionFileName);
            IFunction       function     = factory.CompileFunction(functionPath, moduleName, functionHandler);

            Environment.SetEnvironmentVariable("BASE_PATH", functionPath);
            Environment.SetEnvironmentVariable("PUBLISH_PATH", ".");
        }
Exemplo n.º 19
0
        public void KTest()
        {
            Point3D x        = null; // TODO: Initialize to an appropriate value
            double  expected = 0F;   // TODO: Initialize to an appropriate value
            double  actual;

            actual = FunctionFactory.K(x);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemplo n.º 20
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            var function = FunctionFactory.GetFunction(Configuration);
            var timeout  = FunctionFactory.GetFunctionTimeout(Configuration);

            services.AddTransient <IInvoker>(_ => new CompiledFunctionInvoker(function, timeout));
            services.AddSingleton <IParameterHandler>(new DefaultParameterHandler(Configuration));
        }
Exemplo n.º 21
0
        public DataTypeValue Evaluate(EvaluationContext ctx, string SchemeID)
        {
            IList <DataTypeValue> rets = new List <DataTypeValue>();

            foreach (IEvaluatable e in this._evaluatable)
            {
                rets.Add(e.Evaluate(ctx, SchemeID));
            }
            return(FunctionFactory.Evaluate(this._functionId, rets.ToArray(), ctx));
        }
Exemplo n.º 22
0
        public void QTest()
        {
            Point3D x        = new Point3D(1, 1, 1);             // TODO: Initialize to an appropriate value
            Point3D ksi      = new Point3D(0, 0, 0);             // TODO: Initialize to an appropriate value
            double  expected = 1 / (4 * Math.PI * Math.Sqrt(3)); // TODO: Initialize to an appropriate value
            double  actual;

            actual = FunctionFactory.Q(x, ksi);
            Assert.IsTrue(Math.Abs(expected - actual) < Eps);
        }
Exemplo n.º 23
0
        public void Q1Test()
        {
            Point3D x        = new Point3D(1, 1, 1);
            Point3D ksi      = new Point3D(0, 0, 0);
            double  expected = -1 / (4 * Math.PI * Math.Sqrt(3) * Math.Sqrt(3) * Math.Sqrt(3));
            double  actual;

            actual = FunctionFactory.Q1(x, ksi);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 24
0
        public void CalculateOutputStepTest()
        {
            // 0 0 1 => 0
            // 1 1 1 => 1
            // 1 0 1 => 1
            // 0 1 1 => 0
            // test
            // 1 0 0 => ?
            var weightAdjust = new Func <TrainingCalcModel, double>((m) =>
            {
                return(m.Error * m.Input * m.ActualOutput * (1 - m.ActualOutput));
            });

            var inputNodes1 = new InputLayer()
            {
                new InputNode(0), // { InValue = 0 });
                new InputNode(1), // { InValue = 0 });
                new InputNode(2)  // { InValue = 1 });
            };


            var outnode = new OutputNode(1, FunctionFactory.GetActivationFunction(eActivationFunc.Step), weightAdjust);

            outnode.AddInputNodes(inputNodes1);
            outnode.Bias = 0.0;

            for (int x = 0; x < 100000; x++)
            {
                inputNodes1.SetInput(new double[] { 0.0, 0.0, 1.0 });
                outnode.CalculateOutput();
                outnode.AdjustWeights(0);
                inputNodes1.SetInput(new double[] { 1.0, 1.0, 1.0 });
                outnode.CalculateOutput();
                outnode.AdjustWeights(1);
                inputNodes1.SetInput(new double[] { 1.0, 0.0, 1.0 });
                outnode.CalculateOutput();
                outnode.AdjustWeights(1);
                inputNodes1.SetInput(new double[] { 0.0, 1.0, 1.0 });
                outnode.CalculateOutput();
                outnode.AdjustWeights(0);
            }

            outnode.SetInput(new double[] { 1.0, 0.0, 0.0 });
            outnode.CalculateOutput();

            var outp = outnode.Output;

            Assert.IsTrue(outp == 1);
            outnode.SetInput(new double[] { 0.0, 0.0, 0.0 });
            outnode.CalculateOutput();

            outp = outnode.Output;

            Assert.IsTrue(outp == 0.0);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Acquisition thread
        ///		Awaits for trigger;
        ///		After configured period send appropriate command to MdbSim for each point type
        ///
        ///		Kao uslov za while petlju korititi acquisitionStopSignal da bi se akvizicioni thread ugasio kada se aplikacija ugasi
        /// </summary>
        private void Acquisition_DoWork()
        {
            ConfigReader cr  = ConfigReader.Instance;
            int          cnt = 0;

            int DigOut = cr.GetAcquisitionInterval("DigOut");
            int DigIn  = cr.GetAcquisitionInterval("DigIn");
            int AnaOut = cr.GetAcquisitionInterval("AnaOut");
            int AnaIn  = cr.GetAcquisitionInterval("AnaIn");

            ModbusReadCommandParameters mrcp = null;
            ModbusFunction fn = null;

            while (true)
            {
                if (cnt % DigOut == 0)
                {
                    mrcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_COILS, cr.GetStartAddress("DigOut"), cr.GetNumberOfRegisters("DigOut"));
                    fn   = FunctionFactory.CreateModbusFunction(mrcp);
                    this.commandExecutor.EnqueueCommand(fn);
                }

                if (cnt % DigIn == 0)
                {
                    mrcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_DISCRETE_INPUTS, cr.GetStartAddress("DigIn"), cr.GetNumberOfRegisters("DigIn"));
                    fn   = FunctionFactory.CreateModbusFunction(mrcp);
                    this.commandExecutor.EnqueueCommand(fn);
                }

                if (cnt % AnaOut == 0)
                {
                    mrcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_HOLDING_REGISTERS, cr.GetStartAddress("AnaOut"), cr.GetNumberOfRegisters("AnaOut"));
                    fn   = FunctionFactory.CreateModbusFunction(mrcp);
                    this.commandExecutor.EnqueueCommand(fn);
                }

                if (cnt % AnaIn == 0)
                {
                    mrcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_INPUT_REGISTERS, cr.GetStartAddress("AnaIn"), cr.GetNumberOfRegisters("AnaIn"));
                    fn   = FunctionFactory.CreateModbusFunction(mrcp);
                    this.commandExecutor.EnqueueCommand(fn);
                }

                try
                {
                    acquisitionTrigger.WaitOne();
                    cnt++;
                }
                catch (Exception ex)
                {
                    string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                    stateUpdater.LogMessage(message);
                }
            }
        }
Exemplo n.º 26
0
        public void FunctionsAreContiniousTest()
        {
            var bound = new ParallelepipedNearBound();

            foreach (var point in bound.CornerPoints)
            {
                var x = FunctionFactory.G(point);
                var y = FunctionFactory.Gother(point);
                Assert.AreEqual(x, y);
            }
        }
        public void Given_Handler_Function_ShouldBe_Created()
        {
            var handler = this._fixture.ArrangeRegistrationHandler();
            var logger  = this._fixture.ArrangeLog();

            var factory = new FunctionFactory(handler);

            var function = factory.Create <IFooFunction>(logger);

            function.Log.Should().NotBeNull();
        }
Exemplo n.º 28
0
            public static Action <TEntity, object> Get(Field field)
            {
                var key  = (long)typeof(TEntity).FullName.GetHashCode() + field.Name.GetHashCode();
                var func = (Action <TEntity, object>)null;

                if (cache.TryGetValue(key, out func) == false)
                {
                    func = FunctionFactory.GetDataEntityPropertyValueSetterFunction <TEntity>(field);
                    cache.TryAdd(key, func);
                }
                return(func);
            }
Exemplo n.º 29
0
        private void Acquisition_DoWork()
        {
            int cnt = 0;

            ConfigReader cr    = ConfigReader.Instance;
            int          DOCnt = cr.GetAcquisitionIntervalForPointType(PointType.DIGITAL_OUTPUT);
            int          DICnt = cr.GetAcquisitionIntervalForPointType(PointType.DIGITAL_INPUT);
            int          AICnt = cr.GetAcquisitionIntervalForPointType(PointType.ANALOG_INPUT);
            int          AOCnt = cr.GetAcquisitionIntervalForPointType(PointType.ANALOG_OUTPUT);



            while (true)
            {
                //// TODO implement
                if (cnt % DOCnt == 0)
                {
                    // TODO implement
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_COILS, cr.GetStartAddressForPointType(PointType.DIGITAL_OUTPUT), cr.GetNumberOfRegistersForPointType(PointType.DIGITAL_OUTPUT));
                    ModbusFunction fn = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(fn);
                }
                if (cnt % DICnt == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_DISCRETE_INPUTS, cr.GetStartAddressForPointType(PointType.DIGITAL_INPUT), cr.GetNumberOfRegistersForPointType(PointType.DIGITAL_INPUT));
                    ModbusFunction fn = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(fn);
                }
                if (cnt % AOCnt == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_HOLDING_REGISTERS, cr.GetStartAddressForPointType(PointType.ANALOG_OUTPUT), cr.GetNumberOfRegistersForPointType(PointType.ANALOG_OUTPUT));
                    ModbusFunction fn = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(fn);
                }
                if (cnt % AICnt == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_INPUT_REGISTERS, cr.GetStartAddressForPointType(PointType.ANALOG_INPUT), cr.GetNumberOfRegistersForPointType(PointType.ANALOG_INPUT));
                    ModbusFunction fn = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(fn);
                }

                try
                {
                    acquisitionTrigger.WaitOne();
                    cnt++;
                }
                catch (Exception ex)
                {
                    string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                    stateUpdater.LogMessage(message);
                }
            }
        }
Exemplo n.º 30
0
        public void Given_ModuleTypeGeneric_Property_ShouldNotThrow_Exception()
        {
            var logger = new Mock <ILogger>();

            var factory = new FunctionFactory <FakeModule>();

            var service = factory.Create <IFakeFunctionWithILogger, ILogger>(logger.Object);

            service.Should().NotBeNull();
            service.Should().BeAssignableTo <IFakeFunctionWithILogger>();
            service.Log.Should().BeAssignableTo <ILogger>();
        }
        static ComplexExpressionTreeBuilderExtensionsTests()
        {
            var targetAssembly = Assembly.LoadFrom("TAlex.MathCore.ComplexExpressions.Extensions.dll");

            ConstantFactory = new ConstantFlyweightFactory<object>();
            ConstantFactory.LoadFromAssemblies(new List<Assembly> { targetAssembly });

            FunctionFactory = new FunctionFactory<object>();
            FunctionFactory.LoadFromAssemblies(new List<Assembly> { targetAssembly });

            ExpressionTreeBuilder = new ComplexExpressionTreeBuilder
            {
                ConstantFactory = ConstantFactory,
                FunctionFactory = FunctionFactory
            };

            FunctionsTestCasesData = FunctionFactory.GetMetadata().Select(x =>
            {
                var d = new TestCaseData(x);
                d.SetName(String.Format("ShouldContainsCorrectedExampleUsages: {0}", x.DisplayName));
                return d;
            }).ToList();
        }
 public FunctionFactoryTests()
 {
     this.testee = new FunctionFactory();
 }