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.

CCS: Scripting Console - output to a text file

Tool/software: Code Composer Studio

I am using a .js file to automate a simple test.  The test changes based on some configuration data which is pulled in via a pound define based on the test -

i.e.

#if TEST == 1
    #define <parameters>
     .....
#elif TEST == 2
    #define <parameters>
   ......
etc..

I'd like to be able to fprintf to a .h file to define which test before rebuilding the project.  i.e. myRunTest 4 would write to the .h file:

#define TEST 4

I am unable to find a way to print to a file except to print to a log in xml format.   Am I missing a way to do this?

-Lori

  • Lori,

    in your .js file you can use plain Java methods. For example, to perform file I/O operations you can include the package java.io at the top of your .js file

    importPackage(Packages.java.io.*);

    Then create an object of type BufferedReader/BufferedWriter that inherits the methods FileReader/FileWriter to read/write lines to a file. 

    Several examples are avaialble on the internet. Interesting resources are: 

    https://java2novice.com/java-file-io-operations/ 

    https://www.tutorialspoint.com/java/io/index.htm

    Hope this helps,

    Rafael

  • Thank you, Rafael,

    It took me a while to figure out the package include needed to be in the function and not just at the top of the file.  Here is what I ended up with if it helps someone else. 

    var dirSrc = "C:\\ti\\c2000\\C2000Ware_<..........>\\";
    
    function myRunTest(p1)
    {
        /* The > followed by a space is required because the project is under revision 
           control.  The "> " is put on the name of the project in CCS project explorer
           if the "> " is not included, then the build will timeout.  */
        myWriteDefine(p1);   
        buildProject("> project_name");
        <...... > 
    
    }
    
    function myWriteDefine(p1) 
    {  
        importPackage(Packages.java.io);
        var fw = new FileWriter(dirSrc + "define.h");
        var writer = new BufferedWriter(fw);
        writer.write("#define TEST  " + p1);
        writer.newLine();
        writer.close();
    } 

  • Lori,

    Thank you for sharing the full solution. This will certainly be helpful for others. 

    Regards,

    Rafael