//-------------------------------------------------------------------------------------------------// public EquipmentEngine(string rootFilePath) : base(rootFilePath) { const string STRLOG_MethodName = "EquipmentEngine"; Logfile.WriteCalled(null, STRLOG_MethodName); try { // // Create an instance of the Machine class // this.driverMachine = new DriverMachine(this.xmlNodeEquipmentConfig, null); // // Update the initialisation delay // this.powerupInitialiseDelay = this.driverMachine.InitialiseDelay; } catch (Exception ex) { // // Log the message and throw the exception back to the caller // Logfile.WriteError(ex.Message); throw; } Logfile.WriteCompleted(null, STRLOG_MethodName); }
//-------------------------------------------------------------------------------------------------// public DCDrive(XmlNode xmlNodeEquipmentConfig, DriverMachine.KeepAliveCallback keepAliveCallback) { const string STRLOG_MethodName = "DCDrive"; Logfile.WriteCalled(null, STRLOG_MethodName); try { // // Initialise local variables // this.keepAliveCallback = keepAliveCallback; this.initialised = false; // // Initialise properties // this.online = false; this.statusMessage = STRLOG_NotInitialised; this.lastError = null; this.connectionOpen = false; this.speedSetpoint = 0; // // Get the IP address and port number to use // XmlNode xmlNodeDCdrive = XmlUtilities.GetXmlNode(xmlNodeEquipmentConfig, Consts.STRXML_dcDrive); XmlNode xmlNodeNetwork = XmlUtilities.GetXmlNode(xmlNodeDCdrive, Consts.STRXML_network, false); this.ipaddr = XmlUtilities.GetXmlValue(xmlNodeNetwork, Consts.STRXML_ipAddr, false); IPAddress ipaddr = IPAddress.Parse(this.ipaddr); this.ipport = XmlUtilities.GetIntValue(xmlNodeNetwork, Consts.STRXML_ipPort); Logfile.Write(STRLOG_IPaddr + this.ipaddr.ToString() + Logfile.STRLOG_Spacer + STRLOG_IPport + this.ipport.ToString()); // // Get the network timeouts // XmlNode xmlNodeTimeouts = XmlUtilities.GetXmlNode(xmlNodeNetwork, Consts.STRXML_timeouts, false); this.receiveTimeout = XmlUtilities.GetIntValue(xmlNodeTimeouts, Consts.STRXML_receive); Logfile.Write(STRLOG_ReceiveTimout + this.receiveTimeout.ToString() + STRLOG_MilliSecs); // // Get Modbus slave identity // XmlNode xmlNodeModbus = XmlUtilities.GetXmlNode(xmlNodeDCdrive, Consts.STRXML_modbus, false); this.slaveId = XmlUtilities.GetIntValue(xmlNodeModbus, Consts.STRXML_slaveId); Logfile.Write(STRLOG_ModbusSlaveId + this.slaveId.ToString()); // // Get the flag to determine if equipment initialisation is required // this.doInitialise = XmlUtilities.GetBoolValue(xmlNodeDCdrive, Consts.STRXML_doInitialise, false); Logfile.Write(STRLOG_DoInitialise + this.doInitialise.ToString()); // // Get the time it takes to initialise // this.initialiseDelay = XmlUtilities.GetIntValue(xmlNodeDCdrive, Consts.STRXML_initialiseDelay); // // Determine the logging level for this class // try { this.logLevel = (Logfile.LoggingLevels)Utilities.GetIntAppSetting(STRLOG_ClassName); } catch { this.logLevel = Logfile.LoggingLevels.Minimum; } Logfile.Write(Logfile.STRLOG_LogLevel + this.logLevel.ToString()); } catch (Exception ex) { // // Log the message and throw the exception back to the caller // Logfile.WriteError(ex.Message); throw; } Logfile.WriteCompleted(null, STRLOG_MethodName); }
//-------------------------------------------------------------------------------------------------// public override ExecuteCommandInfo ProcessCommand(ExecuteCommandInfo executeCommandInfo) { const string STRLOG_MethodName = "ProcessCommand"; Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName); CommandInfo commandInfo = (CommandInfo)executeCommandInfo; bool success = false; string errorMessage = null; try { // // Process the execute command // ExecuteCommands executeCommand = (ExecuteCommands)commandInfo.command; switch (executeCommand) { case ExecuteCommands.StartExecution: // // Get the specification in XML format from the parameters and parse // string xmlSpecification = (string)commandInfo.parameters[0]; Specification specification = new Specification(this.xmlNodeEquipmentConfig); ValidationReport validationReport = specification.Parse(xmlSpecification); if (validationReport.accepted == false) { errorMessage = validationReport.errorMessage; break; } // // Create an instance of the driver for the specified setup // and then start the driver with the specification // if (specification.SetupId.Equals(Consts.STRXML_SetupId_OpenCircuitVaryField) == true) { this.driverMachine = new DriverMachine_OCVF(this.xmlNodeEquipmentConfig, specification); } else if (specification.SetupId.Equals(Consts.STRXML_SetupId_OpenCircuitVarySpeed) == true) { this.driverMachine = new DriverMachine_OCVS(this.xmlNodeEquipmentConfig, specification); } else if (specification.SetupId.Equals(Consts.STRXML_SetupId_ShortCircuitVaryField) == true) { this.driverMachine = new DriverMachine_SCVF(this.xmlNodeEquipmentConfig, specification); } else if (specification.SetupId.Equals(Consts.STRXML_SetupId_PreSynchronisation) == true) { this.driverMachine = new DriverMachine_PreSync(this.xmlNodeEquipmentConfig, specification); } else if (specification.SetupId.Equals(Consts.STRXML_SetupId_Synchronisation) == true) { this.driverMachine = new DriverMachine_Sync(this.xmlNodeEquipmentConfig, specification); } else { // // Unknown SetupId // throw new Exception(STRERR_UnknownSetupId + specification.SetupId); } // // Start execution of the specified setup // if ((success = this.driverMachine.Start()) == false) { errorMessage = this.driverMachine.LastError; } break; default: // // Unknown command // throw new Exception(STRERR_UnknownCommand + executeCommand.ToString()); } } catch (Exception ex) { success = false; errorMessage = ex.Message; } // // Update success of command execution // executeCommandInfo.success = success; string logMessage = STRLOG_Success + success.ToString(); if (success == false) { executeCommandInfo.errorMessage = errorMessage; logMessage += Logfile.STRLOG_Spacer + STRLOG_ErrorMessage + errorMessage; } Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage); return executeCommandInfo; }