Pages: [1]   Go Down
Author Topic: windows, read serial port run command  (Read 1975 times)
0 Members and 1 Guest are viewing this topic.
SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ...

[glow]BUGS[/glow]
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://http:www.cheesefactory.us/filecenter/arduino/lua.zip
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!
.
The many bumps on my head could have been prevented if I had read this earlier. :-)
.
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.
http://en.wikipedia.org/wiki/Rutan_Long-EZ
.
Thanks again.
.
kindest,
-b

Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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
« Last Edit: August 17, 2010, 07:20:03 pm by Osgeld » Logged


Pages: [1]   Go Up
Jump to: