Example #1
0
        private void AutomationWorker_DoWork()
        {
            List <Tuple <ushort, ushort> > tuples = new List <Tuple <ushort, ushort> >()
            {
                new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_INPUT, (ushort)1000),
                new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_INPUT, (ushort)1001),
                new Tuple <ushort, ushort>((ushort)PointType.ANALOG_OUTPUT, (ushort)3000),
                new Tuple <ushort, ushort>((ushort)PointType.ANALOG_OUTPUT, (ushort)3001)
            };

            List <IPoint> points = storage.GetPoints(tuples);

            IConfigItem AO = configuration.GetConfigurationItems().Find(x => x.StartAddress == 3000);


            while (!shutDown)
            {
                if (points[0].RawValue == 0 && points[1].RawValue == 1 &&
                    points[2].RawValue > EGUConverter.ConvertToRaw(AO.A, AO.B, 2000) &&
                    points[3].RawValue < EGUConverter.ConvertToRaw(AO.A, AO.B, 1500))
                {
                    commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_COIL, 40, 1);
                    commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_REGISTER, 3000, (ushort)(points[2].RawValue - EGUConverter.ConvertToRaw(AO.A, AO.B, 10)));
                    commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_REGISTER, 3001, (ushort)(points[3].RawValue + EGUConverter.ConvertToRaw(AO.A, AO.B, 10)));
                }
                Thread.Sleep(2000); // don't burn CPU
            }
        }
Example #2
0
        private void AutomationWorker_DoWork()
        {
            List <Tuple <ushort, ushort> > tuples = new List <Tuple <ushort, ushort> >()
            {
                new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_OUTPUT, (ushort)2000),
                new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_OUTPUT, (ushort)2001),
                new Tuple <ushort, ushort>((ushort)PointType.ANALOG_OUTPUT, (ushort)1000)
            };

            List <IPoint> points = storage.GetPoints(tuples);
            IConfigItem   item   = configuration.GetConfigurationItems().Find(x => x.StartAddress == 1000);

            while (!shutDown)
            {
                ushort value = points[2].RawValue;
                if (points[0].RawValue == 1)
                {
                    value -= (ushort)EGUConverter.ConvertToRaw(item.A, item.B, 10);
                }

                if (points[1].RawValue == 1)
                {
                    value -= (ushort)EGUConverter.ConvertToRaw(item.A, item.B, 15);
                }

                if (value != points[2].RawValue)
                {
                    commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_REGISTER, 1000, value);
                }

                Thread.Sleep(1000);
            }
        }