return codes of a shell command

Discussion in 'Questions (Windows Mobile)' started by pmu5757, Jun 13, 2008.

  1. pmu5757

    pmu5757 Member Licensed User

    Hello everybody
    On the desktop, with the "shell" command, I can execute a dos command.
    How can I do to set a B4PPC variable with the return code of this dos command ?

    Thank you.

    Pascal.
     
  2. Cableguy

    Cableguy Expert Licensed User

    Not sure WE understand what you mean..
    can you give an example of what you want to do and expect from it?
     
  3. pmu5757

    pmu5757 Member Licensed User

    Here are the details you ask :
    I would like to use B4PPC to command a lego robotic brick, the "Mindstorms RCX 2.0".
    I've found on the web, a program called "nqc" that can send commands to the lego brick by typing dos commands.
    For exemple the command "c:\nqc.exe -Susb -raw 5103" makes the brick play the internal sound number 3.
    Another example, the command "c:\nqc.exe -Susb -raw 2181" makes the brick start the motor number 1.
    My problem is that other commands get the value of a sensor that is connected on the brick.
    For example, the command "c:\nqc.exe -Susb -raw 120901", when I type it in a dos window returns the value of sensor number 1.
    In B4PPC, I would like to put this return value in a variable.

    Thank you.
     
  4. Cableguy

    Cableguy Expert Licensed User

    How does the "brick" conect to the desktop...?
    perhaps it all can be done with serial com...
     
  5. agraham

    agraham Expert Licensed User

  6. Cableguy

    Cableguy Expert Licensed User

    yes, but from what I could google about mindstorms, there are a few ocx, and .net based dll, so a wrapper should sufice, thus making the need of shell obsolete....
    And far better performance I think...

    Here's one:
     
    Last edited: Jun 13, 2008
  7. pmu5757

    pmu5757 Member Licensed User

    The Mindstorms brick I have is the old one, the RIS 2.0, and not the new one (NXT).
    The line between the brick and the PC is infrared : an infrared sender is connected to one usb port of the PC.
    I agree with Cableguy, concerning the low performance of the shell commands, but I personnaly don't know how to do a "wrapper", I only know B4PPC, So I'll try with shell commands.

    Thank you
     
  8. Cableguy

    Cableguy Expert Licensed User

    since you are using an IR tower, it must have a com port assigned to it, then the rest should be "normal" serial comunication...
    I found alot of info about mindstorms and .net, also some sets of command and relations....
    Nothing like an hands-on aproach to see if it works...
    use one of the serial IR examples to send a simple, ON/OFF command and see if it works...
    If so, build on it...

    PS.I wish I had one of those to play with....
    perhaps if you decide to upgrade to the new version...argh just daydreamming
     
  9. agraham

    agraham Expert Licensed User

    I don't think it does. I believe that it requires its own USB driver to be installed and my guess would be that it is an HID (Human Interface Device) device (like a keyboard or mouse) as this is an easy way to interface a slow(ish) speed device to USB without writing a complicated driver as Windows already has a generic HID driver available. The interface is by File I/O calls and calls to a Windows dll - HID.DLL
     
  10. Cableguy

    Cableguy Expert Licensed User

    continuin googling I found that RIS2.0 should have come with, msot probably, a CD with some software, including .NET runtimes (DLL's)...
    If this is to be true, then one of two things are true..
    They(the dll's) run from B4PPc or need a wrapper...
    The IR tower, as far as I could figure, is standart issue in RIS2.0
     
  11. pmu5757

    pmu5757 Member Licensed User

    Agraham,
    As I'm not a B4PPC expert, I think I need an example of using your library with its "lastexitcode" property.
    Could you do it for me ?
    I just need to launch a shell command and put its return code in a variable.
    Thank you.

    Pascal.
     
  12. agraham

    agraham Expert Licensed User

    I misquoted the name of the property, it is actually called ExitCode not LastExitcode. See example.
     

    Attached Files:

  13. pmu5757

    pmu5757 Member Licensed User

    Hello Agraham
    Thank you for your example, it's very clear for a newbie like me.
    But unfortunately, it doesn't work.

    In a dos windows I type :
    C:\>c:\nqc.exe -Susb -raw 120901
    It answers :
    54 00
    This works

    In your example, I use the line :
    Process.Start("c:\nqc.exe" ,"-Susb -raw 120901")
    Result : the command is launched (I can see the red light on the infrared lego tower), but a 0 is returned.

    I suppose that your example only gets error codes and that "54 00" is not an error code. So it answers "0" that means "no error".

    I then tried to redirect the result of the command in a text file :
    In a dos widow, I type : C:\>c:\nqc.exe -Susb -raw 120901 > sortie.txt
    Then the file "sortie.txt" contains "54 00" : it works.

    In your code I then use the line : Process.Start("c:\nqc.exe" ,"-Susb -raw 120901 > sortie.txt")
    I obtain the number "-13" that indicates an error I presume, because the file "sortie.txt" is neither created, nor modified if it exists...

    I think I still need help...

    Pascal.
     
  14. agraham

    agraham Expert Licensed User

    My example does just this. The problem is that it is not the return code that you require :(

    It looks like that app writes the number to StdOut. StdOut and redirection of it only exists for a console app running in a DOS window. Executing it directly under Windows using Shell doesn't provide access to StdOut. The following code line starts the command interpreter "cmd" and instructs it "/c" to execute the rest of the argument string then terminate.

    Code:
    Process.Start("cmd""/c c:\nqc.exe -Susb -raw 120901 > " & AppPath & "\sortie.txt")
     
  15. taximania

    taximania Well-Known Member Licensed User

    Reminds me of the old days when I wrote a mouse driver in assembly for a 286 that couldn't run windows.

    ax
    dx

    etc ha ha ha
     
  16. pmu5757

    pmu5757 Member Licensed User

    Thank you Agraham.
    your "cmd" works well with a line like :
    Process.Start("cmd", "/c c:\nqc.exe -Susb -raw 120901 >> c:\sortie.txt")

    But not with your line with the AppPath statement...

    It doesn't matter, it's enough for me.

    Best regards

    Pascal.
     
  17. agraham

    agraham Expert Licensed User

    It should work - it does for me. Did you make a typo in appending the strings?

    Note that you could revert to using the standard B4ppc "Shell" function as you don't need the return value.
     
  18. pmu5757

    pmu5757 Member Licensed User

    Sorry, but with my poor english, I don't understand what you mean with "make a typo in appending the strings".

    Anyway, your other idea is good : using the "cmd" only when I need to return a value, and using the standard shell command if not.

    Pascal.
     
  19. agraham

    agraham Expert Licensed User

    Make a mistake when adding the three strings for the arguments parameter
    "/c c:\nqc.exe -Susb -raw 120901 > " & AppPath & "\sortie.txt"

    What I meant was that you can use cmd with the standard Shell command instead of using Process as you don't want the exitcode of the app, only what it writes to StdOut.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice