示例#1
0
        public void HandleReceivedBytes(byte[] receivedBytes)
        {
            Dictionary <Tuple <PointType, ushort>, ushort> pointsToupdate = this.currentCommand?.ParseResponse(receivedBytes);

            if (UpdatePointEvent != null)
            {
                foreach (var point in pointsToupdate)
                {
                    UpdatePointEvent.Invoke(point.Key.Item1, point.Key.Item2, point.Value);
                    stateUpdater.LogMessage(string.Format(RECEIVED_MESSAGE, point.Key.Item1, point.Key.Item2, point.Value));
                }
            }
        }
示例#2
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);
                }
            }
        }
示例#3
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);
                }
            }
        }
示例#4
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);
                }
            }
        }
示例#5
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()
 {
     try
     {
         throw new NotImplementedException();
     }
     catch (Exception ex)
     {
         string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
         stateUpdater.LogMessage(message);
     }
 }
示例#6
0
        /// <summary>
        /// Acquisition thread
        ///		Awaits for trigger;
        ///		After configured period send appropriate command to MdbSim for each point type
        /// </summary>
        private void Acquisition_DoWork()
        {
            int cnt = 0;

            ConfigReader cr = ConfigReader.Instance;

            int DOCnt = cr.GetAcquisitionInterval("DigOut");
            int AOCnt = cr.GetAcquisitionInterval("AnaOut");

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

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



                //ModbusWriteCommandParameters mwcp1 = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_COIL, cr.GetStartAddress("DigOut"), cr.GetNumberOfRegisters("DigOut"));
                //ModbusFunction mf1 = FunctionFactory.CreateModbusFunction(mwcp1);
                //this.commandExecutor.EnqueueCommand(mf1);

                //ModbusWriteCommandParameters mwcp2 = new ModbusWriteCommandParameters(6, (byte)ModbusFunctionCode.WRITE_SINGLE_REGISTER, cr.GetStartAddress("AnaOut"), cr.GetNumberOfRegisters("AnaOut"));
                //ModbusFunction mf2 = FunctionFactory.CreateModbusFunction(mwcp2);
                //this.commandExecutor.EnqueueCommand(mf2);

                try
                {
                    acquisitionTrigger.WaitOne();
                    cnt++;
                }
                catch (Exception ex)
                {
                    string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                    stateUpdater.LogMessage(message);
                }
            }
        }
示例#7
0
        /// <summary>
        /// Acquisition thread
        ///		Awaits for trigger;
        ///		After configured period send appropriate command to MdbSim for each point type
        /// </summary>
        private void Acquisition_DoWork()
        {
            int cnt = 0;

            ConfigReader cr = ConfigReader.Instance;

            int DOcnt1 = cr.GetAcquisitionInterval("DigOut1");
            int DOcnt2 = cr.GetAcquisitionInterval("DigOut2");

            int DIcnt1 = cr.GetAcquisitionInterval("DigIn1");
            int DIcnt2 = cr.GetAcquisitionInterval("DigIn2");

            int AOcnt1 = cr.GetAcquisitionInterval("AnaOut1");
            int AOcnt2 = cr.GetAcquisitionInterval("AnaOut2");

            int AIcnt1 = cr.GetAcquisitionInterval("AnaIn1");
            int AIcnt2 = cr.GetAcquisitionInterval("AnaIn2");

            while (true)
            {
                if (cnt % DOcnt1 == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_COILS, cr.GetStartAddress("DigOut1"), cr.GetNumberOfRegisters("DigOut1"));
                    ModbusFunction mf = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(mf);
                }
                if (cnt % DOcnt2 == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_COILS, cr.GetStartAddress("DigOut2"), cr.GetNumberOfRegisters("DigOut2"));
                    ModbusFunction mf = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(mf);
                }
                if (cnt % DIcnt1 == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_DISCRETE_INPUTS, cr.GetStartAddress("DigIn1"), cr.GetNumberOfRegisters("DigIn1"));
                    ModbusFunction mf = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(mf);
                }
                if (cnt % DIcnt2 == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_DISCRETE_INPUTS, cr.GetStartAddress("DigIn2"), cr.GetNumberOfRegisters("DigIn2"));
                    ModbusFunction mf = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(mf);
                }
                if (cnt % AOcnt1 == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_HOLDING_REGISTERS, cr.GetStartAddress("AnaOut1"), cr.GetNumberOfRegisters("AnaOut1"));
                    ModbusFunction mf = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(mf);
                }
                if (cnt % AOcnt2 == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_HOLDING_REGISTERS, cr.GetStartAddress("AnaOut2"), cr.GetNumberOfRegisters("AnaOut2"));
                    ModbusFunction mf = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(mf);
                }
                if (cnt % AIcnt1 == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_INPUT_REGISTERS, cr.GetStartAddress("AnaIn1"), cr.GetNumberOfRegisters("AnaIn1"));
                    ModbusFunction mf = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(mf);
                }
                if (cnt % AIcnt2 == 0)
                {
                    ModbusReadCommandParameters mcp = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_INPUT_REGISTERS, cr.GetStartAddress("AnaIn2"), cr.GetNumberOfRegisters("AnaIn2"));
                    ModbusFunction mf = FunctionFactory.CreateModbusFunction(mcp);
                    this.commandExecutor.EnqueueCommand(mf);
                }

                try
                {
                    cnt++;
                    // TODO implement
                    acquisitionTrigger.WaitOne();
                }
                catch (Exception ex)
                {
                    string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                    stateUpdater.LogMessage(message);
                }
            }
        }
示例#8
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()
        {
            try
            {
                ConfigReader reader = ConfigReader.Instance;
                int          AO, AO1, AI, AI1, DO, DO1, DI, DI1;
                AO = AO1 = reader.GetAcquisitionInterval("AnaOut");
                AI = AI1 = reader.GetAcquisitionInterval("AnaIn");
                DO = DO1 = reader.GetAcquisitionInterval("DigOut");
                DI = DI1 = reader.GetAcquisitionInterval("DigIn");

                int cnt = 0;
                ModbusReadCommandParameters mbParams = null;
                ModbusFunction fn = null;

                while (acquisitionStopSignal)
                {
                    if (cnt % AO == 0)
                    {
                        mbParams = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_HOLDING_REGISTERS, reader.GetStartAddress("AnaOut"), reader.GetNumberOfRegisters("AnaOut"));
                        fn       = FunctionFactory.CreateModbusFunction(mbParams);
                        commandExecutor.EnqueueCommand(fn);
                    }
                    if (cnt % AO1 == 0)
                    {
                        mbParams = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_HOLDING_REGISTERS, reader.GetStartAddress("AnaOut1"), reader.GetNumberOfRegisters("AnaOut1"));
                        fn       = FunctionFactory.CreateModbusFunction(mbParams);
                        commandExecutor.EnqueueCommand(fn);
                    }
                    if (cnt % AI == 0)
                    {
                        mbParams = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_INPUT_REGISTERS, reader.GetStartAddress("AnaIn"), reader.GetNumberOfRegisters("AnaIn"));
                        fn       = FunctionFactory.CreateModbusFunction(mbParams);
                        commandExecutor.EnqueueCommand(fn);
                    }
                    if (cnt % AI1 == 0)
                    {
                        mbParams = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_INPUT_REGISTERS, reader.GetStartAddress("AnaIn1"), reader.GetNumberOfRegisters("AnaIn1"));
                        fn       = FunctionFactory.CreateModbusFunction(mbParams);
                        commandExecutor.EnqueueCommand(fn);
                    }
                    if (cnt % DO == 0)
                    {
                        mbParams = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_COILS, reader.GetStartAddress("DigOut"), reader.GetNumberOfRegisters("DigOut"));
                        fn       = FunctionFactory.CreateModbusFunction(mbParams);
                        commandExecutor.EnqueueCommand(fn);
                    }
                    if (cnt % DO1 == 0)
                    {
                        mbParams = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_COILS, reader.GetStartAddress("DigOut1"), reader.GetNumberOfRegisters("DigOut1"));
                        fn       = FunctionFactory.CreateModbusFunction(mbParams);
                        commandExecutor.EnqueueCommand(fn);
                    }
                    if (cnt % DI == 0)
                    {
                        mbParams = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_DISCRETE_INPUTS, reader.GetStartAddress("DigIn"), reader.GetNumberOfRegisters("DigIn"));
                        fn       = FunctionFactory.CreateModbusFunction(mbParams);
                        commandExecutor.EnqueueCommand(fn);
                    }
                    if (cnt % DI1 == 0)
                    {
                        mbParams = new ModbusReadCommandParameters(6, (byte)ModbusFunctionCode.READ_DISCRETE_INPUTS, reader.GetStartAddress("DigIn1"), reader.GetNumberOfRegisters("DigIn1"));
                        fn       = FunctionFactory.CreateModbusFunction(mbParams);
                        commandExecutor.EnqueueCommand(fn);
                    }

                    try
                    {
                        ++cnt;
                        acquisitionTrigger.WaitOne();
                    }
                    catch (Exception ex)
                    {
                        string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                        stateUpdater.LogMessage(message);
                    }
                } // end while
            }
            catch (Exception ex)
            {
                string message = $"{ex.TargetSite.ReflectedType.Name}.{ex.TargetSite.Name}: {ex.Message}";
                stateUpdater.LogMessage(message);
            }
        }