windows, read serial port run command

Okay there is another user that wants to read the serial port in a windows command line then have it start a program based on that data (lets say there is a new keg and they want to fire up some party music, I dunno)

so poking around with it I kinda made a mostly useless kludge of a lua script that sorta does that, the lua script polls a com port, and if the command matches do something, kinda simple but ...

BUGS
lua by nature has no io for ports at all, so I am fudging it a little by treating the com port like a file, opening it and closing it each loop. The problem with that is, if you close out of it and the port is still open the script will lock the port open and you cant use it

if this happens you need to terminate the lua script (by task manager or ctrl c, and it may take a few tries) open a terminal like putty or even the serial monitor in arduino, bang enter a few times (or the send button) and then it will snap out of it, course the intent of this is to run in the background for who knows how long so its only a minor annoyance while fiddling with it

Also the nature of the cmd prompt only lets you run 1 program from it at a time, so if your input triggers a program, it aint doing jack until that program exits and returns control to lua. I looked at the "start" command but it actually kills lua to use it so 1 at a time or single shot it seems (maybe someone has a better way)

its sort of like interrupts, do it quick and get out of dodge

anyway I am going to post a zip file, which contains core lua binaries for 32 bit windows (runs on 64 bit) the script and a couple batch files

by default I have these batch files pointing to C:\lua\ so if you place them somewhere else you may have to edit 1 or both batch files

RUN-ME-SILENT.vbs is a windows script file that will run the program but in the background (so no annoying cmd box to get in the way) and if you want to stop the program you will have to find lua.exe in the taskmanager under processes

GO.bat is what actually starts lua along with its script, this is called from the vbs file, but if you run it by itself it does the same thing, but leaves a cmd window open

anyway its a clunky time killer, maybe someone can find use for it

http:www.cheesefactory.us/filecenter/arduino/lua.zip

Thanks!
.
The many bumps on my head could have been prevented if I had read this earlier. :slight_smile:
.
Just took on Lua for interfacing into FS9 and have been attempting to "listen" to the Arduino.
Here is what I will do with the control switch position data from the Arduino.
http://bit.ly/adfi2K
Now we are going to have to make Lua talk to a second Arduino to command some indicator lights and servo position for the "steam gauges" on the instrument panel of the Long-EZ.

.
Thanks again.
.
kindest,
-b

Okay, after a UH-DUH moment if you want it to fire an app and keep on trucking change the script to

serial_port = "com4" -- the serial port data is entering


while 1 do
      serial = assert(io.open(serial_port,"r"))
      serial:flush()
      data = serial:read("*l")
      serial:close()
      if data == "hello world" then
            os.execute("start calc.exe")
      end
end

and use start before your command, so lets say you wanted a personal shortcut keys device, you can now set a button to launch (however many sessions of) firefox, calc, word or winamp you want on via serial port input