Пример #1
0
        /// <summary>
        /// 在目标ModbusUnit集合中查找数据点所在的ModbusUnit
        /// </summary>
        /// <param name="allModbusUnits">目标ModbusUnit集合</param>
        /// <param name="dataPointNumber">数据点编号(唯一标识)</param>
        /// <returns>目标ModbusUnit</returns>
        public static ModbusUnit FindModbusUnit(List <ModbusUnit> allModbusUnits, string dataPointNumber)
        {
            ModbusUnit toFindModbusUnit = null;

            if (allModbusUnits != null && !string.IsNullOrWhiteSpace(dataPointNumber))
            {
                foreach (var modbusUnit in allModbusUnits)
                {
                    if (modbusUnit.AllDataPoints.Any(p => p.Number == dataPointNumber))
                    {
                        toFindModbusUnit = modbusUnit;
                        break;
                    }
                }
            }

            return(toFindModbusUnit);
        }
Пример #2
0
        /// <summary>
        /// 初始化运行环境
        /// </summary>
        /// <param name="modbusConfigFile">配置文件物理路径(包含名称+后缀):例如:Config/ModbusConfig.xml</param>
        public void InitializeFromConfigFile(string modbusConfigFile)
        {
            var modbusConfigs = GetModbusConfigFromFile(modbusConfigFile);

            ModbusUnits = new List <ModbusUnit>();

            int number = 0;

            foreach (var modbusConfig in modbusConfigs)
            {
                ModbusUnit modbusUnit = new ModbusUnit();
                modbusUnit.Number          = Convert.ToString(++number);
                modbusUnit.Connector       = new SockeHelper(modbusConfig.IP, modbusConfig.Port);
                modbusUnit.DataAnalyzeMode = modbusConfig.DataAnalyzeMode;
                modbusUnit.ModulesDic      = modbusConfig.ModulesFromConfigFile;
                modbusUnit.DataPointsDic   = modbusConfig.DataPointsFromConfigFile;
                var allDataPoints = modbusConfig.DataPointsFromConfigFileList;
                modbusUnit.AllDataPoints           = allDataPoints;
                modbusUnit.AllReadRegisterCommands = GetReadRegisterCommands(allDataPoints);

                ModbusUnits.Add(modbusUnit);
            }
        }