This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCSv4: ScriptingEnvironment instance error when calling from Matlab

Other Parts Discussed in Thread: CCSTUDIO

Hi

I am trying to create a Matlab GUI that uses the debug server. The problem I am having is that the GUI works as expected when I run it the first time, but the second time I run it I get an error on

script = ScriptingEnvironment.instance();

There is obviously some java object still defined in Matlab's environment that doesn't get cleared when GUI is ended.

To create a simpler test, I created the function below. It has the same problem. I checked the scripting env API and there does not seems to be a method that can tell me the instance is present (kinda like isWithinCCS() ).

Restarting Matlab works.

Perhaps there is a java command that destroys the singleton  created by ScriptingEnvironment.instance()?

??? Java exception occurred:
java.lang.ClassCastException: com.ti.ccstudio.scripting.environment.DirectedConsoleHandler cannot be cast to
com.ti.ccstudio.scripting.environment.DirectedConsoleHandler

    at
    com.ti.ccstudio.scripting.environment.ScriptingEnvironment.initializeParentLogger(ScriptingEnvironment.java:117)
   
    at com.ti.ccstudio.scripting.environment.ScriptingEnvironment.<init>(ScriptingEnvironment.java:77)

    at com.ti.ccstudio.scripting.environment.ScriptingEnvironment.instance(ScriptingEnvironment.java:60)


Error in ==> startDebugServer at 24
script = ScriptingEnvironment.instance();

************ Function ************************

function startDebugServer()

disp ('SetupCcsDebugServer');

DEBUG_DIR = 'C:/Program Files/Texas Instruments/ccsv4/DebugServer';
%TARGETCFG_DIR = 'C:/Program Files/Texas Instruments/ccsv4/emulation/boards/evmc6472/target_configuration';
%TARGET_EMULATOR = '/EVM6472_XDS100USB.ccxml';

javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/js.jar'  ]);
javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/dss.jar'  ]);
javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/com.ti.debug.engine_1.0.0.jar'  ]);
javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/com.ti.ccstudio.scripting.environment_3.1.0.jar' ]);
javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/com.ti.ccstudio.scripting.rtdx_1.0.0.jar' ]);
javaaddpath([ DEBUG_DIR '/../eclipse/startup.jar' ]);

import com.ti.ccstudio.scripting.environment.*;
import com.ti.debug.engine.scripting.*;
import java.lang.System;
import java.lang.Object;
 
System.setProperty('XPCOM.RUNTIME',[ DEBUG_DIR '/win32' ]);

%global script;
script = ScriptingEnvironment.instance();

display('Done')

 

  • Hi Eddie,

    There is a known issue where the debug server would not shut down correctly from DSS scripts.  Hence you needed to terminate the session with a java.lang.System.exit(0); call. I wonder if you are running into this issue

    ki

  • Hi

    Ki-Soo Lee said:
    There is a known issue where the debug server would not shut down correctly from DSS scripts.  Hence you needed to terminate the session with a java.lang.System.exit(0); call. I wonder if you are running into this issue

    Thats likely the issue. I tried java.lang.System.exit(0), but that also shuts down Matlab.

    There must be a java command that can force a shut down without having to kill Matlab.

    Cheers

    Eddie

  • Hi Eddie,

    I am not sure what the bug was in DSS, however, can the startDebugServer() function check if "script" is null before calling ScriptingEnviornment.instance()?

    Regards,
    Patrick

  • Hi

    I've made some progress with the help from Ed at the Matlab forum

    http://www.mathworks.com/matlabcentral/newsreader/view_thread/298936#804810

    Its strange, but the addpath and System.setProperty have to be commented out for it to work the second time. Now to figure out how to automate it so that I don't have to manually edit the file.

    Cheers

    **************** MATLAB SCRIPT *******************************

    function startDebugServer()

    YES = 1;
    NO = 0;

    FIRST_PASS = YES;        % set this to no the next time you run this.

    disp ('SetupCcsDebugServer');

    DEBUG_DIR = 'C:/Program Files/Texas Instruments/ccsv4/DebugServer';
    %TARGETCFG_DIR = 'C:/Program Files/Texas Instruments/ccsv4/emulation/boards/evmc6472/target_configuration';
    TARGETCFG_DIR = 'C:/Documents and Settings/epatto/user/CCSTargetConfigurations';
    %TARGET_EMULATOR = '/EVM6472_BHUSB560M.ccxml';
    TARGET_EMULATOR = '/evm6472_USB560M.ccxml';
    WORK_DIR = 'D:/vws/ejp_M2_evm6472_pwcw/spDsp/EVM/Test/Test.Doppler/Test.WallFilter';
    %CPU_NAME = 'Spectrum Digital XDS510USB Emulator_0/C6472_0';
    CPU_NAME = 'Blackhawk USB560-M Emulator, 20-pin JTAG Cable_0/C6472_0';

    if FIRST_PASS
    javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/js.jar'  ]);
    javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/dss.jar'  ]);
    javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/com.ti.debug.engine_1.0.0.jar'  ]);
    javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/com.ti.ccstudio.scripting.environment_3.1.0.jar' ]);
    javaaddpath([ DEBUG_DIR '/packages/ti/dss/java/com.ti.ccstudio.scripting.rtdx_1.0.0.jar' ]);
    javaaddpath([ DEBUG_DIR '/../eclipse/startup.jar' ]);
    end

    import com.ti.ccstudio.scripting.environment.*;
    import com.ti.debug.engine.scripting.*;
    import java.lang.System;
    import java.lang.Object;
     
    if FIRST_PASS
    System.setProperty('XPCOM.RUNTIME',[ DEBUG_DIR '/win32' ]);
    end

    %global script;
    script = ScriptingEnvironment.instance();

    uDebugServer = script.getServer('DebugServer.1');

    %uDebugServer.setConfig(targetConfigFile);

    %uDebugServer = script.getServer('DebugServer.1');
    uDebugServer.setConfig([TARGETCFG_DIR TARGET_EMULATOR]);

    % Starts IDE

    %script.getServer('CCSServer.1').openSession('.*');

    % Exclude the text in the quotes to get list of targets (WARNING: the text in quotes has to match what you see in your CCSv4 emulator view)
    uDebugSession = uDebugServer.openSession(CPU_NAME);
    %uDebugServer.openSession('.*');         % do this to see device names.

    uDebugSession.target.connect();

    uDebugSession.memory.loadProgram([ WORK_DIR '/Debug/Test.WallFilter.out']);

    %global debug_Server;
    %debug_Server = uDebugServer;

    display('Done')

  • Hi Patrick

    patch said:
    can the startDebugServer() function check if "script" is null before calling ScriptingEnviornment.instance()?

    I would if I knew how. In Matlab, workspace variables show up in the workspace window. The "script" variable is declared within the function when I do 

    script1 = ScriptingEnvironment.instance();

    And after leaving a Matlab function, any workspace variable declared in the function is supposed to be destroyed unless declared as global. 

    So I'm not sure how to find the variable "script" when its not supposed to be there.

    Cheers

     

  • Does matlab script has global? can 'script' be declare as a global variable?

  • Hi

    Yes, but globals are cleared when your main function exits. The main function is out Matlab GUI, and when you exit, bye bye globals.

    Keep the ideas comin. I'm sure we'll find a solution.

    Cheers

  • Greg from Matlab found the solution. Thanks a bunch Greg!!!!!!!!

     DO NOT USE javaaddpath !!!!!!!!!!!!!!!!!!!


     Type "which classpath.txt" and add the following to the file.

     C:/Program Files/Texas Instruments/ccsv4/DebugServer/../eclipse/startup.jar                                             
     C:/Program Files/Texas Instruments/ccsv4/DebugServer/packages/ti/dss/java/com.ti.ccstudio.scripting.rtdx_1.0.0.jar      
     C:/Program Files/Texas Instruments/ccsv4/DebugServer/packages/ti/dss/java/com.ti.ccstudio.scripting.environment_3.1.0.jar
     C:/Program Files/Texas Instruments/ccsv4/DebugServer/packages/ti/dss/java/com.ti.debug.engine_1.0.0.jar                 
     C:/Program Files/Texas Instruments/ccsv4/DebugServer/packages/ti/dss/java/dss.jar                                       
     C:/Program Files/Texas Instruments/ccsv4/DebugServer/packages/ti/dss/java/js.jar

    http://www.mathworks.com/matlabcentral/newsreader/view_thread/298936#808548

    See http://www.mathworks.com/help/techdoc/ref/javaaddpath.html