コード例 #1
0
        /// <summary>
        /// Used for setting the currently controllable actuator <br/>
        ///As only one actuator can be commanded at any given time (see Controller.ActuatorController.OpenDevice())
        /// this method provides a techinque to give to the user the impression that he can have control of all
        /// of the actuators at the same time. When the user issues a command on the interface, the software registers to which
        /// actuator the command is issued, closes all connections to other actuators using Controller.MainController.CloseAllActuators(),
        /// opens with Controller.ActuatorController.OpenDevice() only the device needed and executes the command. This implies a level
        /// of transparency, the user not needing to know this happens in the background
        /// </summary>
        /// <param name="listIndex">identifies the index of the actuator (Entities.Actuator) in the actuator list, of type int </param>
        public void ChangeContext(int listIndex = 0)
        {
            // Engage thread lock
            Monitor.Enter(_lockerEnum);

            if (isFirstTimeLaunch == true)
            {
                Actuators.List[listIndex].OpenDevice(Actuators.List[listIndex].DeviceName);
                ActuatorInContext = Actuators.List[listIndex];
                isFirstTimeLaunch = false;
                logController.LogActuatorInfo(Enums.ActuatorLog.NewActuatorInContext, ActuatorInContext);
            }
            else

            // Only change the context if the new device is different from the one already opened
            if (Actuators.List[listIndex].DeviceID != ActuatorInContext.DeviceID)
            {
                CloseAllActuators();

                Actuators.List[listIndex].OpenDevice(Actuators.List[listIndex].DeviceName);

                // Set the new actuator in context (which is currently in use by the controller)
                ActuatorInContext = Actuators.List[listIndex];
                logController.LogActuatorInfo(Enums.ActuatorLog.NewActuatorInContext, ActuatorInContext);
            }

            // Disengage thread lock
            Monitor.Exit(_lockerEnum);
        }
 /// <summary>
 /// Closes the device specified by deviceID
 /// </summary>
 /// <param name="deviceID">identifies actuator, of type int</param>
 /// <returns>Result.ok if operation is successful, otherwise either Result.error, Result.value_error, Result.no_device, or Result.not_implemented</returns>
 public Result CloseDevice(ref int deviceID)
 {
     try
     {
         if ((base.Result = API.close_device(ref deviceID)) == Result.ok)
         {
             logController.LogActuatorInfo(Enums.ActuatorLog.CloseDevice, this);
         }
     }
     catch (Exception ex)
     {
         logController.LogActuatorError(Enums.ActuatorLog.CloseDevice, deviceID, ex);
         actuatorErrorHandler.HandlePhysicalErrors(Enums.PhysicalErrorType.APIError, "API error occured. Handling is to be implemented");
     }
     return(base.Result);
 }