Shop OBEX P1 Docs P2 Docs Learn Events
How do you trap the error from Propellent.exe in a batch file? — Parallax Forums

How do you trap the error from Propellent.exe in a batch file?

Don MDon M Posts: 1,652
edited 2013-04-03 12:58 in Propeller 1
I've never written an MSDOS batch file before and was playing around today. For example I am trying to figure out that when a Prop is not connected it will return the error 301 - No Propeller chip found on any serial port. SCAN_STATUS and how to trap it.

I was looking at MSDOS batch file commands from here http://www.eacsystems.com/misc/batch/batchcommands.htm and see this:

IF ERRORLEVEL 2 GOTO END

So I changed it to 301 instead of 2 in the following batch command:

I have 2 quickstart boards connected together and am using the first to load the other using Propeller Loader then loading another image into the first. That part works. Just trying to understand how to trap errors etc.
ECHO OFF
Echo Flashing Stage 1....
Echo Wait for "Press any key to continue" message.
propellent.exe /set /gui dialogs

IF ERRORLEVEL 301 GOTO End
propellent.exe /eeprom Blank_Prop_Loader_V2.binary >Blank_Prop_Loader_V2_Log.txt
Echo Ready to flash stage 2....
pause
Echo Flashing stage 2....
propellent.exe /eeprom blank_bin.binary >blank_bin.txt
Echo Finished.
:END
pause

Comments

  • Heater.Heater. Posts: 21,230
    edited 2013-04-01 13:16
    Don M,
    I've never written an MSDOS batch file before

    Sorry for chuckling, you do realize this is 2013....
  • Don MDon M Posts: 1,652
    edited 2013-04-01 13:21
    I know I know... but I gotta start somewhere right? Is there a better alternative for writing something similar?
  • Heater.Heater. Posts: 21,230
    edited 2013-04-01 23:56
    Don,

    Sorry again for being so flippant. It just tickled me to see a question about MSDOS batch files. I don't think I've seen one since last century.
    As a result I'm not very helpful I'm afraid. These things are much more easily done in Unix shell scripts. I suspect installing cygwin to get that is more effort than its worth though.
  • Mike GMike G Posts: 2,702
    edited 2013-04-02 11:43
    @ECHO OFF
    ECHO ===========================
    ECHO FIND PROPELLER ID
    ECHO ===========================
    Propellent.exe /id /gui OFF > results.txt
    type results.txt
    PAUSE
    
  • Mike GMike G Posts: 2,702
    edited 2013-04-02 12:55
    Here's an example of braching logic
    @ECHO OFF
    ECHO ===========================
    ECHO FIND PROPELLER ID
    ECHO ===========================
    Propellent.exe /id /gui OFF > results.txt 
    
    ::FIND the string 303 in results.txt
    FIND /C /I "303" results.txt >NULL
    IF NOT ERRORLEVEL 1 GOTO HandleError
    
    ECHO Propeller Found!
    GOTO EXIT
    
    :HandleError
    TYPE results.txt 
    
    :EXIT
    PAUSE
    
  • jazzedjazzed Posts: 11,803
    edited 2013-04-02 13:33
    http://www.computerhope.com/batch.htm

    Computer Hope has lots of helpful information on all kinds of scripting and built-in O/S commands.
  • Don MDon M Posts: 1,652
    edited 2013-04-02 15:27
    Thanks everyone for your help and suggestions. Good information here.
  • Jeff MartinJeff Martin Posts: 758
    edited 2013-04-02 16:37
    Hi,

    After reading your initial question, I began to wonder if I told Propellent to actually pass the status code to the application's error code value. Turns out, I didn't. :-( Sorry, somehow I neglected to think of that.

    So I fixed it! (attached). Please let me know if it works for you.

    Also, I think your batch file examples are broken because they don't reference ERRORLEVEL in percent signs: % (but I could be wrong... though I couldn't get it to work without it)

    Here's the batch file code I used to test the new Propellent executable:
    Propellent /ID
    
    IF NOT %ERRORLEVEL%==0 GOTO Error
    
    :NoError
      ECHO No Error
      GOTO Done
    
    :Error
      ECHO Error: %ERRORLEVEL%
    
    :Done
    

    So this way you can use the simple %ERRORLEVEL% method to check the response from Propellent.

    NOTE: Not all values returned are actual errors (as noted in the documentation)... whatever ends up being the last value issued will be the value of %ERRORLEVEL% when Propellent exits. My batch code above doesn't take that into consideration... it treats every non-0 value as an error.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2013-04-02 18:24
    Here is an example using VBScript. Save the file as "id.vbs" in the same directory as propellent.exe.
    To run it, double click it in Windows explorer or create a shortcut to it
    Dim WshShell, oExec, input
    Set WshShell = CreateObject("WScript.Shell")
    Set oExec    = WshShell.Exec("propellent.exe /id /gui OFF")
    input = ""
    Do While Not oExec.StdOut.AtEndOfStream
         input = input & mid(oExec.StdOut.Readline(), 2) & vbcrlf
    Loop
    msgbox input,vbinformation,"Prop ID"
    
  • Don MDon M Posts: 1,652
    edited 2013-04-03 07:50
    Jeff- Thanks so much for updating this. Works great. As I mentioned earlier I have a project that will have 3 Propellers in it and I want a way to sequentially program the 3 through the first Prop using a simple batch program and to be able to abort and report an error. This will work great. Thanks again.

    Ron- I'll have a play with your method and see if I can adapt that as well.
  • Jeff MartinJeff Martin Posts: 758
    edited 2013-04-03 09:21
    Don M wrote: »
    Jeff- Thanks so much for updating this. Works great. As I mentioned earlier I have a project that will have 3 Propellers in it and I want a way to sequentially program the 3 through the first Prop using a simple batch program and to be able to abort and report an error. This will work great. Thanks again.

    Oh good! You're welcome, and thanks for letting me know it works for you.

    [SPECIAL NOTE]: I made that change quite quickly yesterday after finally figuring out how to do it. Today I looked more carefully through the code and made a couple other minor adjustments. None of the other changes should affect you or anyone else, however, I've updated the attachment (three posts above this one) and attached the latest one here as well. Please delete the one you downloaded previous to this and use the one now attached. Thanks!

    Propellent-v1.6.zip
  • Don MDon M Posts: 1,652
    edited 2013-04-03 09:33
    Ok. Thanks.

    Here's my batch file for programming 2 Propellers one connected to another after compiling and configuring using the Propeller Loader object.

    If the flash programming was successful it continues on the next stage and says so otherwise any error number other than 451 will be reported.
    ECHO OFF
    ECHO Quickstart Multi Prop Flash Demo. 
    ECHO Slave board will flash P16 LED. Master board will flash P20 LED.
    ECHO Flashing Slave....
    Propellent /set /gui off
    Propellent /eeprom Don_Prop_Loader_V2_bin.binary >Don_Prop_Loader_V2_bin_Log.txt
    IF NOT %ERRORLEVEL%==0 GOTO Error
    :ERROR
        IF NOT %ERRORLEVEL%==451 GOTO ErrorMessage
    :NOERROR	
    	ECHO Slave Flash Success!
    	ECHO Ready to flash Master....
    	PAUSE
    	ECHO Flashing Master....
    	Propellent /eeprom example3bin.binary >example3.txt
    	IF NOT %ERRORLEVEL%==0 GOTO Error2
    :ERROR2
        IF NOT %ERRORLEVEL%==451 GOTO ErrorMessage
    :NOERROR2	
        ECHO Master Flash Success! Finished.
    	GOTO End
    :ERRORMESSAGE
    	ECHO Error: %ERRORLEVEL%
    	ECHO Report Error number for further assistance.
    	GOTO End	
    :END
    	PAUSE
    
  • Don MDon M Posts: 1,652
    edited 2013-04-03 10:50
    Simplified it a bit...
    ECHO OFF
    ECHO Quickstart Multi Prop Flash Demo. 
    ECHO Slave board will flash P16 LED. Master board will flash P20 LED.
    ECHO Flashing Slave....
    Propellent /set /gui off
    Propellent /eeprom Don_Prop_Loader_V2_bin.binary >Don_Prop_Loader_V2_bin_Log.txt
    IF NOT %ERRORLEVEL%==451 GOTO Error
    :NOERROR	
    	ECHO Slave Flash Success!
    	ECHO Ready to flash Master....
    	PAUSE
    	ECHO Flashing Master....
    	Propellent /eeprom example3bin.binary >example3.txt
    	IF NOT %ERRORLEVEL%==451 GOTO Error
    :NOERROR	
        ECHO Master Flash Success! Finished.
    	GOTO End
    :ERROR
    	ECHO Error: %ERRORLEVEL%
    	ECHO Report Error number for further assistance.
    	GOTO End	
    :END
    	PAUSE
    
  • Don MDon M Posts: 1,652
    edited 2013-04-03 11:13
    Found another neat feature. Rather than write a seperate log file for each Propellent command I found a way to append just 1 text file by using >>.

    So in my example below I open up a text file called Log.txt and write the version of Propellent, the port that the Propeller was found on, any success / error command then on to the next file. Saves from having to look at different text logs.
    ECHO OFF
    ECHO Quickstart Multi Prop Flash Demo. 
    ECHO Slave board will flash P16 LED. Master board will flash P20 LED.
    ECHO Flashing Slave....
    Propellent /set /gui off
    Propellent /version >Log.txt
    Propellent /id >>Log.txt
    Propellent /eeprom Don_Prop_Loader_V2_bin.binary >>Log.txt
    IF NOT %ERRORLEVEL%==451 GOTO Error
    :NOERROR	
    	ECHO Slave Flash Success!
    	ECHO Ready to flash Master....
    	PAUSE
    	ECHO Flashing Master....
    	Propellent /eeprom example3bin.binary >>Log.txt
    	IF NOT %ERRORLEVEL%==451 GOTO Error
    :NOERROR	
        ECHO Master Flash Success! Finished.
    	GOTO End
    :ERROR
    	ECHO Error: %ERRORLEVEL%
    	ECHO Report Error number for further assistance.
    	GOTO End	
    :END
    	PAUSE
    
  • Jeff MartinJeff Martin Posts: 758
    edited 2013-04-03 11:16
    Don M wrote: »
    Found another neat feature.

    Awesome Don! Thanks for sharing that with everybody also, that batch file can be a great starting place for someone doing a similar task.
  • SapiehaSapieha Posts: 2,964
    edited 2013-04-03 11:52
    Hi Jeff Martin

    What place I can find ERRORLEVEL numbers descriptions?

    Awesome Don! Thanks for sharing that with everybody also, that batch file can be a great starting place for someone doing a similar task.
  • Jeff MartinJeff Martin Posts: 758
    edited 2013-04-03 12:11
    Sapieha wrote: »
    Hi Jeff Martin

    What place I can find ERRORLEVEL numbers descriptions?

    Run this command-line "Propellent.exe /Help" and it will display an .rtf file with lots of information. The messages are listed at the bottom of that file.

    Also, it's included with the archive of Propellent as "Propeller Executable.pdf."
  • Don MDon M Posts: 1,652
    edited 2013-04-03 12:13
    Sapieha wrote: »
    Hi Jeff Martin

    What place I can find ERRORLEVEL numbers descriptions?

    They are in the zipped attachment to post #12 above in a pdf file.
  • Don MDon M Posts: 1,652
    edited 2013-04-03 12:58
    I found a pretty cool Bat To Exe Converter on download.cnet.com from f2ko that allows you to compile all the files into an executable so as not to reveal all the included files and your batch file. This will work great for doing updates.

    Just thought I'd pass this along.
Sign In or Register to comment.