fuction _write displays the data in console

If you have a simple question and just want an answer.
Unchyu2
Member++
Posts: 29
Joined: Tue Jun 17, 2014 11:40 am

fuction _write displays the data in console

Post by Unchyu2 »

Hello,

I am trying to write some measured data to a file so I can process them later.
I have used the functions provided in the AN10123: How to write to a file during execution, and I have discovered that the file is correctly created and opened but when I try to write something to it using the _write function, it displays the data to mu console instead of writing it to the file.
I have also used the other approach and I have used the fopen and fwrite functions but the result was the same.

The odd thing is that I have used the exact same code about 3 mounts ago and it worked perfectly.

Any help is apreciated,
Ilie

Code: Select all

void writeFETmeasurement(){

    printstrln("Saving data ...");
    int destinationFile = _open("FET.txt", O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); 
    if (destinationFile == -1){
        printstrln ("Error: _open failed");
        _exit(1);
    }

    char tempChar[50];
    int  tempInt;

    for (int i=0; i<processingSize; i++){
        tempInt = sprintf (tempChar, "%d %lld %lld \n", i, sumSamplesClean[i]/nr_measurements, sumSamplesCompressed[i]/nr_measurements);
        if (_write(destinationFile, tempChar, tempInt)!=tempInt){
            printstrln("Error: _write failed");
            _exit(1);
        }
    }
    if (_close(destinationFile)!=0){
        printstrln("Error: _close failed");
        _exit(1);
    }

    printstrln("Save compleate");
    _exit(1);

}


User avatar
larry
Respected Member
Posts: 275
Joined: Fri Mar 12, 2010 6:03 pm

Post by larry »

What is your xTIMEcomposer version? Is it Windows, Linux or Mac?

The following code works fine for me:

Code: Select all

#include <syscall.h>
#include <print.h>
#include <stdio.h>

int main(void)
{
    printstrln("Saving data ...");
    int destinationFile = _open("FET.txt", O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); 
    if (destinationFile == -1){
        printstrln ("Error: _open failed");
        _exit(1);
    }

    char tempChar[50];
    int  tempInt;

    for (int i=0; i<100; i++){
        tempInt = sprintf (tempChar, "%d\n", i);
        if (_write(destinationFile, tempChar, tempInt)!=tempInt){
            printstrln("Error: _write failed");
            _exit(1);
        }
    }
    if (_close(destinationFile)!=0){
        printstrln("Error: _close failed");
        _exit(1);
    }

    printstrln("Save compleate");
    _exit(1);

    return 0;
}
Unchyu2
Member++
Posts: 29
Joined: Tue Jun 17, 2014 11:40 am

Post by Unchyu2 »

Hello again, and sorry for the long delay, I had to switch my focus to other things.
What is your xTIMEcomposer version? Is it Windows, Linux or Mac?
I have tested the code on xTIMEcomposer Community_14.2.3 (build 15642, Oct-17-2016) on Windows 10 and also on xTIMEcomposer Community_14.1 on Mac and I got the same results: on both cases the "_write" function displayed the result in the console window instead of writing it to the file.

I have traced the problem and I found out that is has something to do with XSCOPE:
if I disable XSCOPE, or more precisely, if I comment the lines:

Code: Select all

void xscope_user_init()
{
    xscope_register(0, 0, "", 0, "");

    xscope_config_io(XSCOPE_IO_BASIC);
}
the code compiles perfectly and the _write function writes the values to the file, but if I leave the xscope_user_init() function as it is, the _write function displays the values in the console.

If my memory dosen't deceive me, I believe that the first time I implemented this code I had a couple of XSCOPE traces working and the "_write" function wrote correctly to the file, but now I cant get them to work together any more.

Any help is appreciated,
Ilie