‎03-25-2009 03:44 PM
I am sending and monitoring messages through the COM port.
I am taking the data that I am receiving and storing into an array (hex format)
I would like to Write the time(hh:mm:ss) and the results from the buffer into a file (xls).
For example column A would be Time and B to whenever holds the bytes received from the COM port.
Each message that I receive I want to write the time and the data, and then moved to row 2 and etc.
I am using the sprintf to format the time and the writeline to output it to the file - that works
I am using the arraytofile to ouput the data - that works
The problem that I am having is that it puts all the times first and then after will put the data (all in column A)
Any help would be appreciated.
Thanks,
Solved! Go to Solution.
‎03-26-2009 03:10 AM
If i correctly understand your problem, you could use sprintf to generate a row with time and data separated by tabulator ('\t'), next writeline it to the physical file wich will be automatically separated into columns when loaded in excel:
sprintf (msg, "%s\t%f", TimeStr (), data);
or even simpler
FmtFile (fileHandle, "%s\t%d\n", TimeStr (), data);
‎03-26-2009 07:57 AM
Thanks for your help,
I just want to clarify a little:
Here is an example that I would like to do:
buffer[0] = 0xAB
buffer[1] = 0x11
buffer[2] = 0x33
buffer[3] = 0x17
Please note that the #of bytes stored in the buffer changes based on the message i receive, some messages will be 6 bytes in lenght and others will be like 15 bytes.
Now when i write to the file I would like the following format in excel:
Columns: A B C D E
hh:mm:ss 0xAB 0x11 0x33 0x17
Is there a better way to do this other than:
sprintf (msg,"%s\t%x\t%x\t%x\t%x",TimeStr(),buff[0],buff[1],buff[2],buff[3])
The reason I ask is because the # of data bytes changes.
Any help would be much appreciated!
Thanks
‎03-26-2009 08:39 AM
Well, not the best solution you can find, but:
int count, buf[15];
char msg[256];
buf[0] = 0xAB;
buf[1] = 0x11;
buf[2] = 0x33;
buf[3] = 0x18;
buf[4] = 0x19;
buf[5] = 0x20;
buf[6] = 0x21;
buf[7] = 0x22;
buf[8] = 0x23;
buf[9] = 0x24;
count = 5;
Fmt (msg, "%s\t%*x[j3]\t", TimeStr (), count, buf);
Changing the value of 'count' changes the number of data written to the destination (Fmt can be replaced with FmtFile simply passing a file handle instead of a string): e.g. with count = 5 the output is "14:30:29 ab 11 33 18 19 ".
One problem of this solution is that it adds a separator after the last element has been written to the destination, the other is that you cannot have the '0x' prefix before data.
‎03-26-2009 09:53 AM