public ParamArray(string configFile) { _paramArray = new Param[MAX_NUMBER_OF_PARAMS]; _numberOfParams = new int[Settings.BoardVersions.Length]; using (INIFile iniFile = new INIFile(configFile, false, true)) { for (int verNumber = 0; verNumber < Settings.BoardVersions.Length; verNumber++) // we need to load all related info from ini file // get the number of available params for the selected version { string sectionNumber = PARAMINFO_INI_SECTION_PARAMS_PREFIX + (verNumber + 1); int numOfAvailableParams = iniFile.GetValue(sectionNumber, PARAMINFO_INI_KEY_NUMBER_OF_AVAILABLE_PARAMS, 0); if (numOfAvailableParams == 0) { _logger.WriteLine(LogLevel.Error, $"Can't fill Control Param Info - Section [{sectionNumber}] Key {PARAMINFO_INI_KEY_NUMBER_OF_AVAILABLE_PARAMS}"); return; } _numberOfParams[verNumber] = numOfAvailableParams; for (int paramNumber = 0; paramNumber < numOfAvailableParams; paramNumber++) { if (verNumber == 0) // creating new param only once for the first board version { _paramArray[paramNumber] = new Param(); } string paramPrefix = "Param" + (paramNumber + 1) + "_"; int bytePosition = iniFile.GetValue(sectionNumber, paramPrefix + PARAMINFO_INI_KEY_BYTE_POSITION, INI_SECTION_NOT_AVAILABLE_VERIFIER); if (bytePosition == INI_SECTION_NOT_AVAILABLE_VERIFIER) { _logger.WriteLine(LogLevel.Error, $"Can't fill Control Param Info - Section [{sectionNumber}] Key {paramPrefix}"); continue; } string description = iniFile.GetValue(sectionNumber, paramPrefix + PARAMINFO_INI_KEY_DESCRIPTION, "INI Loading Error"); int bytesUsed = iniFile.GetValue(sectionNumber, paramPrefix + PARAMINFO_INI_KEY_BYTES_USED, 1); bool visible = iniFile.GetValue(sectionNumber, paramPrefix + PARAMINFO_INI_KEY_VISIBLE, false); int defaultValue = iniFile.GetValue(sectionNumber, paramPrefix + paramPrefix + PARAMINFO_INI_KEY_DEFAULT_VALUE, 0); ParamInfo paramInfo = new ParamInfo(description, bytePosition, bytesUsed, visible, defaultValue); _paramArray[paramNumber].SetParamInfo(verNumber, paramInfo); } } } }
} // prevent to call default constructor public ControlBitParam(string configFile) { _controlBitArray = new ControlBit[NUMBER_OF_CONTROL_BITS]; using (INIFile iniFile = new INIFile(configFile, false, true)) { // we need to load all related info from ini file for (int bitNumber = 0; bitNumber < NUMBER_OF_CONTROL_BITS; bitNumber++) { _controlBitArray[bitNumber] = new ControlBit(); for (int verNumber = 0; verNumber < Settings.BoardVersions.Length; verNumber++) { string sectionNumber = PARAMINFO_INI_SECTION_CONTROL_BITS_PREFIX + (verNumber + 1); string bitPrefix = "Bit" + bitNumber + "_"; int bitPosition = iniFile.GetValue(sectionNumber, bitPrefix + PARAMINFO_INI_KEY_BIT_POSITION, INI_SECTION_NOT_AVAILABLE_VERIFIER); if (bitPosition == INI_SECTION_NOT_AVAILABLE_VERIFIER) { _logger.WriteLine(LogLevel.Error, $"Can't fill Control RParam Info - Section [{sectionNumber}] is not available"); continue; } string description = iniFile.GetValue(sectionNumber, bitPrefix + PARAMINFO_INI_KEY_DESCRIPTION, "INI Loading Error"); int bitsUsed = iniFile.GetValue(sectionNumber, bitPrefix + PARAMINFO_INI_KEY_BITS_USED, 1); bool visible = iniFile.GetValue(sectionNumber, bitPrefix + PARAMINFO_INI_KEY_VISIBLE, false); int defaultValue = iniFile.GetValue(sectionNumber, bitPrefix + PARAMINFO_INI_KEY_DEFAULT_VALUE, 0); string[] valuesInfo = iniFile.GetValue(sectionNumber, bitPrefix + PARAMINFO_INI_KEY_VALUES_INFO, "INI Loading Error").Split(','); ControlBitInfo controlBitInfo = new ControlBitInfo(description, bitPosition, bitsUsed, visible, defaultValue, valuesInfo); _controlBitArray[bitNumber].SetControlBitInfo(verNumber, controlBitInfo); } } } }
/// <summary> /// Load App and Counter Board settings /// </summary> private void LoadSettings() { // Let's load all available Board Versions List <string> boardVersions = new List <string>(); using (INIFile iniFile = new INIFile(Settings.ApplicationPath + Defs.PARAMINFO_INI_FILE_NAME, false, true)) { for (byte loop = 0; loop < Defs.MAX_BOARD_VERSIONS; loop++) { string verName = iniFile.GetValue(Defs.PARAMINFO_INI_SECTION_PARAM_VERSIONS, Defs.PARAMINFO_INI_KEY_PARAM_VERSIONS_PREFIX + (loop + 1), ""); if (verName != "") { boardVersions.Add(verName); _logger.WriteLine(LogLevel.Info, $"Added board ver.{loop + 1} [{verName}]"); } } } Settings.BoardVersions = boardVersions.ToArray(); // Let's try to load all available counter board entries int boardsLoaded = 0; for (byte loop = 0; loop < Defs.MAX_BOARDS; loop++) { string sectionNumber = Defs.INI_SECT_CB_PREFIX_NAME + loop.ToString(); bool isAvailable = _iniFile.GetValue(sectionNumber, Defs.INI_KEY_CB_IS_AVAILABLE_FOR_REUSE, true); if (!isAvailable) // ini entry exists and not available for reuse { boardsLoaded++; Board board = new Board { IniPosition = loop, IsAvailableToReuse = false, IsEnabled = _iniFile.GetValue(sectionNumber, Defs.INI_KEY_CB_IS_ENABLED, true), Name = _iniFile.GetValue(sectionNumber, Defs.INI_KEY_CB_NAME, "Board #" + boardsLoaded.ToString()), ComPortNumber = _iniFile.GetValue(sectionNumber, Defs.INI_KEY_CB_COMPORT_NUMBER, 0) }; _logger.WriteLine(LogLevel.Info, $"Added info about board [{boardsLoaded}] - " + board.Name); int boardVersion = _iniFile.GetValue(sectionNumber, Defs.INI_KEY_CB_FW_VERSION, 0); if (boardVersion >= 0 && boardVersion < Settings.BoardVersions.Length) { board.BoardVersion = boardVersion; } else { _logger.WriteLine(LogLevel.Error, $"Board protocol version [{boardVersion}] is not valid; Using default version [{Defs.CB_DEFAULT_BOARD_VERSION}]"); board.BoardVersion = Defs.CB_DEFAULT_BOARD_VERSION; } _cbList.Add(board); } } _logger.WriteLine("Settings loaded"); }