Destroy

Closes the link to the KINGSTAR Subsystem and terminates the Subsystem.

Syntax

KsError Destroy();

Return value

If the function succeeds, it returns errNoError, otherwise an error code. For more information about the error code, see the KsError list.

Remarks

Destroy closes the application’s link to the KINGSTAR Subsystem and if no process are connected, the Subsystem is stopped. This must be the last KINGSTAR function in an application.

Example

BOOL StartKingstar() {
   //Launch or connect to the KINGSTAR Subsystem process
   KsError nRet = errNoError;
   nRet = Create(INSTANCE, 0);

   SubsystemStatus Subsystem = { ecatOffline, ecatOffline, 0, 0, 0, 
	{ecatOffline}, {ecatOffline}, {axisOffline} };
   GetStatus(&Subsystem, NULL);
   if (Subsystem.State == ecatOP) {
      RtPrintf("Subsystem already started: %x\n", nRet);
      return TRUE;
   }
   else if (Subsystem.State != ecatOffline) {
      RtPrintf("Subsystem in unexpected state: %d\n", Subsystem.State);
      return FALSE;
   }

   //Configure the Subsystem settings
   nRet = SetCycleTime(cycle500);
   nRet = SetAxisAccessMode(accessPos);
   nRet = EnableServerLog(FALSE);
   nRet = EnableAxisInput(TRUE);
   nRet = EnableAxisOutput(FALSE);
   nRet = EnableSecondEncoder(FALSE);
   nRet = EnableActualVelocity(TRUE);
   nRet = EnableActualTorque(TRUE);
   nRet = EnableActualCurrent(TRUE);
   nRet = EnableFollowingError(TRUE);
   nRet = EnableMaxTorque(TRUE);
   nRet = EnableMaxCurrent(TRUE);
   nRet = EnableTorqueOffset(FALSE);
   nRet = EnableProfilePosition(FALSE);
   nRet = EnableSynchronizedControlMode(TRUE);
   nRet = EnableAutoRestart(TRUE);
   nRet = EnableAutoRepair(TRUE);
   nRet = EnableAutoConfig(TRUE);
   nRet = ConfigureDc(TRUE, TRUE, FALSE, 0);
   nRet = EnableHotConnect(TRUE);
   nRet = EnableRedundancy(TRUE);
   nRet = SetConfiguredAxesCount(1);
   nRet = SetConfiguredIoCount(3);
   SlaveStatus simulatedIo = { 0 };
   simulatedIo.InputLength = 16;
   simulatedIo.OutputLength = 16;
   for (int i = 0; i < IO_COUNT; i++) {
      nRet = ConfigureIo(i, simulatedIo);
   }

   SlaveStatus axisDefinition = { "Simulated Axis", 0 };
   ConfigureAxis(0, axisDefinition, 131072);

   //Start the EtherCAT network
   //This function is asynchronous so the network is not started yet when it returns
   KsCommandStatus status = WaitForCommand(30, TRUE, Start());

   return TRUE;
}

BOOL StopKingstar() {
   BOOL Success = TRUE;

   //Stop the EtherCAT network
   KsCommandStatus status = WaitForCommand(5, FALSE, Stop());
   if (status.Error) {
      RtPrintf("Stop Failed: %d\n", status.ErrorId);
      Success = FALSE;
   }

   //Terminates the KINGSTAR Subsystem process
   KsError nRet = Destroy();
   if (nRet != errNoError) {
      RtPrintf("DisposeLink Failed: %x\n", nRet);
      Success = FALSE;
   }
   return Success;
}

Requirements

  RT Win32
Minimum supported version 4.0 4.0
Header ksapi.h ksapi.h
Library KsApi_Rtss.lib KsApi.lib

See also

Create

Start

Stop