Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Read NMEA from Server


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2007, 03:51 PM
Junior Member
 
Join Date: Oct 2007
Posts: 45
Default Read NMEA from Server

Hello!!!

Ich have a Problem with reading a kompletly NMEA-protocol like "§GPGGA,..." (see Help 'StrSplit') from a server.
The Server sends every two seconds a NMEA-protokoll. Ich can see this in a Control-Monitor and the server allows every client to take this data. But in the 'filestream.ReadString' there are only some parts of the protocol. Sometimes parts out of the middle or something from the end. Only the first read is correct and begins with "GPGGA,...." With the folowing code i always checked the length of the string. This is every time different between 5 or 10 and perhaps 60 to 80.
I have tested the timer with 500,1000 and 2000 ms, but no different.
If i don't know, where the string begins, I can not take the parameters with 'StrSplit' to use them.

Here the nessesary parts of my code:

I use the components Network.dll and BinaryFile.dll

Sub App_Start
..
Timer1.Enabled=true
Client.New1
Client.Connect("87.139.78.???",11112)
..
end sub

Sub Timer1_Tick
..
if Client.DataAvailable=true then
filestream.New1(Client.Getstream,false)
Protokoll=filestream.ReadString
Label1.Text=Protokoll
Label2.Text=StrLength(Protokoll)
end if
..
end sub



I trie to find an answer for two weeks, but nothing.....

Thanks for help!!!
Reply With Quote
  #2 (permalink)  
Old 12-13-2007, 05:28 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,778
Default

You could try to use the GPS library.
The GPS.GPSStream collects pieces of NMEA strings and parses it when there is enough data.
Reply With Quote
  #3 (permalink)  
Old 12-15-2007, 09:35 AM
Junior Member
 
Join Date: Oct 2007
Posts: 45
Default GPSStream

Hello Erel, thanks for your fast answer.

But I have two problems with GPS.GPSStream: First i have give a kompletly NMEA-String to the GPSStream like


Sub Globals
NMEA="$GPGGA,161229.487,3723.2475,N,12158.3416,W,1 ,07,1.0,9.0,M,,,,0000*18"

end Sub

Sub Timer1_Tick
if NMEA<>"" then
gps.GPSStream(NMEA)
end if
End Sub

Sub GPS_GPSDecoded
Label1.text=gps.latitude
...
end Sub


but the GPS_GPSDecoded -Sub was not call. So I have call this Sub manuell, but there is no data from the NMEA-Protocol. I have tested it with GPGGA an GPRMC. What else i need to call the GPS_GPSDecoded, if the GPSBuffer have enough data?

The second Problem is, that my application takes the data from a GPS-mouse and the GPS-data from the server at the same time, because i calculate then distance and course of this two points. When I use the GPS.dll for both, the GPSBuffer takes the data from the GPS-mouse and from the server, so that I must have two different GPS-Objekts with two different GPS-Buffer.

To take the data from the server is my last problem of the application, then it run.

Frindly greetings

schimanski
Reply With Quote
  #4 (permalink)  
Old 12-15-2007, 09:58 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,778
Default

The GPS decoder waits for a full GPGGA and a full GPRMC sentences.
There is no problem with creating several GPS objects.
Reply With Quote
  #5 (permalink)  
Old 01-18-2008, 02:19 PM
Junior Member
 
Join Date: Oct 2007
Posts: 45
Default Problem with buffer from Server

Hello!

Thanks for the given answers. It was a great help for me. But now, i have again one problem:
When I read the NMEA-protocoll from the server by using the client-object and filestream.readstring over a GPRS-connection, i can take the data without problems. But if I dont' read the data form the server for perhaps one minute, the server will send me the NMEA-protocoll from one minute ago. If I wait three or four minutes and read then the filestream, i don't can take the actuell data, only the data from the time, i have stoped reading. The administrator from the server said, that the server doesn't buffer the data. Is it possible to make a reset, when i begin to read from the stream?





thanks for help....
Reply With Quote
  #6 (permalink)  
Old 01-18-2008, 02:32 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,778
Default

You can read the waiting data and discard it. Wait one second and read the new data.
Reply With Quote
  #7 (permalink)  
Old 01-18-2008, 09:43 PM
Junior Member
 
Join Date: Oct 2007
Posts: 45
Default How to discard?

Thanks for help, but i don't know, how I discard the old data? Which argument do I have to use?

m.f.G. schimanski
Reply With Quote
  #8 (permalink)  
Old 01-19-2008, 06:10 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,778
Default

Can you post the code that you use to read the data from the server and pass it to the GPS object?
Reply With Quote
  #9 (permalink)  
Old 01-19-2008, 01:41 PM
Junior Member
 
Join Date: Oct 2007
Posts: 45
Default The code, which I take the data from the server...

Hello Erel!

Here the code, which i take the data from the server:
If I don't take the data for perhaps two minutes, because i have selected another index in combobox2, i only can get the old data.


Sub Globals
Dim Type (Lat,Lon,HemLat,HemLon) Ziel
Dim Type (Lat,HemLat,Lon,HemLon,Geschwindigkeit,Kurs) Array_NMEA
..
end sub

Sub App_Start
GPS_Server.New1
..
end sub

'Create the server-connection, when button is clicked'
Sub Button4_Click
ErrorLabel(noconnection)
WaitCursor(true)
client.New1 'init Client-Objekt'
IP_Adresse=textbox18.Text
Port_Nummer=textbox19.Text
Client.Connect (IP_Adresse,Port_Nummer)

If timer2.Enabled=false Then timer2.Enabled = true
'I have tested the Timer with 2000, 1000 and 500 ms'
WaitCursor(false)
Return
noconnection:
..
End Sub

'Takes the data from the server'
Sub Timer2_Tick
ErrorLabel(connectionbreak)
if ComboBox2.SelectedIndex = 1 then
If client.DataAvailable=true Then
Image4.LoadPicture("IconDaten1.bmp")
filestream.New1(client.GetStream,false)
GPS_Server.GPSStream(filestream.ReadString)
Else
Image4.LoadPicture("IconDaten2.bmp")
End If
End If
Return

connectionbreak:
..
client.close
End Sub

'Read the GPS_Server-bufferstring'
Sub GPS_Server_GPSDecoded
ErrorLabel(GPS_Server_Fehler)
If GPS_Server.status="A" Then
Image3.LoadPicture("IconSat1.bmp")
Else
Image3.LoadPicture("IconSat2.bmp")
End If

Ziel.Lat=GPS_Server.DecimalLatitude
Ziel.HemLat=GPS_Server.LatitudeHemisphere
Ziel.Lon=GPS_Server.DecimalLongitude
Ziel.HemLon=GPS.LongitudeHemisphere

'Save the GPS-data from Server to create a NMEA-protocoll'
Array_NMEA.Lat=GPS_Server.Latitude
Array_NMEA.HemLat=GPS_Server.LatitudeHemisphere
Array_NMEA.Lon=GPS_Server.Longitude
Array_NMEA.HemLon=GPS_Server.LongitudeHemisphere
Array_NMEA.Geschwindigkeit=GPS_Server.SpeedOverGro und
Array_NMEA.Kurs=GPS_Server.CourseOverGround

Label11.Text=Round(GPS_Server.SpeedOverGround * 1.852)

Label20.Text=Round(GPS_Server.Altitude) & "(" & (Round(GPS_Server.Altitude)-Round(GPS.Altitude)) & ")"
Return

GPS_Server_Fehler:
End Sub

'Close server-connection'
Sub Button3_Click
client.Close
If timer2.Enabled=true Then timer2.Enabled=false
Image3.LoadPicture("IconSat2.bmp")
Image4.LoadPicture("IconDaten2.bmp")
End Sub


'Generate a NMEA-protokoll (GPRMC) an send it to a serial COM.port'
Sub Timer3_Tick

NMEA="$GPRMC," & Time(Now) & ",A," & Array_NMEA.Lat & "," & Array_NMEA.HemLat & "," & Array_NMEA.Lon & "," & Array_NMEA.HemLon & "," & Array_NMEA.Geschwindigkeit & "," & Array_NMEA.Kurs & "," & Date(Now) & ",0.4,E,A*"

'Berechnung der Prüfsumme'
buffer() = bit.StringToBytes(NMEA,1,StrLength(NMEA)-2)
laenge=ArrayLen(buffer())
Summe=buffer(0)
For i=1 To laenge-1
Summe=bit.XOR(summe,buffer(i))
Next
Pruefsumme=bit.DecToHex(Summe)

'Pruefsumme am NMEA-Protokoll anhängen'
NMEA=NMEA & Pruefsumme & crlf

serial_output.Output(NMEA)
End Sub



Reply With Quote
  #10 (permalink)  
Old 01-19-2008, 02:16 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,778
Default

You don't need to initialize filestream object each time you read the data.
Instead you should initialize once after creating the connection.

Maybe something like this will solve your problem:
Instead of:
Code:
Sub Timer2_Tick
    ErrorLabel(connectionbreak)
    If ComboBox2.SelectedIndex = 1 Then
        If client.DataAvailable=true Then
            Image4.LoadPicture("IconDaten1.bmp")
            'REMOVE THIS LINE:filestream.New1(client.GetStream,false)
            GPS_Server.GPSStream(filestream.ReadString)
        Else
            Image4.LoadPicture("IconDaten2.bmp")
        End If
    End If
    Return
    
    connectionbreak:
    ..
    client.close
End Sub
Discard the data if ComboBox2.SelectedIndex doesn't equal 1:
Code:
Sub Timer2_Tick
    ErrorLabel(connectionbreak)
    If ComboBox2.SelectedIndex = 1 Then
        If client.DataAvailable=true Then
            Image4.LoadPicture("IconDaten1.bmp")
            GPS_Server.GPSStream(filestream.ReadString)
        Else
            Image4.LoadPicture("IconDaten2.bmp")
        End If
    Else If client.DataAvailable Then
       fileStream.ReadString
    End If
    Return
    
    connectionbreak:
    ..
    client.close
End Sub
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Comunicating with a Telnet Server lu_ozzie Questions & Help Needed 16 05-05-2008 05:25 PM
Simple NMEA logger Bruno Share Your Creations 0 05-02-2008 07:43 PM
Checksum in nmea wolfgang Code Samples & Tips 0 02-15-2008 01:42 PM
Probleme beim Lesen eines NMEA-Protokolls schimanski German Forum 0 12-09-2007 05:20 PM
New server Erel Forum Discussion 12 11-06-2007 04:21 PM


All times are GMT. The time now is 11:35 PM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0