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.

Reading a text file in CC Studio

Other Parts Discussed in Thread: TMS320F28335

I want to read a text a file from PSCAD software in Code Composer Studio. How to do this? I have read lots of material. But, I have not been able to do this. Is there any specific way to do this? I am using CCS 3.3 and tms320f28335. Please, answer as early as possible. 

  • I'm not familiar with PSCAD and the format of files they generate, but the method you use depends on what you wish to do with the files. If you want to open, read, write files on the host, you can use C file operations such as fread, fwrite, fopen etc. These are standard C functions that you can find documented in any C books.

    If you wish to read/write to file at a specific point in your code, to update a variable for instance, (connected to a breakpoint) you can do this using probe points in CCSv3. The data files have to be a specific format to support this. More information on this can be found in the CCS Online Help (look for the topics "Probe Points" or "Streaming Data To/From a File").

  • Thanks for your reply.

    I am using fopen to access file but I am getting an error.

    fp = fopen("G:\\DSP28335_paste\\san.txt","r"); // read mode
     
       if( fp == NULL )
       {
          printf("Error while opening the file.\n");
         
       }
     
     
     
       while( ( ch = fgetc(fp) ) != EOF )
          printf("´%c",ch);
     
       fclose(fp);

    Every time I run this program, I get erroneous result on hyperterminal.

    The result is ´%Rm[H.

    Also, I get the warnings.

    warning: creating output section .cio without SECTIONS specification
    warning: creating .sysmem section with default size of 400 (hex) words.

  • You have a printf in your code. Is this being redirected to a serial output to view through hyperterminal or defaulting to printing out in the CCS console view? In general, there are a few considerations when working with C I/O routines such as fread/fwrite etc. in CCS. This wiki page contains several tips/guidelines.

    In your case I would suggest first trying to increase the stack and heap sizes, and also add an allocation for the .cio section in your linker command file.

  • Can code composer read a text file, and if so, how?

    Also can it read a .mid file?

  • Hello AartiG,

    My aim is to take entries from one file, process them and then store them in another file. I am storing it in another file to check whether every thing has worked correctly.

    When I use fscanf() for taking floating point number from a file, it is working but when I try to print it using fprintf() function it is giving me error. I want to read the following entries from file. Whether I should use fscanf() or gets() and after that atof()? But, with second option I am again getting an error while using ftoa().

    My text file looks like this:

         .0000000000000          .0000000000000    
        .10000000000000E-02     .71603386860445E-06
        .20000000000000E-02     .69420467142686E-06
        .30000000000000E-02    -.57832807168558E-05
        .40000000000000E-02    -.20406369295612E-04
        .50000000000000E-02    -.40548526990502E-04
        .60000000000000E-02    -.60976867673720E-04
        .70000000000000E-02    -.75539555946393E-04
        .80000000000000E-02    -.78668981056866E-04
    The first column represents time where as second one represents corresponding voltage value.
    Thanking you,
    Amrut
  • Amrut Deshmukh said:
    When I use fscanf() for taking floating point number from a file, it is working but when I try to print it using fprintf() function it is giving me error.

    What error exactly does it give? I would expect fscanf() and fprintf() to work, but if it give problems. trying other similar functions is certainly an option. I'm not sure what types of errors you are still running into but did you make sure to read and carefully check the points mentioned in this wiki page?

    The other thing I wanted to note is that you are using CCS 3.3 which is very old so there is limited support we can provide. The latest version is CCS 5.3 which is based on Eclipse and is a different environment than CCS 3.3, but is the future direction. I am not sure if there is reason for you to stay with CCS 3.3, but whenever possible, I would recommend updating to CCS 5.3 to avail of the latest fixes and improvements.