Exemplo n.º 1
0
        //-------------------------------------------------------------------------------------------------//
        public override ExecuteCommandInfo ProcessCommand(ExecuteCommandInfo executeCommandInfo)
        {
            const string STRLOG_MethodName = "ProcessCommand";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            CommandInfo commandInfo = (CommandInfo)executeCommandInfo;

            bool success = true;
            string errorMessage = null;

            try
            {
                //
                // Process the execute command
                //
                ExecuteCommands executeCommand = (ExecuteCommands)commandInfo.command;

                switch (executeCommand)
                {
                    case ExecuteCommands.CreateConnection:

                        //
                        // Create a connection to the RedLion controller
                        //
                        if ((success = this.redLion.CreateConnection()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.CloseConnection:

                        //
                        // Close the connection to the RedLion controller
                        //
                        if ((success = this.redLion.CloseConnection()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.ResetACDrive:

                        //
                        // Reset the AC drive controller
                        //
                        if ((success = this.redLion.ResetACDrive()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.ConfigureACDrive:

                        //
                        // Get AC drive configuration from parameters
                        //
                        RedLion.ACDriveConfigs acDriveConfig = (RedLion.ACDriveConfigs)commandInfo.parameters[0];

                        //
                        // Configure the AC drive
                        //
                        if ((success = this.redLion.ConfigureACDrive(acDriveConfig)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.StartACDrive:

                        //
                        // Get AC drive mode from parameters
                        //
                        RedLion.ACDriveModes acDriveMode = (RedLion.ACDriveModes)commandInfo.parameters[0];

                        //
                        // Start the AC drive
                        //
                        if ((success = this.redLion.StartACDrive(acDriveMode)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.StopACDrive:

                        //
                        // Get AC drive mode from parameters
                        //
                        acDriveMode = (RedLion.ACDriveModes)commandInfo.parameters[0];

                        //
                        // Stop the AC drive
                        //
                        if ((success = this.redLion.StopACDrive(acDriveMode)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.TakeMeasurement:

                        //
                        // Take a measurement
                        //
                        RedLion.Measurements measurement = new RedLion.Measurements();
                        if ((success = this.redLion.TakeMeasurement(ref measurement)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        else
                        {
                            //
                            // Add the measurement values to results - ensure the order of the measurement values is the
                            // same as in EquipmentManager.cs
                            //
                            commandInfo.results = new object[] {
                                measurement.voltageMut,
                                measurement.currentMut,
                                measurement.powerFactorMut,
                                measurement.voltageVsd,
                                measurement.currentVsd,
                                measurement.powerFactorVsd,
                                measurement.speed,
                                measurement.torque
                            };
                        }
                        break;

                    default:

                        //
                        // Unknown command
                        //
                        errorMessage = STRERR_UnknownCommand + executeCommand.ToString();
                        success = false;
                        break;
                }
            }
            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;
        }
Exemplo n.º 2
0
        //-------------------------------------------------------------------------------------------------//
        public override ExecuteCommandInfo ProcessCommand(ExecuteCommandInfo executeCommandInfo)
        {
            const string STRLOG_MethodName = "ProcessCommand";

            Logfile.WriteCalled(this.logLevel, STRLOG_ClassName, STRLOG_MethodName);

            CommandInfo commandInfo = (CommandInfo)executeCommandInfo;

            bool success = true;
            string errorMessage = null;

            try
            {
                //
                // Process the execute command
                //
                ExecuteCommands executeCommand = (ExecuteCommands)commandInfo.command;

                switch (executeCommand)
                {
                    case ExecuteCommands.CreateConnection:

                        //
                        // Create a connection to the RedLion controller
                        //
                        if ((success = this.redLion.CreateConnection()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.CloseConnection:

                        //
                        // Close the connection to the RedLion controller
                        //
                        if ((success = this.redLion.CloseConnection()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.ResetACDrive:

                        //
                        // Reset the AC drive
                        //
                        if ((success = this.redLion.ResetACDrive()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.ConfigureACDrive:

                        //
                        // Get AC drive configuration from parameters
                        //
                        RedLion.ACDriveConfigs acCDriveConfig = (RedLion.ACDriveConfigs)commandInfo.parameters[0];

                        //
                        // Configure the AC drive with the specified configuration
                        //
                        if ((success = this.redLion.ConfigureACDrive(acCDriveConfig)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.StartACDrive:

                        //
                        // Start the AC drive
                        //
                        if ((success = this.redLion.StartACDrive()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.StopACDrive:

                        //
                        // Stop the AC drive
                        //
                        if ((success = this.redLion.StopACDrive()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.ResetDCDriveMut:

                        //
                        // Reset the DC drive
                        //
                        if ((success = this.redLion.ResetDCDriveMut()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.ConfigureDCDriveMut:

                        //
                        // Get DC drive configuration from parameters
                        //
                        RedLion.DCDriveMutConfigs dcDriveMutConfig = (RedLion.DCDriveMutConfigs)commandInfo.parameters[0];

                        //
                        // Configure the AC drive with the specified configuration
                        //
                        if ((success = this.redLion.ConfigureDCDriveMut(dcDriveMutConfig)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.StartDCDriveMut:

                        //
                        // Get DC drive mode from parameters
                        //
                        RedLion.DCDriveMutModes dcDriveMutMode = (RedLion.DCDriveMutModes)commandInfo.parameters[0];

                        //
                        // Start the DC drive
                        //
                        if ((success = this.redLion.StartDCDriveMut(dcDriveMutMode)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.StopDCDriveMut:

                        //
                        // Stop the DC drive
                        //
                        if ((success = this.redLion.StopDCDriveMut()) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.SetSpeedACDrive:

                        //
                        // Get speed from parameters
                        //
                        int speedACDrive = (int)commandInfo.parameters[0];

                        //
                        // Set the speed of the AC drive
                        //
                        if ((success = this.redLion.SetSpeedACDrive(speedACDrive)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.SetSpeedDCDriveMut:

                        //
                        // Get speed from parameters
                        //
                        int speedDCDriveMut = (int)commandInfo.parameters[0];

                        //
                        // Set the speed of the DC drive
                        //
                        if ((success = this.redLion.SetSpeedDCDriveMut(speedDCDriveMut)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.SetTorqueDCDriveMut:

                        //
                        // Get torque from parameters
                        //
                        int torqueDCDriveMut = (int)commandInfo.parameters[0];

                        //
                        // Set the torque of the DC drive
                        //
                        if ((success = this.redLion.SetTorqueDCDriveMut(torqueDCDriveMut)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.SetFieldDCDriveMut:

                        //
                        // Get torque from parameters
                        //
                        int fieldDCDriveMut = (int)commandInfo.parameters[0];

                        //
                        // Set the field of the DC drive
                        //
                        if ((success = this.redLion.SetFieldDCDriveMut(fieldDCDriveMut)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        break;

                    case ExecuteCommands.TakeMeasurement:

                        //
                        // Take a measurement
                        //
                        RedLion.Measurements measurement = new RedLion.Measurements();
                        if ((success = this.redLion.TakeMeasurement(ref measurement)) == false)
                        {
                            errorMessage = this.redLion.GetLastError();
                        }
                        else
                        {
                            //
                            // Add the measurement values to results
                            //
                            commandInfo.results = new object[] {
                                measurement.speed,
                                measurement.voltage,
                                measurement.fieldCurrent,
                                measurement.load
                            };
                        }
                        break;

                    default:

                        //
                        // Unknown command
                        //
                        errorMessage = STRERR_UnknownCommand + executeCommand.ToString();
                        success = false;
                        break;
                }
            }
            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(this.logLevel, STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return executeCommandInfo;
        }