Automating BLF to MAT File Conversion in Vector CANalyzer - file-conversion

I'm trying to automate my conversion of a bunch of BLF files into Matlab MAT files. I found a similar question on here and used the answer to get started:
Is there a way to automate BLF to CSV conversion in Vector CANoe?
I would just comment on that thread, but my account here is new so I can't.
I followed the instructions in the other thread to set it up for CANalyzer and BLF/MAT files. When I run the BAT file I get an error in the Write window of CANalyzer that says:
System Logging file 'logfile001.blf' could not be imported
So the issue seems to be that the BLF isn't getting imported into CANalyzer properly. Has anyone tried this before or have any suggestions on what to try? I've never really used VBS so I'm having a hard time troubleshooting the code.
Here's my code as I have it written.
For the BAT file:
for /F %%x in ('cd') do for %%i in (*.blf) do c:\windows\system32\wscript.exe canalyzer_convert.vbs %%i %%x
For the VBS script:
'-----------------------------------------------------------------------------
' converts the filenames which are passed via startup parameter to MAT files with the help of CANalyzer
'-----------------------------------------------------------------------------
Dim src_file, dst_file, pos
Set App = CreateObject("CANalyzer.Application")
Set Measurement = App.Measurement
Set args = WScript.Arguments
' read first command line parameter
arg0=args.Item(0)
arg1=args.Item(1)
If Measurement.Running Then
Measurement.Stop
End If
Wscript.Sleep 500
'---------------------------------------------------------------------------
' you have to create an empty CANalyzer configuration and specify the path and file name below
'-----------------------------------------------------------------------------
App.Open("c:\CANalyzer\empty_config.cfg")
'-----------------------------------------------------------------------------
' create destination file name and append .mat -- you could change this to different file format that is supported by CANalyzer
' next line has to be cut down to src_file="" & arg0 or src_file=arg0 to avoid adding folder name to file name, but this script still crashes
src_file=arg0
dst_file=src_file & ".mat"
Set Logging = App.Configuration.OnlineSetup.LoggingCollection(1)
Set Exporter = Logging.Exporter
With Exporter.Sources
.Clear
.Add(src_file)
End With
' Load file
Exporter.Load
With Exporter.Destinations
.Clear
.Add(dst_file)
End With
Exporter.Save True
App.Quit
Set Exporter = Nothing
Set Logging = Nothing
Set App = Nothing
Set args = Nothing
Set Measurement = Nothing
If you compare mine to the answer from the other thread, you'll see I had to remove the arg1 info from this line
src_file=arg1 & "" & arg0
If I don't remove arg1 from there, then CANalyzer tries to import a BLF file that also includes the folder name in the file name and crashes the script. I think it may be causing problems with
Set Logging = App.Configuration.OnlineSetup.LoggingCollection(1)
because that line appears to reference
arg1=args.Item(1)
Any help would be appreciated.

Related

Waiting on another python process to continue

Python version: Python 2.7.13
I am trying to write a script that is able to go through a *.txt file and launch a batch file to execute a particular test.
The code below goes through the input file, changes the string from 'N' to 'Y' which allows the particular test to be executed. I am in the process of creating a for loop to go through all the lines within the *.txt file and execute all the test in a sequence. However, my problem is that I do not want to execute the test at the same time (which is what would happen if I just write the test code).
Is there a way to wait until the initial test is finished to launch the next one?
Here is what I have so far:
from subprocess import Popen
import os, glob
path = r'C:/Users/user1/Desktop/MAT'
for fname in os.listdir(path):
if fname.startswith("fort"):
os.remove(os.path.join(path, fname))
with open('RUN_STUDY_CHECKLIST.txt', 'r') as file:
data = file.readlines()
ln = 4
ch = list(data[ln])
ch[48] = 'Y'
data[ln] = "".join(ch)
with open('RUN_STUDY_CHECKLIST.txt', 'w') as file:
file.writelines(data)
matexe = Popen('run.bat', cwd=r"C:/Users/user1/Desktop/MAT")
stdout, stderr = matexe.communicate()
In this particular instance I am changing the 'N' in line 2 of the *.txt file to a 'Y' which will be used as an input for another python script.
I have to mention that I would like to do this task without having to interact with any prompt, I would like to do execute the script and leave it running (since it would take a long time to go through all the tests).
Best regards,
Jorge
After further looking through several websites I managed to get a solution to my question.
I used:
exe1 = subprocess.Popen(['python', 'script.py'])
exe1.wait()
I wanted to post the answer just in case this is helpful to anyone.

Trying to start an exe or bat file on a remote machine, via a cmd shell

Running the following from a command line to launch a process on remote computer
wmic /node:remotemachine /user:localadmin process call create "cmd.exe /c C:\temp\myfolder\test.bat"
basically it's just
echo Some Text > output.txt
I tested by double clicking the batch file and it creates the output.txt file.
the batch file just echoes to a file. I did this to see if it actually runs.
The cmd process starts. I can see it in the processes, but the batch file never creates the text file.
I started off trying to run an EXE from my C# application, but it will create the process for the executable, but the actions the executable takes, never occurs.
So I started testing other ways to do the same thing, and I am encountering the same issue. it creates the process, but doesn't actually run the bat or exe.
Any help would be appreciated.
I need to be more specific
I'm using the following code within my C# application:
public static void ConnectToRemoteClient(string client_machine, string target_exe )
{
var connection = new ConnectionOptions();
object[] theProcessToRun = { target_exe };
var wmiScope = new ManagementScope($#"\\{client_machine}\root\cimv2", connection);
wmiScope.Connect();
using (var managementClass = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions()))
{
managementClass.InvokeMethod("Create", theProcessToRun );
}
}
It's called as follows:
It is called using the following syntax:
string exe = string.Format(#"cmd.exe /c C:\temp\Myfolder\test.bat");
ConnectToRemoteClient("ClientMachine", exe);
It will launch the process and I see the cmd.exe running, but the test.bat actions never occur.
Telling WMIC to run a single command is pretty straight forward. Trouble shows up once we try to nest one command inside another. :-)
Since this case has an outer command (cmd.exe) and an inner command (C:\temp\Myfolder\test.bat), the trick is separating them in a way that WMIC can use. There are 3 techniques that'll work, but the one which has the fewest issues with special characters is the single-to-double-wrap method. Effectively you use single quotes around the outer command, and double quotes around the inner command. For example:
wmic /node:NameOfRemoteSystem process call create 'cmd.exe /c "whoami /all >c:\temp\z.txt"'
Wrapping in this way will preserve the redirector (>) and it also doesn't require you to double your backslashes on the inner command.
Output From Example:
dir \\NameOfRemoteSystem\c$\temp\z.txt
File Not Found
wmic /node:NameOfRemoteSystem process call create 'cmd.exe /c "whoami /all >c:\temp\z.txt"'
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ProcessId = 20460;
ReturnValue = 0;
};
dir \\NameOfRemoteSystem\c$\temp\z.txt
03/27/2019 04:40 PM 17,977 z.txt
Please use below mentioned powershell command
Invoke-Command -ComputerName <remoteMachine> -Credential $cred -ScriptBlock {<location of batch file>}

Qt - pdftocairo pdf conversion process not working when application on auto start

I am running my Qt (4.8, QWS server, QWidget app) application on an ARM/embedded linux platform. On my application, I have a module/widget to view PDF files.
Being a slower processor, it was better to go for a conversion of the PDF file to image files using pdftocairo. The module also has a feature to import any pdf file from a flash drive and convert it to images using pdftocairo. The entire module works as expected when I manually start the application from command line. Here is the code that imports the pdf file into the device in the form of images:
QString CacheName = PDFList->currentItem()->text(); //name of PDF file without ".pdf"
QString PDFString = "pdftocairo -jpeg -r 200 \"/media/usb/" + CacheName + ".pdf\" \"/opt/.pdf/" + CacheName + "\"";
qDebug() << PDFString;
QProcess PDFCacheprocess;
PDFCacheprocess.startDetached(PDFString); //or PDFCacheprocess.start(PDFString)
The ultimate goal of the project is to have the application to auto-start when the device boots up. However, when starting the application automatically, the import feature doesn't seem to do anything. I am stumped with not being able to identify the problem because I do not have any debug output (which I do have when executing the app normally).
I normally execute the application manually with
/opt/[path]/[application name] -qws
When auto-starting, I put the application out into a file, log.txt by adding &>/opt/log.txt. The output seems to be the same as when I am running with the manual command. This is the content of the file during the import process (no error being reported).
"pdftocairo -jpeg -r 200 "/media/usb/manual.pdf" "/opt/.pdf/manual"
Strangely enough, every other command (other than pdftocairo) is working. I tried to replace this command with QString PDFString = "/opt/./importPDF.sh". The script was being executed for any command (like reboot), but again, it would fail if it contained the pdftocairo command.
I also tried to add a slot connected to QProcess::finished(int) to show the QProcess output:
connect(&PDFCacheprocess, SIGNAL(finished(int)), this, SLOT(pdfImportStatus(int)));
void UserManual::pdfImportStatus(int)
{
qDebug()<<PDFCacheprocess.errorString()<<'\t'<<PDFCacheprocess.exitCode();
}
For the manual execution ( when import works), I would get:
"pdftocairo -jpeg -r 200 "/media/usb/manual.pdf" "/opt/.pdf/manual""
"Unknown error" 0
For the auto-start, log.txt only shows this (seems like the slot isn't being triggered?)
"pdftocairo -jpeg -r 200 "/media/usb/manual.pdf" "/opt/.pdf/manual""
Any help is appreciated. Thanks in advance :)
Apparently the problem was that the command was not being recognized in the working directory (only when auto-starting for some reason). When using a Qprocess, it turns out that it is always good to give the path even if the file/command exists in the environment variables - as was in my case ($PATH).
I had to replace the QString with:
QString PDFString = "/usr/local/bin//pdftocairo -jpeg -r 200 \"/media/usb/" + CacheName + ".pdf\" \"/opt/.pdf/" + CacheName + "\"";

Tensorboard: No graph definition files were found.

In my Python code I execute
train_writer = tf.summary.FileWriter(TBOARD_LOGS_DIR)
train_writer.add_graph(sess.graph)
I can see 1.6MB file created in E:\progs\tensorboard_logs (and no other file)
but then when I execute
tensorboard --logdir=E:\progs\tensorboard_logs
it loads, but says: "No graph definition files were found." when I click on Graph.
Additionally, running tensorboard --inspect --logdir=E:\progs\tensorboard_logs
displays
Found event files in:
E:\progs\tensorboard_logs
These tags are in E:\progs\tensorboard_logs:
audio -
histograms -
images -
scalars -
Event statistics for E:\progs\tensorboard_logs:
audio -
graph
first_step 0
last_step 0
max_step 0
min_step 0
num_steps 1
outoforder_steps []
histograms -
images -
scalars -
sessionlog:checkpoint -
sessionlog:start -
sessionlog:stop -
This is TF 1.01 or so, on Windows 10.
I had similar issue. The issue occurred when I specified 'logdir' folder inside single quotes instead of double quotes. Hope this may be helpful to you.
egs: tensorboard --logdir='my_graph' -> Tensorboard didn't detect the graph
tensorboard --logdir="my_graph" -> Tensorboard detected the graph
In Tensorflows dealing with graphs, there are three parts:
1) creating the graph
2) Writing the graph to event file
3) Visualizing the graph in tensorboard
Example: Creating graph in tensorflow
a = tf.constant(5, name="input_a")
b = tf.constant(3, name="input_b")
c = tf.multiply(a,b, name="mul_c")
d = tf.add(a,b, name="add_d")
e = tf.add(c,d, name="add_e")
sess = tf.Session()
sess.run(c) <--check, value should be 15
sess.run(d) <--check, value should be 8
sess.run(e) <--check, value should be 23
Writing graph in event file
writer = tf.summary.FileWriter('./tensorflow_examples', sess.graph)
It is very important to specify a directory(in this case, the directory is tensorflow_examples), where the event file will be written to.
writer = tf.summary.FileWriter('./', sess.graph) didnt work for me, because the shell command => tensorboard --logdir expects a directory name.
After executing this step, verify if event file has been created in specified directory.
Visualizing graph in Tensorboard
Open terminal(bash), under working directory type:
tensorboard --logdir='tensorflow_examples' --host=127.0.0.1
Then open a new browser in http://127.0.0.1:6006/ or http://localhost/6006 and now tensorboard shows the graph successfully.
The problem might be the parameter --logdir. make sure you have type the correct
example:
in the code:
writer = tf.summary.FileWriter('./log/', s.graph)
open powershell
cd to your work directory and type
tensorboard --logdir=log
you can also use --debug to see if there is a problem in finding the log file. if you see:
TensorBoard path_to_run is: {'C:\\Users\\example\\log': None} that means it can not find the file.
You may need to change the powershell directory to your log file. And the logdir need not the single quotation marks.(Double quotation marks or without the quotes will be both OK)

Dumping memory in gdb - how to choose the file name at run time

I'm running a program that does processing on a file.
I want to be able to supply the program with several files, and by attaching to it with gdb, I want to get a memory dump at a certain point in the code for each of the files. I want the dump for each file to go to a file with the same filename as the input file (maybe after formatting it a little, say adding a suffix)
So suppose I have a function called HereIsTheFileName(char* filename), and another function called DumpThisMemoryRegion(void* startAddr, void* endAddr), I want to do something like the following:
To get the file name to an environment variable:
break HereIsTheFileName
commands 1
set $filename = malloc(strlen(filename) + 1)
call memcpy($filename, filename, strlen(filename) + 1)
end
Then to dump the memory to the filename I saved earlier:
break DumpThisMemoryRegion
commands 2
append binary memory "%s.memory"%$filename startAddr endAddr
end
(I would even settle for the filename as it is, without formatting, if that turns out to be the difficult part)
However, I couldn't get gdb to accept anything except an exlicit file name for the append/dump commands. when I ran "append binary memory $filename ..." I got the output in the file "/workdir/$filename".
Is there any way to make gdb choose the file name at runtime?
Thanks!
I don't know how to make append accept a runtime filename, but you can always cheat a bit by writing the whole thing to a file and then sourcing that file, using logging.
By putting this in your ~/.gdbinit
define reallyappend
printf "using gdbtmp.log to dump memory to file %s\n", $arg0
set logging file gdbtmp.log
set logging overwrite on
set logging redirect on
set logging on
printf "append binary memory %s 0x%x 0x%x", $arg0, $arg1, $arg2
set logging off
set logging redirect off
set logging overwrite off
source gdbtmp.log
end
you can use the function reallyappend instead, for example with
(gdb) set $filename = "somethingruntimegenerated"
(gdb) reallyappend $filename startAddr endAddr
I don't know if logging works ok in an "commands" environment, but you can give it a shot at least.
Yeah, you can't use a variable here for the filename argument.
The best suggestion I can offer is to write a script that will
set all the breakpoints and set up the "append" commands, and
use text editing or awk and sed to set up the filenames in the
script.