News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
io.open /dev/ttyS0
Author Message
chrimo
Member
***


Posts: 94
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #1
io.open /dev/ttyS0

Hi,

has anybody ever used murgaLua to communicate with a serial device ?
I'd like to write a userfriendly GUI for settings some modem switches.

Code fraqment:

Code:
port="/dev/ttyS0";
in=io.open(port,"r");
out=io.open(port,"w");

while(true) do
result=in:read("*line");
if(string.find(result,"RING")) then
out:write("ATA\n");
end
end



This is just a simple stupid stuff, but later useful for robotic applications
Any idea ?
Thanks
Bye
Christian

07-18-2007 07:45 AM
Find all posts by this user Quote this message in a reply
chrimo
Member
***


Posts: 94
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #2
RE: io.open /dev/ttyS0

chrimo Wrote:
Hi,

has anybody ever used murgaLua to communicate with a serial device ?
I'd like to write a userfriendly GUI for settings some modem switches.

Code fraqment:

Code:
port="/dev/ttyS0";
in=io.open(port,"r");
out=io.open(port,"w");

while(true) do
result=in:read("*line");
if(string.find(result,"RING")) then
out:write("ATA\n");
end
end



This is just a simple stupid stuff, but later useful for robotic applications
Any idea ?
Thanks
Bye
Christian



Hi all,

this code works very well with my Navilock-GPS Bluetooth receiver at OSX Big Grin
Now starting to code a simple GPS-Tracker-Application.

Bye
Christian

Code:
port="/dev/tty.BT-348_GPS-Serialport-1"

        ttyin = assert(io.open(port, "r"))
        ttyin:flush()
        while (1) do
           ttyin:flush()
           reply = ttyin:read("*line")
                print("Reply:"..reply);
        end

        ttyin:close()


Output from GPS:
Reply:$GPGSA,A,3,25,29,10,24,27,08,28,,,,,,2.2,1.2,1.8*34
Reply:$GPRMC,101733.000,A,5322.8875,N,00936.3823,E,0.07,191.51,290707,,,A*6A
Reply:$GPVTG,191.51,T,,M,0.07,N,0.1,K,A*06
Reply:$GPGGA,101734.000,5322.8874,N,00936.3823,E,1,07,1.2,48.1,M,46.1,M,,0000*65
Reply:$GPGSA,A,3,25,29,10,24,27,08,28,,,,,,2.2,1.2,1.8*34
Reply:$GPRMC,101734.000,A,5322.8874,N,00936.3823,E,0.19,250.10,290707,,,A*68
Reply:$GPVTG,250.10,T,,M,0.19,N,0.3,K,A*00
Reply:$GPGGA,101735.000,5322.8873,N,00936.3820,E,1,07,1.2,48.1,M,46.1,M,,0000*60
Reply:$GPGSA,A,3,25,29,10,24,27,08,28,,,,,,2.2,1.2,1.8*34
Reply:$GPRMC,101735.000,A,5322.8873,N,00936.3820,E,0.31,263.31,290707,,,A*64
Reply:$GPVTG,263.31,T,,M,0.31,N,0.6,K,A*0C
Reply:$GPGGA,101736.000,5322.8872,N,00936.3817,E,1,07,1.2,48.0,M,46.1,M,,0000*67
Reply:$GPGSA,A,3,25,29,10,24,27,08,28,,,,,,2.2,1.2,1.8*34
Reply:$GPRMC,101736.000,A,5322.8872,N,00936.3817,E,0.19,230.50,290707,,,A*69
Reply:$GPVTG,230.50,T,,M,0.19,N,0.3,K,A*02
Reply:$GPGGA,101737.000,5322.8871,N,00936.3816,E,1,07,1.2,47.9,M,46.1,M,,0000*62
Reply:$GPGSA,A,3,25,29,10,24,27,08,28,,,,,,2.2,1.2,1.8*34
Reply:$GPGSV,3,1,12,08,80,123,35,10,65,240,24,27,56,067,31,29,38,285,28*7C

07-29-2007 09:18 PM
Find all posts by this user Quote this message in a reply
chrimo
Member
***


Posts: 94
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #3
RE: io.open /dev/ttyS0

Hi,

now the first version of the GPSTracker.lua Big Grin

Code:
-- ***********************************************
-- GPSTracker.lua
-- Author: chrimo@moccy.xdsnet.de  and friends
-- Changes: initial startup
-- Beta-0 Test
-- Date: 2007-07-28    startup
-- Date:
-- ***********************************************

version="0.2007-07-28";
port="/dev/tty.BT-348_GPS-Serialport-1"
running=0;
UTCdiff=0;

--
-- GPS GUI
--

MaxWinSizeX=320;                      
MaxWinSizeY=80;                      

BorderX=1;
BorderY=1;

OutWinSizeX=MaxWinSizeX-BorderX;
OutWinSizeY=MaxWinSizeY-BorderY;

ButtonSizeX=79;
ButtonSizeY=30;

window = fltk:Fl_Double_Window(MaxWinSizeX, MaxWinSizeY, "GPSTracker");
window:tooltip("GPSTracker by Chrimo and friends "..version);
window:color(55);
window:align(fltk.FL_ALIGN_CENTER);
window:position(BorderX,BorderY);

startButton = fltk:Fl_Button(MaxWinSizeX/2-ButtonSizeX/2, MaxWinSizeY-ButtonSizeY-BorderY, ButtonSizeX, ButtonSizeY, "Start");
startButton:color(31);
startButton:selection_color(31);
startButton:tooltip("Start");

pos=1;
timeOut=fltk:Fl_Value_Output( pos*BorderX+(pos-1)*ButtonSizeX, BorderY, ButtonSizeX, ButtonSizeY, "");
timeOut:color(31);
timeOut:value(0);
timeOut:type(1);
timeOut:label("UTC");
timeOut:align(fltk.FL_ALIGN_BOTTOM);

pos=2;
latOut=fltk:Fl_Value_Output( pos*BorderX+(pos-1)*ButtonSizeX, BorderY, ButtonSizeX, ButtonSizeY, "");
latOut:color(31);
latOut:value(0);
latOut:type(1);
latOut:label("Latitude");
latOut:align(fltk.FL_ALIGN_BOTTOM);

pos=3;
longOut=fltk:Fl_Value_Output( pos*BorderX+(pos-1)*ButtonSizeX, BorderY, ButtonSizeX, ButtonSizeY, "");
longOut:color(31);
longOut:value(0);
longOut:type(1);
longOut:label("Longitude");
longOut:align(fltk.FL_ALIGN_BOTTOM);

pos=4;
altOut=fltk:Fl_Value_Output( pos*BorderX+(pos-1)*ButtonSizeX, BorderY, ButtonSizeX, ButtonSizeY, "");
altOut:color(31);
altOut:value(0);
altOut:type(1);
altOut:label("Altitude");
altOut:align(fltk.FL_ALIGN_BOTTOM);


function readGPS()
    while (1) do
           ttyin:flush()
        Fl:check();
        reply = ttyin:read("*line")
        Fl:check();
        parseGPGGA(reply);
    end
end

function parseGPGGA (s)
   _,_,time,lat,ns,long,ew,_,_,_,alt = string.find(s,"([^,]+),([^,]+),([NS]),([^,]+),([EW]),([^,]+),([^,]+),([^,]+),([^,]+)")
  
   if( nil ~= alt ) then
     timeOut:value(time+UTCdiff);
     latOut:value(lat);
     longOut:value(long);
     altOut:value(alt);
    
     Fl:check();
   end
end

function quit_callback(object)
    if fltk.fl_ask("Are you sure to quit now ?") >= 1 then
        window:hide();
        if(running ~= 0) then
            ttyin:close();
        end
    end
    os.exit();
end

function start_callback(object)
    if(running == 0) then
        ttyin = assert(io.open(port, "r"));
        ttyin:flush();
    end
    running=1;
    readGPS();
end

window:callback(quit_callback)
startButton:callback(start_callback)

window:show();
Fl:run();


I think it needs some more optimizations, but it works fine Big Grin

Bye
Christian

07-30-2007 05:51 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #4
RE: io.open /dev/ttyS0

This is VERY, VERY cool :-)

Almost makes we want to get a GPS thingy ...

Cheers
JohnM

07-30-2007 05:25 PM
Visit this user's website Find all posts by this user Quote this message in a reply
chrimo
Member
***


Posts: 94
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #5
RE: io.open /dev/ttyS0

JohnMurga Wrote:
This is VERY, VERY cool :-)

Almost makes we want to get a GPS thingy ...

Cheers
JohnM


Now I need to use this coordinates and try to map it to Google-Maps Big Grin

Bye
Christian

07-30-2007 06:13 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: