Shop OBEX P1 Docs P2 Docs Learn Events
Need WinOS command line pgm -- can you help JonnyMac help a friend? — Parallax Forums

Need WinOS command line pgm -- can you help JonnyMac help a friend?

JonnyMacJonnyMac Posts: 9,107
edited 2013-12-09 19:43 in General Discussion
Another guy who uses the Propeller and works around movie and TV props asked me for help on a project -- and as I have focused all of my time on embedded programming I'm out of my depth when it comes to the PC side.

Here's what we need:

-- command line program called RUREADY.EXE
-- will take two parameters: com port and connection attempts, for example:

C:\ >RUREADY COM1 500

Behavior:

-- on running, open the com port and send "?" character at 57_600 baud
-- repeat every 20ms for number of attempts specified
* if no attempts specified, default to 100 (if this is not too much effort)
-- if "!" received, transmit "NOW!", wait 5 seconds then exit

The reason for waiting is in case the DTR line gets fiddled and resets the Propeller (we will be using a QuickStart connected to the PC -- it needs a second to do what it needs to do with its own IO.

The com port can simply be a number if that makes things easier.

I have CodeBlocks and MinGW on my computer but am just getting into it. My friend needs this quickly, as he is helping someone else.

Thanks for your consideration. If you can do it and provide a stand-alone executable I will be very grateful. I'll be especially grateful if I could open the code and re-compile it with CodeBlocks/MinGW so that I can learn from it. The last part is a nice-to-have, not have-to-have.

Thank you very much for your consideration.

Jon

Comments

  • jazzedjazzed Posts: 11,803
    edited 2013-12-09 16:43
    Hi Jon,

    Will it be a Windows only application?

    Usually DTR will toggle when all programs using the serial port are finished.

    Added: Guess the thread title says it's Windows only. Doubt I could do today. So much "Honey, do this and that."
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-12-09 18:37
    Steve,

    I actually got it working in Python -- muddled though, but made it work. Well, not with as much flexibility as I asked for, but I think that's fine. I fixed the COM port and attempts in the code. If this all happens, I will help my friend reassign the COM ports on his Propeller boards to match.

    For you Python gurus, have a laugh at my expense. If there's an opportunity to teach me something, please take it! :)
    # RUREADY Python host
    # by Jon McPhalen
    # 09 DEC 2012
    
    import serial
    import time
    
    success = False
    
    ser = serial.Serial("COM1", 57600, timeout=0.05)    # 50ms timeout
    
    for tries in range(0, 99):
        print "."                                       # show host activity
        ser.write("?")                                  # send prompt
        check = ser.read()                              # get one character
        if check == "!":
          ser.write("NOW!")                             # send command to operate
          success = True
          break                                         # quit loop
        
    if success == True:
        print("\n\nConnected and sent command\n")
    else:
        print("\n\nFailed to connect\n")
    
    time.sleep(5.0)                                     # let device run
    ser.close()                                         # release serial port
    exit()                                              # end program
    
  • jazzedjazzed Posts: 11,803
    edited 2013-12-09 18:44
    Well, I found some time anyway :)

    Ooops, the initial version didn't send the '?' at startup. This latest one does.
    C:\gccdev\propgcc\loader\src>ruready
    Usage: ruready <port#> [attempts#]
    
    C:\gccdev\propgcc\loader\src>ruready 42 400
    Looking for '!' on port 42. Attempts 400.
    Got !
    Sent 'NOW!'
    Sleeping 5 seconds.
    
    C:\gccdev\propgcc\loader\src>ruready 42
    Looking for '!' on port 42. Attempts 100.
    Got !
    Sent 'NOW!'
    Sleeping 5 seconds.
    
    C:\gccdev\propgcc\loader\src>
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-12-09 18:46
    Here's a Perl version (.exe attached).
    use strict;
    
    use Win32::SerialPort;
    use Win32;
    use Carp::Heavy;
    
    my ($port, $tries) = @ARGV;
    $tries = 100 unless $tries;
    my $Port;
    
    unless ($Port = new Win32::SerialPort("\\\\.\\$port")
      and $Port->baudrate(57600)
      and $Port->parity('none')
      and $Port->databits(8)
      and $Port->stopbits(2)
      and $Port->buffers(4096,4096)
      and $Port->binary(1)
      and $Port->write_settings)
    {
      print "Error opening $port.\n";
      exit
    }
    Win32::Sleep 100;
    my (undef, $n, undef, $err) = ($Port->status);
    if ($err) {
      $Port->reset_error;
    }
    foreach (0 .. $tries - 1) {
      $Port->write('?');
      Win32::Sleep 20;
      my $stream = $Port->input;
      if ($stream =~ m/\!/) {
        print "NOW!\n";
        Win32::Sleep(5000);
        $Port->close;
        exit
      }
    }
    $Port->close
    

    -Phil
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2013-12-09 19:08
    Here is a windows version, its plain and simple the command line is the executable name space com port space attempts, eg: ruready 1 200

    There is a certain amount of error trapping and the command line could be enhanced to accept more arguments or have some kind of "switch" system (-c -a etc.)

    It also reports success or failure as it runs.

    Jeff T.

    EDIT I just realized the port is not closed when the app finishes, not a big deal for now if you want it I can re-post an update
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-12-09 19:43
    Thanks, guys!

    @Phil: I had a little side bet in my head that you'd show me how to do this in Perl; which I find fascinating but not sure I'll ever tackle. I won that bet, think I'll treat myself to a beer! :)
Sign In or Register to comment.