09-23-2010 06:47 AM
Hi, CVI veterans,
I succeed reading back firmware and EEPROM from a uc with a bat of below code.
int status;
char fw_pro_cmd[300]="D:\\data\\read_uc.bat";
SetWaitCursor(1);
status=LaunchExecutableEx(fw_pro_cmd,LE_HIDE,&cmd_handle);
Delay(8); // 8 second is to make sure the cmd is executed surely.
RetireExecutableHandle(cmd_handle);
SetWaitCursor(0);
The content of read_uc.bat is
cd d:\Data\
pk2cmd.exe /PPIC18F2320 /GFD:\1.hex >>d:\1.txt
===============================
/GFD:\1.hex means to save the content to D:\1.hex.
I’d like to the hex destination is changeable easier in my next version, instead of fixing it in the bat file. e.g., user can set hex name or full path from user interface.
One approach is to modify the bat file with CVI before using LaunchExecutableEx() , but I don’t prefer it.
Is there a beeter way? Please advise.
Thanks.
Solved! Go to Solution.
09-23-2010 07:27 AM
Hi,
You can easily put your batch file functionality into an executable program.
Then you can easily input arguments into your exe.
They appear in the argv input to your main function.
Hope this helps,
09-23-2010 08:18 AM
You could try passing parameters to the batch file. So your C code would change:
char fw_pro_cmd[300]="D:\\data\\read_uc.bat D:\\1.hex D:\\1.txt";
and so would your batch file:
pk2cmd.exe /PPIC18F2320 /GF%1 >>%2
Obviously you would want to create the string to be sent programatically, but I'm sure you get the general idea.
JR
09-23-2010 06:33 PM
Hi, jr_2005,
The hex path must be pre-defined in the bat file, so it seems that I have to update the bat file if user wants to save the hex to a different path. As I posted previously, I wonder if there are other ways to handle my issue, instead of updating bat file?
==============
/GFD:\1.hex
/G is command, D:\1.hex is path.
thanks.
09-24-2010 03:44 AM
@labc wrote:
The hex path must be pre-defined in the bat file
Did you try my suggestion? The "%1" and "%2" text strings in the batch file will be replaced by corresponding strings present in the command line, before it is processed by the operating system - this is all pretty standard batch file parameter passing stuff. Try it and see.
Is there any other reason that you think this approach would not be suitable? For example, are the files locked down by some audit requirements and so must not be altered?
JR
09-26-2010 02:40 AM - edited 09-26-2010 02:41 AM
Hi, jr_2005,
Thanks for your suggestion, and I didn't try for I have no idea about how to apply cmd parameters %1 %2.
I googled a link and realize your advice are pretty good.
Could you please share me some links to study the parameters? Some examples are appreciated.
09-28-2010 06:45 AM
Hi, who can help me?
Thanks.
09-28-2010 07:32 AM
Hi labc, a simple google search returned this page which I consider exhaustive on DOS batch files.
There is nothing different on their usage in CVI: you must simply accomodate in a proper way the string to pass to LaunchExecutable.
09-28-2010 06:15 PM
Hi, Roberto,
Great! Thank you.
09-29-2010 09:39 AM - edited 09-29-2010 09:46 AM