Stop the KINGSTAR Subsystem

In Start the KINGSTAR Subsystem, you have learned how to use the functions to configure the KINGSTAR settings and start the KINGSTAR Subsystem. In this section, you'll learn how to stop the KINGSTAR Subsystem.

Functions and structures

In this section, the following functions and structures are used.

When you stop the KINGSTAR Subsystem, you must use these two functions and use them in the correct sequence. If an application is still linked to the Subsystem while it is terminated, a blue screen of death may appear.

To check whether the functions are run successfully, we use the flag Success. If they are, StopKingStar returns TRUE. You can use return TRUE or return FALSE instead of using the flag.

In SystemInitialization.cpp, under the block of StartKingstar, add the following code:

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;

    //Terminate the KINGSTAR Subsystem process.
    KsError nRet = Destroy();
    if (nRet != errNoError)
        RtPrintf("DisposeLink failed: %x\n", nRet);
        Success = FALSE;
    return Success;