VS C++ Variables

Hello.

I'm trying to receive and present some values.
I want to display them in a txt.

I've this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
char InputPacketBuffer[64];
unsigned short DataReceive[32];
unsigned short Data1, Data2, Data;
unsigned Data3;
FILE * pFile;
for (unsigned int i = 0; i < 63; i=i+2)
{
Data1 = InputPacketBuffer[i];
Data2 = InputPacketBuffer[i+1];
Data3 = Data2<<8;
Data = (Data1 | Data3);
DataReceive[i/2]=Data;
label1->Text = Data.ToString();
}
pFile = fopen ("Data.txt","w");
if (pFile!=NULL)
{
fwrite(DataReceive , 2 , sizeof(DataReceive) , pFile );
fclose (pFile);
}


Basically the code has 8bit values in each InputPacketBuffer I want to concatenate them 2 by 2 and then display the 32 16bit values (that are in DataReceive array).

The received values in txt aren't the values I want.
Although label1 the value Data is correct.
Do I need to transform the values in characteres??
How do I do it?

And to present them in a graph plot directly in visual studio? Which library do I use?

Thank you all.
The problem is line 18. This way you write 2 * sizeof(DataReceive) and that's not what you want (do you always have the whole array filled?) -> fwrite(DataReceive , 1, sizeof(DataReceive) , pFile );

The next issue is the byte order if unsigned short. How do you read the stored data?

And to present them in a graph plot directly in visual studio?
What do you mean?
About line 18, as I've seen in fwrite function:
size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );
Parameters
ptr
Pointer to the array of elements to be written.
size
Size in bytes of each element to be written.
count
Number of elements, each one with a size of size bytes.
stream
Pointer to a FILE object that specifies an output stream.

DataReceive is an array of 32 shorts(each short 16bits/2bytes). So I've selected 2 because each element has 2 bytes.

Each element of DataReceive has 16 bits which correspond to the value from a 16bit-ADC.
I want to put this values in ints in a txt.

The second issue, is I want to show the values in a graphic-> the 32 values. One way is to pic up the values from the txt and transport them to other program like matlab. The better solution was showing a graphic directly from vs c++ 2008.

Thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
char OutputPacketBuffer[64];			
OutputPacketBuffer[0] = 0x83;			
char InputPacketBuffer[64];
unsigned short int DataReceive[32];
unsigned short Data1, Data2, Data;
unsigned Data3;
FILE * pFile;
pFile = fopen ("Dados.txt","w");
for (unsigned int i = 0; i < 63; i=i+2)
{
	Data1 = InputPacketBuffer[i];
	Data2 = InputPacketBuffer[i+1];
	Data3 = Data2<<8;
	Data = (Data1 | Data3);
	int Datak=(int)Data;
	DataReceive[i/2]=Datak;
	label1->Text = Datak.ToString();
	fprintf(pFile,"%d\n",Datak);
}
fclose(pFile);


Using the function fprint, I've achieved the Data in the txt. =)
If anyone knows about a library which I could display the values in a graphic in VS C++ I would apreciate.

Thank you.
Topic archived. No new replies allowed.