Ejemplo n.º 1
0
        private void DoOnDataPointRealValueChanged(object sender, md.Event.DataPointRealValueEventArgs e)
        {
            List <DataPointRealValue>    dataPointRealValues    = e.DataPointRealValues;
            List <DataPointRealValueDto> dataPointRealValueDtos = DataObjectMapper.ConvertToListFrom(dataPointRealValues);

            RaiseCurrentReceiveDataChangedEvent(dataPointRealValueDtos);
        }
Ejemplo n.º 2
0
        private void ReadModbus()
        {
            try
            {
                foreach (var modbusUint in this.ModbusUnits)
                {
                    if (!modbusUint.Connector.IsConnect())
                    {
                        modbusUint.Connector.Connect();
                    }
                }

                while (CanReadModbus())
                {
                    foreach (var modbusUint in this.ModbusUnits)
                    {
                        foreach (var readRegisterCommand in modbusUint.AllReadRegisterCommands)
                        {
                            var recvBytes = modbusUint.Connector.Send(readRegisterCommand.ReadCommand);
                            if (recvBytes != null)
                            {
                                AnalyzeRecivedDataReponse reponse = ModbusTCP.AnalyzeRecivedDataStatic(modbusUint.DataAnalyzeMode, readRegisterCommand.ReadCommand, recvBytes);
                                if (reponse.ModbusReponseSuccess && reponse.AnalyzeRecivedDataSuccess)
                                {
                                    List <DataPoint> dataPointsWhoseRealTimeDataChanged = ModbusTCP.SetDataPointValueFromRegisterValue(reponse.Registers, modbusUint.AllDataPoints);

                                    List <DataPointRealValue> dataPointRealValues = DataObjectMapper.ConvertToListFrom(dataPointsWhoseRealTimeDataChanged);
                                    RaiseCurrentReceiveDataChangedEvent(dataPointRealValues);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ReadModbus();
            }
        }
Ejemplo n.º 3
0
        private void WriteModbus()
        {
            try
            {
                foreach (var modbusUint in this.ModbusUnits)
                {
                    if (!modbusUint.Connector.IsConnect())
                    {
                        modbusUint.Connector.Connect();
                    }
                }

                while (CanWirteModbus())
                {
                    foreach (var modbusUint in this.ModbusUnits)
                    {
                        if (modbusUint.ToWriteRegisterCommands != null && modbusUint.ToWriteRegisterCommands.Count > 0)
                        {
                            WriteRegisterCommand currentWriteRegisterCommand = null;
                            List <byte>          recvBytes = null;
                            lock (writeMobusThreadLoker)
                            {
                                currentWriteRegisterCommand = modbusUint.ToWriteRegisterCommands.Dequeue();
                            }

                            if (currentWriteRegisterCommand != null)
                            {
                                recvBytes = modbusUint.Connector.Send(currentWriteRegisterCommand.WriteCommand);
                                if (recvBytes != null)
                                {
                                    AnalyzeRecivedDataReponse reponse = ModbusTCP.AnalyzeRecivedDataStatic(modbusUint.DataAnalyzeMode, currentWriteRegisterCommand.WriteCommand, recvBytes);
                                    if (reponse.ModbusReponseSuccess && reponse.AnalyzeRecivedDataSuccess)
                                    {
                                        var dataPointsWhoseRealTimeDataChanged = ModbusTCP.SetDataPointValueFromRegisterValue(reponse.Registers, modbusUint.AllDataPoints);

                                        List <DataPointRealValue> dataPointRealValues = DataObjectMapper.ConvertToListFrom(dataPointsWhoseRealTimeDataChanged);
                                        RaiseCurrentReceiveDataChangedEvent(dataPointRealValues);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteModbus();
            }
        }