Thanks Ross, Brendan, Jon. 

I need to get the PICKit2 back from the client to test out the full code
but it does appear to return no programmer found correctly.

For anyone else that ever googles on this subject.  Here are the code
fragments.
First inside ExecCmdLineAndWait :

  Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,
    CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, 
    nil,
    nil,
    SUInfo, 
    ProcInfo);

  { Wait for it to finish. }
  if Result then begin
    WaitForSingleObject(ProcInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcInfo.hProcess,ExitCode);
    CloseHandle(ProcessInfo.hProcess);  { (From Brendon Blake)Must remove
handles to prevent.. }
    CloseHandle(ProcessInfo.hThread);   {   ...memory creep
}
end;


And then in the calling function:

    bRes := ExecCmdLineAndWait('pk2cmd.exe /PPIC18F2680 /HK /Ftemp.hex /M
/A5.00 ', SW_SHOWNORMAL, EResult);

    if EResult = 0 then begin
            AssignFile(LogFile,'C:\Firmware\LogFile.csv');
            {$I-}
            Append(LogFile);
            {$I+}
            if IOResult <> 0 then
          ReWrite(LogFile);     // File not there?  Then create it.
            EEText := DateTimeToStr(Now);   // Get date and time
            writeln(LogFile, EEText, ',',
NodeIDEdit.text,',',EBESerialEdit.text);
            Flush(LogFile);                // Make sure it's written out.
            CloseFile(LogFile);            // Done.
    end
    else begin
        case EResult of
        OPSUCCESS :     ErrorMsg := 'Success';
                VOLTAGE_ERROR : ErrorMsg := 'VOLTAGE ERROR';
                OPFAILURE : ErrorMsg := 'OP FAILURE';
                NO_PROGRAMMER : ErrorMsg := 'NO PROGRAMMER';
                WRONG_OS : ErrorMsg := 'WRONG OS';
                FILE_OPEN_ERROR : ErrorMsg := 'FILE OPEN ERROR';
                DEVICEFILE_ERROR : ErrorMsg := 'DEVICE FILE ERROR';
                UPDGRADE_ERROR : ErrorMsg := 'UPGRADE ERROR';
                PGMVFY_ERROR : ErrorMsg := 'PROGRAM VERIFY ERROR';
                INVALID_CMDLINE_ARG     : ErrorMsg := 'INVALID CMDLINE
ARG';
                INVALID_HEXFILE : ErrorMsg := 'INVALID HEX FILE';
                AUTODETECT_FAILED : ErrorMsg := 'AUTODETECT FAILED';
        else
                ErrorMsg := 'UNKNOWN ERROR';
        end;
        MessageDlg('PICKit2 Programmer : '+ ErrorMsg, mtInformation,
[mbOk], 0);
    end;

Thanks again,

John

Automation Artisans Inc.
http://www.autoartisans.com/ELS/
Ph. 1 250 544 4950


> -----Original Message-----
> From: delphi-boun...@elists.org 
> [mailto:delphi-boun...@elists.org] On Behalf Of Ross Levis
> Sent: Friday, October 09, 2009 4:07 AM
> To: 'Borland's Delphi Discussion List'
> Subject: RE: Captures information from a ShellExecute
> 
> 
> It is the ExitCode you need to test for.
> 
> GetExitCodeProcess(ProcessInfo.hProcess,ExitCode);
> 
> You can test ExitCode = Still_Active if you wish to wait in a 
> loop until the
> process finishes.
> 
> Ross.
> 
> -----Original Message-----
> From: delphi-boun...@elists.org 
> [mailto:delphi-boun...@elists.org] On Behalf
> Of John Dammeyer
> Sent: Friday, 9 October 2009 8:58 p.m.
> To: 'Borland's Delphi Discussion List'
> Subject: Captures information from a ShellExecute
> 
> Hi,
> 
> I'm launching a windows command line PIC programmer as follows:
> 
>     res := ShellExecute(Self.Handle, nil, 'pk2cmd.exe', '/PPIC18F2680
> /FTricolourNode.hex /M /A5.00',
>     'C:\Firmware', SW_SHOWNORMAL);
> 
> The shell executes and returns immediately as it probably should.  The
> Command Line window stays open until the pktcmd.exe finishes. 
>  Once the
> pk2cmd.exe finishes it closes the window immediately.  If 
> it's failed to
> program th PIC microntroller I don't see the information 
> before the window
> closes.
> 
> If I use CreateProcess I can then hang around until the app 
> is done but
> then it's the same issue.  The Command Window closes when the 
> app closes
> and I can't seem to catch an error code from the pk2cmd.exe 
> as outlined
> below:
> 
> 11. Return Codes
> --------------------------------------------------------------
> ------------
> --
> Value   Code                    Notes
> -----   ----                    -----
> 0       OPSUCCESS             Returned if all selected operations
> complete
>                                 successfully.
> 5       VOLTAGE_ERROR           A Vdd and/or Vpp voltage error was
> detected.
>                                 This could be due to PICkit 2 being
>                                 improperly connected to a 
> part, incorrect
>                                 part selection, or 
> interference from other
>                                 circuitry on the target board.
> ...
> 
> 39      AUTODETECT_FAILED       A part autodetect operation 
> failed to find
>                                 a known part.
> 
> Is there a way to lauch a window and capture the return code of the
> application as opposed to the success or failure of launching 
> the command
> line window?
> 
> GetLastError just returns 0.
> 
> I've tried >>results.txt with no luck to try and catch the 
> text output.
> 
> Googling on this subject seems to always refer to the Windows 
> Error Code
> which GetLastError would return.
> 
> Thanks
> 
> John
> 
> 
> Automation Artisans Inc.
> http://www.autoartisans.com/ELS/
> Ph. 1 250 544 4950
> 
> 
> _______________________________________________
> Delphi mailing list -> Delphi@elists.org
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
> 
> 
> _______________________________________________
> Delphi mailing list -> Delphi@elists.org
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
> 
> 

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to