/// <summary> /// Performs the configuration of the PROFIdtmDPV1 Communication DTM /// </summary> /// <param name="communication"> /// The communication. /// </param> /// <returns> /// <br>True: if configuration was successful</br> /// <br>False: if configuration was unsuccessful or errors occurred</br> /// </returns> public bool Run(Communication communication) { /* Class initialization */ var setBoard = new SpecificFlows.SetBoardName(); var setBaudRate = new SpecificFlows.SetBaudRate(); var setStartAddress = new SpecificFlows.SetStartAddress(); var setEndAddress = new SpecificFlows.SetEndAddress(); var setHighestStationAddress = new SpecificFlows.SetHighestStationAddress(); var setStationAddress = new SpecificFlows.SetStationAddress(); var pressOk = new SpecificFlows.ClickButtonOk(); var pressDefaults = new SpecificFlows.ClickButtonDefaults(); var pressCancel = new SpecificFlows.ClickButtonCancel(); var pressApply = new SpecificFlows.ClickButtonApply(); var waitForReady = new Functions.ApplicationArea.Validation.WaitUntilModuleIsReady(); var parser = new Functions.ApplicationArea.Execution.SettingParser(); string commUnit = communication.CommunicationHardwareName; string baudRate = string.Empty; string stationAddress = string.Empty; string highestStationAddress = string.Empty; string startAddress = string.Empty; string endAddress = string.Empty; bool baudRateSet = false; bool stationAddressSet = false; bool highestStationAddressSet = false; bool startAddressSet = false; bool endAddressSet = false; bool defaultConfig = false; /* Preconditions: * Check if commUnit is nullOrEmpty * Check for communication settings: * Baud Rate, Station Address, Highest Station Address, Start Address, End Address * * If no comm settings are present -> click defaults, set board and finish */ if (communication.CommunicationSettings.Count <= 0) { defaultConfig = true; } else { foreach (CommunicationSetting cs in communication.CommunicationSettings) { if (parser.Parse(cs.SettingName) == "baud rate") { if (!string.IsNullOrEmpty(cs.SettingValue)) { baudRateSet = true; baudRate = cs.SettingValue; } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "A configuration for \"Baud Rate\" exists but value is empty and will therefore be skipped"); } } if (parser.Parse(cs.SettingName) == "station address") { if (!string.IsNullOrEmpty(cs.SettingValue)) { stationAddressSet = true; stationAddress = cs.SettingValue; } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "A configuration for \"Station Address\" exists but value is empty and will therefore be skipped"); } } if (parser.Parse(cs.SettingName) == "highest station address") { if (!string.IsNullOrEmpty(cs.SettingValue)) { highestStationAddressSet = true; highestStationAddress = cs.SettingValue; } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "A configuration for \"Highest Station Address\" exists but value is empty and will therefore be skipped"); } } if (parser.Parse(cs.SettingName) == "start address") { if (!string.IsNullOrEmpty(cs.SettingValue)) { startAddressSet = true; startAddress = cs.SettingValue; } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "A configuration for \"Start Address\" exists but value is empty and will therefore be skipped"); } } if (parser.Parse(cs.SettingName) == "end address") { if (!string.IsNullOrEmpty(cs.SettingValue)) { endAddressSet = true; endAddress = cs.SettingValue; } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "A configuration for \"End Address\" exists but value is empty and will therefore be skipped"); } } } } /* Execution: * 1) Check if module is ready * 2) check if default flag is set, if so -> default config (press defaults, set board, apply, ok) * 3) Set link device * 4) Click button OK */ if (waitForReady.Run(30000)) { if (setBoard.Run(commUnit)) { if (defaultConfig) { // default config pressDefaults.Run(); pressApply.Run(); Log.Success(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Default Configuration finished without errors"); return(true); } bool result = true; if (baudRateSet) { if (setBaudRate.Run(baudRate)) { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Baud rate " + baudRate + " correctly set"); } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Baud rate " + baudRate + " not correctly set"); result = false; } } if (stationAddressSet) { if (setStationAddress.Run(stationAddress)) { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Station address " + baudRate + " correctly set"); } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Station address " + baudRate + " not correctly set"); result = false; } } if (highestStationAddressSet) { if (setHighestStationAddress.Run(highestStationAddress)) { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Highest station address " + highestStationAddress + " correctly set"); } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Highest station address " + highestStationAddress + " not correctly set"); result = false; } } if (startAddressSet) { if (setStartAddress.Run(startAddress)) { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Start address " + startAddress + " correctly set"); } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Start address " + startAddress + " not correctly set"); result = false; } } if (endAddressSet) { if (setEndAddress.Run(endAddress)) { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "End address " + endAddress + " correctly set"); } else { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "End address " + endAddress + " not correctly set"); result = false; } } if (result) { Log.Success(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Configuration finished without errors"); pressApply.Run(); return(true); } Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Configuration finished with errors"); pressApply.Run(); return(false); } Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "The board could not be set. Terminating the configuration"); return(false); } Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Module was not ready in time. Terminating the configuration"); return(false); }
/// <summary> /// Performs the configuration of the RSG45 HART Communication DTM /// </summary> /// <returns> /// <br>True: if configuration was successful</br> /// <br>False: if configuration was unsuccessful or errors occurred</br> /// </returns> public bool Run(Communication communication) { /* Class initialization */ var parser = new Functions.ApplicationArea.Execution.SettingParser(); var clickApply = new SpecificFlows.ClickButtonApply(); var isApplyEnabled = new SpecificFlows.IsApplyButtonEnabled(); var setEndAddress = new SpecificFlows.SetEndAddress(); var setStartAddress = new SpecificFlows.SetStartAddress(); var setIPAddress = new SpecificFlows.SetIPAddress(); var setPort = new SpecificFlows.SetPort(); var setTimeout = new SpecificFlows.SetTimeout(); var isModuleReady = new Functions.ApplicationArea.Validation.WaitUntilModuleIsReady(); List <bool> executionResults = new List <bool>(); bool isDefaultConfig = false; string commUnit = communication.CommunicationHardwareName; /* Precondition: * Check communication for settings and set bools accordingly: * Check for start address * Check for end address * * If not found, do a default scan from 0 to 0 */ if (string.IsNullOrEmpty(commUnit)) { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Communication Unit value is null. Not possible to configure correctly"); return(false); } //default config if (communication.CommunicationSettings.Count == 0) { isDefaultConfig = true; } /* Execution: * 1) Check if module is ready * 2) set the ip * 3) Set port, start/end address and timeout, if flags are set in preconditions * 4) Click button apply */ if (isModuleReady.Run(30000)) { if (setIPAddress.Run(commUnit)) { if (isApplyEnabled.Run()) { if (!isDefaultConfig) { bool result = true; // do extended config foreach (var st in communication.CommunicationSettings) { if (st.SettingValue != "") { switch (parser.Parse(st.SettingName)) { case "start address": executionResults.Add(setStartAddress.Run(st.SettingValue)); break; case "end address": executionResults.Add(setEndAddress.Run(st.SettingValue)); break; case "timeout": executionResults.Add(setTimeout.Run(st.SettingValue)); break; case "port": executionResults.Add(setPort.Run(st.SettingValue)); break; } } Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "The value for the setting " + st.SettingName + " is empty. Skipping configuration for this setting"); } // check for execution results for (int i = 0; i < executionResults.Count; i++) { if (!executionResults[i]) { result = false; } } if (result) { if (clickApply.Run()) { Log.Success(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Configuration finished without errors"); return(true); } Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Apply button is not enabled. Cannot save configuration"); return(false); } Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Configuration finished with errors"); int failCounter = 0; foreach (var bla in executionResults) { if (!bla) { failCounter++; } } Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), string.Format("{0} out of {1} configurations finished with status failed", failCounter, executionResults.Count)); clickApply.Run(); return(false); } else { if (clickApply.Run()) { Log.Success(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Configuration finished without errors"); return(true); } Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Apply button is not enabled. Cannot save configuration"); return(false); } } else { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Apply button is not enabled though a parameter was already changed"); return(false); } } else { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "IP was not correctly set"); return(false); } } else { Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Module was not ready in time"); return(false); } }
/// <summary> /// Performs the configuration of the HART Communication DTM /// </summary> /// <param name="communication"> /// The communication. /// </param> /// <returns> /// <br>True: if configuration was successful</br> /// <br>False: if configuration was unsuccessful or errors occurred</br> /// </returns> public bool Run(Communication communication) { /* Class initialization */ SpecificFlows.ClickButtonApply clickApply = new SpecificFlows.ClickButtonApply(); SpecificFlows.SetSerialInterface setModem = new SpecificFlows.SetSerialInterface(); SpecificFlows.SetStartAddress setStartAddress = new SpecificFlows.SetStartAddress(); SpecificFlows.SetEndAddress setEndAddress = new SpecificFlows.SetEndAddress(); SpecificFlows.SetCommunicationInterface setCommInterface = new SpecificFlows.SetCommunicationInterface(); Functions.ApplicationArea.Validation.WaitUntilModuleIsReady waitForReady = new Functions.ApplicationArea.Validation.WaitUntilModuleIsReady(); CommunicationSetting communicationInterface = communication.GetSpecificSetting("Communication interface"); CommunicationSetting serialInterface = communication.GetSpecificSetting("Serial Interface"); // CommunicationSetting master = communication.GetSpecificSetting("Master"); // CommunicationSetting preamble = communication.GetSpecificSetting("Preamble"); // CommunicationSetting retries = communication.GetSpecificSetting("Number of communication retries"); CommunicationSetting startAddress = communication.GetSpecificSetting("Start address"); CommunicationSetting endAddress = communication.GetSpecificSetting("End address"); bool isPassed = true; if (waitForReady.Run(30000)) { if (communicationInterface != null) { if (!setCommInterface.Run(communicationInterface.SettingValue)) { isPassed = false; Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), communicationInterface.SettingName + " was not set correctly."); } } if (serialInterface != null) { if (!setModem.Run(serialInterface.SettingValue)) { isPassed = false; Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), serialInterface.SettingName + " was not set correctly."); } } //if (master != null) //{ // if (!setMaster.Run(master.SettingValue)) // { // isPassed = false;; // Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), master.SettingName + " was not set correctly."); // } //} //if (preamble != null) //{ // if (!setPreamble.Run(preamble.SettingValue)) // { // isPassed = false; // Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), preamble.SettingName + " was not set correctly."); // } //} //if (retries != null) //{ // if (!setRetries.Run(retries.SettingValue)) // { // isPassed = false; // Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), retries.SettingName + " was not set correctly."); // } //} if (startAddress != null) { if (!setStartAddress.Run(startAddress.SettingValue)) { isPassed = false; Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), startAddress.SettingName + " was not set correctly."); } } if (endAddress != null) { if (!setEndAddress.Run(endAddress.SettingValue)) { isPassed = false; Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), endAddress.SettingName + " was not set correctly."); } } if (clickApply.Run()) { Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Configuration done"); } } else { isPassed = false; Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "DTM was not ready after 30 seconds"); } return(isPassed); }