CANoe trace data in an excel file(.csv or.xlsx) - canoe

How to export CANoe trace data in an excel file(.csv or.xlsx) where we can see the messages and signals' names along with their updated values.
I tried storing the log file in .csv format but couldn't see the message and signal name details and their value. I hope there is someway to store the CANoe trace data in an excel file format which can be readable. Any suggestions? Any answer is highly appreciated.

You can use the Logging/Export Block to save the entire measurement in a file as BLF or ASCII. Afterwards you convert the BLF into other formats like CSV or MAT. This can be found under Tools->Convert (I don't know the correct menu items in english, because I have only the german version of CANoe). If you convert an BLF file, you can select the time and the signals you want.
Another solution is to write an own exporter in CAPL and write directly into a file (I didn't try the code, it's just an idea).
on Start {
glbHandle = OpenFileWrite ("Data.csv", 2);
}
on message * {
int i;
char buffer [64];
write("[%07.3f] %03X,", this.time / 100000.0, this.id);
for (i = 0; i < this.dlc; i++) {
snprintf(buffer, elcount(buffer), "%02X, ", this.byte(i));
filePutString(buffer, elcount(buffer), glbHandle);
}
on StopMeasurement {
fileClose (glbHandle);
}

Related

OCTAVE data import from PCE-VDL data logger device and conversion of decimal coma to decimal point

I have a measurement device PCE-VDL, which gives me measurements in following CSV format below, which I need to import to OCTAVE for further investigation.
Especially I need to import last 3 columns with xyz acceleration data.
The file is in CSV format with delimiter of semicolon ";".
I have tried:
A_1 = importdata ("file.csv", ";", 3);
but have recieved
error: missing_idx(10): out of bound 9
The CSV file looks like this:
#PCE-VDL X - TableView series
#2020.16.11
#Date;Time;Duration [s];t [°C];RH [%];p [mbar];aX [g];aY [g];aZ [g];
2020.28.10;16:16:32:0000;00:000;;;;0,0195;-0,0547;1,0039;
2020.28.10;16:16:32:0052;00:005;;;;0,0898;-0,0273;0,8789;
2020.28.10;16:16:32:0104;00:010;;;;0,0977;-0,0313;0,9336;
2020.28.10;16:16:32:0157;00:015;;;;0,1016;-0,0273;0,9297;
The numbers in last 3 columns have also decimal coma and not decimal point. So there probably should be done also some conversion.
Thank you very much for any help.
Regards
EDIT: 18.11.2020
Thanks for help. I have tried now following:
A_1_str = fileread ("file.csv");
A_1_str_m = strrep (A_1_str, ".", "-");
A_1_str_m = strrep (A_1_str_m, ",", ".");
save "A_1_str_m.csv" A_1_str_m;
A_1 = importdata ("A_1_str_m.csv", ";", 8);
and still receive error: file_content(140): out of bound 139
There is probably some problem with time format in first columns, which I do not want to read. I just need last three columns.
After my conversion, the file looks like this:
# Created by Octave 5.1.0, Wed Nov 18 21:40:52 2020 CET <zdenek#ASUS-F5V>
# name: A_1_str_m
# type: sq_string
# elements: 1
# length: 7849
#PCE-VDL X - TableView series
#2020-16-11
#Date;Time;Duration [s];t [°C];RH [%];p [mbar];aX [g];aY [g];aZ [g];
2020-28-10;16:16:32:0000;00:000;;;;0.0195;-0.0547;1.0039;
2020-28-10;16:16:32:0052;00:005;;;;0.0898;-0.0273;0.8789;
2020-28-10;16:16:32:0104;00:010;;;;0.0977;-0.0313;0.9336;
Thanks for support!
You can first read the data with fileread, which stores the data as a string. Then you can manipulate the string like this:
new_string = strrep(string, ",", ".");
strrep replaces all occurrences of a pattern within a string. Afterwards you save this data as a separate file or you overwrite the existing file with the manipulated data. When this is done you proceed as you have tried before.
EDIT: 19.11.2020
To avoid the additional heading lines in the new file, you can save it like this:
fid = fopen("A_1_str_m.csv", "w");
fputs(fid, A_1_str_m);
fclose(fid);
fputs will just write the string to the file.
The you can read the new file with dlmread.
A1_buf = dlmread("A_1_str_m.csv", ";");
A1_buf = real(A1); # get the real value of the complex number
A1_buf(1:3, :) = []; # remove the headlines
A1 = A1_buf(:, end-3:end-1); # get only the the 3 columns you're looking for
This will give you the three columns your looking for. But the date and time data will be ignored.
EDIT 20.11.2020
Replaced abs with real, so the sign of the value will be kept.
Use csv2cell from the io package.

Read data to matlab with for loop

I want to read the data of a file with size about 60 MB into matlab in some variables, but I get errors. This is my code:
clear all ;
clc ;
% Reading Input File
Dataz = importdata('leak0.lis');
%Dataz = load('leak0.lis');
for k = 1:1370
foundPosition = 1 ;
for i=1:size(Dataz,1)
strp = sprintf('I%dz=',k);
fprintf(strp);
findValue = strfind(Dataz{i}, strp) ;
if ~isempty(findValue)
eval_param = strp + '(foundPosition) = sscanf(Dataz{i},''%*c%*c%*f%*c%*c%f'') ;';
disp(eval_param);
% str(foundPosition) = sscanf(Dataz{i},'%*c%*c%*f%*c%*c%f') ;
eval(eval_param);
foundPosition = foundPosition + 1 ;
end
end
end
When I debugged it, I found out that the dataz is empty & so it doesn't proceed to next lines. I replace it with fopen, load & etc, but it didn't work.
From the Matlab help files, import data is likely failing because it doesn't understand your file format.
From the help files
Name and extension of the file to import, specified as a string. If importdata recognizes the file extension, it calls the MATLAB helper function designed to import the associated file format (such as load for MAT-files or xlsread for spreadsheets). Otherwise, importdata interprets the file as a delimited ASCII file.
For ASCII files and spreadsheets, importdata expects to find numeric
data in a rectangular form (that is, like a matrix). Text headers can
appear above or to the left of the numeric data, as follows:
Assuming that your .lis files actually have delimited text.
You should adjust the delimiter in the importdata call so that Matlab can understand your file.
filename = 'myfile01.txt';
delimiterIn = ' ';
headerlinesIn = 1;
A = importdata(filename,delimiterIn,headerlinesIn);

Weird looking symbols in dat file?

Learning to program in C. Used a textbook to learn about writing data randomly to a random access file. It seems like the textbook code works ok. However the output in the Notepad file is: Jones Errol Ÿru ”#e©A Jones Raphael Ÿru €€“Ü´A. This can't be correct yeah? Do you know why the numbers don't show?
I have no idea how to format code properly. Always someone tells me it is bad. I use CTRL +K. And in my compiler follow the book exactly. I'm sorry if it isn't correct. Maybe you can tell me how? Thanks
Here is the code:
#include <stdio.h>
//clientData structure definition
struct clientData{
int acctNum;
char lastName[15];
char firstName[10];
double balance;
};
int main (void){
FILE *cfPtr;//credit.dat file pointer
//create clientData with default information
struct clientData client={0,"","",0.0};
if ((cfPtr=fopen("c:\\Users\\raphaeljones\\Desktop\\clients4.dat","rb+"))==NULL){
printf("The file could not be opened\n");
}
else {
//require user to specify account number
printf("Enter account number"
"(1 to 100, 0 to end input)\n");
scanf("%d",&client.acctNum);
// users enters information which is copied into file
while (client.acctNum!=0) {
//user enters lastname,firstname and balance
printf("Enter lastname,firstname, balance\n");
//set record lastName,firstname and balance value
fscanf(stdin,"%s%s%lf", client.lastName,
client.firstName, &client.balance);
//seek position in file to user specified record
fseek(cfPtr,
(client.acctNum-1)* sizeof (struct clientData),
SEEK_SET);
//write user specified information in file
fwrite(&client,sizeof(struct clientData),1,cfPtr);
//enable user to input another account number
printf("Enter account number\n");
scanf("%d",&client.acctNum);
}
fclose(cfPtr);
return 0;
}
You have created a structure clientData which contains an integer, two strings and a double. You open the file in binary mode and you use fwrite() to write the structure to it.
This means you are writing the integer and the double in binary, and not as character strings, so what you see is logically correct, and you could read the file back into a structure with fread() and then print it out.
If you want to create a text file, you should use fprintf(). You can specify the field widths for integer and double values, so you can create a fixed-length record (which is essential for random access).

How to use the current date as name for a CSV file

How do I create a csv file with date as the name of the csv file. I tried doing it, but the date won't appear only the name does. The language is Scilab which is similar to Matlab.
I do not understand your question fully. But following the csvWrite documentation and the date documentation. You could do someting like this
filename_with_date_string = date() + ".csv";
directory_path = TMPDIR;
// Some matrix you want to save
M = [1:10] * 0.1;
// Create the file
file = fullfile(directory_path, filename_with_date_string);
// Fill it with your matrix
csvWrite(M, file);

Naming a file in matlab

I currently have this:
[filename, pathname, filterindex] = uiputfile({...
... (various filetypes)
'Disks image.jpg');
if isequal(filename,0) || isequal(pathname,0)
disp('User selected Cancel');
else
disp(['User selected ',fullfile(pathname,filename)]);
end
imwrite(M, 'Disks image.jpg', 'jpg');
disp('Image saved');
end
How would I write for the part currently saying 'Disks image.jpg' a name that is either the current time (given by the following):
dateTime = javaMethod('currentTimeMillis', 'java.lang.System');
Or a name that is a combination of both that and some other specified name (e.g. currentTimeMillis_Diffraction_pattern.jpg)
As I am saving two image files, it would be good if I can name the file by the second method, as it gives an ordered list without having to separate the two images into different file folders.
Using time...........+..........._Diffraction_pattern.extension would be great
Thanks
Not sure why you are using a Java function to get the time, rather than built in Matlab time function. I would just use
dateTimeString = datestr(now, 'yyyy-mm-dd-HH_MM_SS_FFF');
Then concatenate that with whatever name you want to create a file name:
myFileName = [dateTimeString '_withSomeName.jpg'];
imwrite( M, myFileName, 'jpg' );
Note - I think that if you include the .jpg extension on the file, it will automatically be converted by imwrite so you don't need the third argument. Also note that using the FFF format specifier will give you the time down to ms - so it's got the same functionality (and granularity) as your original Java function call, but results in more sensible file names.
If you insist on using the Java function, you need to convert it to Matlab's internal clock - this means something like this (untested):
timeNow = javaMethod('currentTimeMillis', 'java.lang.System');
timeMatlab = timeNow / (1000 * 3600 * 24) + datenum('1 Jan 1970');
dateTimeString = datestr(timeMatlab, 'yyyy-mm-dd-HH_MM_SS');
but why would you do that...
String concatenation can be done like this:
filename=[num2str(dateTime) '_Diffraction_pattern.extension'];
Or using sprintf:
filename=sprintf('%d_Diffraction_pattern.extension',dateTime);