MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




problem while read NMEA.txt file

This is a discussion on problem while read NMEA.txt file within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; Hello, Thank you very much for you peoples efforts in mine previous work. Please let me know about the NMEA ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 04-24-2008
Member
Yellow Belt
 
Join Date: Mar 2008
Posts: 37
problem while read NMEA.txt file

Hello,
Thank you very much for you peoples efforts in mine previous work.
Please let me know about the NMEA Simulator which I am working on nowadays. I want to develop a simulator which will get data from NMEA.txt file and will show on screen. Mine code is extracting data which I placed in timer and I am facing two problems .
1. when I use this
Code:
str = sr.ReadToEnd();
it will show all mine txt file but it is not updating continuously.
2. When I use this
Code:
 str = sr.ReadLine();
it shows only first line of txt file and it is continuously updating.
All i want to keep on updating continuously mine txt file data which I will use to mine application.
Code:
 private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {       
FileStream gul = new FileStream("C:/GPS.txt.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader nasir = new StreamReader(gul);
string str = nasir.ReadLine();
//str = nasir.ReadLine();
while (str != null)
{
    txtResults.Text = str;
    str = nasir.ReadLine();
    //str = nasir.ReadToEnd();
    
}
 }
Hope to hear from u guys.
Regards.
nasir
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 04-28-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,037
Re: problem while read NMEA.txt file

Hi,

Your code example read the file line by line by ReadLine() until the end of file is reached. since you do it in a timer event the next time the same file is completely read, so if it is updated then you also have updated information. Do I understeand you question well? If not please rephrase.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 04-28-2008
Member
Yellow Belt
 
Join Date: Mar 2008
Posts: 37
Re: problem while read NMEA.txt file

Hi,
Thanks for yours reply.Well when I use it in public Form1()
Code:
 str = nasir.ReadLine();
and this in timer1_Tick
Code:
txtResults.Text = str;
it only reads first line. With using str = nasir.ReadToEnd(); it show me whole text file. I am not able to understand how to show mine text file line by line with some timer delay as I fixed it to 1.. I am also using array but when I insert in for() loop and want to show as result txtResults.Text = str[i]; it shows only last line.
Please let me know how to do it.
regards.
nasir
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 04-28-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,037
Re: problem while read NMEA.txt file

Hi,

I understand what you wants to do now. But there can be a problem. ReadLine() will work, but if another program updates the file it is possible that ReadLine() will forever will return null. Not sure of it, but this can be an untested situation and may change.

You can however close the file, and after a timer expires open it again and read it complete. But file will always get bigger and bigger so your program will slow down in time. Also you have to count the lines to see if a new line is appended.

There is also another problem. If you read the last line in the middle where the other program is updating it then you possible have only part of the line.

Question: is the program that write to the file also from you as author or do you have the source ? Because then easy synchronization can be done. but let me know first.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 04-28-2008
Member
Yellow Belt
 
Join Date: Mar 2008
Posts: 37
Re: problem while read NMEA.txt file

Hello,
many thanks for yours reply. Well I got control on it. what I did as in public
Code:
 
protected FileInfo theSourceFile = null;
protected StreamReader reader = null;
protected string text = " "; // assigned to allow first line to be read below
then in timer i fixed this
Code:
 private void timer1_Tick(object sender, EventArgs e)
        {
            if (text != null)
            {
                text = reader.ReadLine();
                //Console.WriteLine(text);
                txtResults.Text = text;
                
            }
Now it keep on updating mine NMEA text file and when the file ends it restart it again.
Well yours question I am not going to write any file just using text file and mine software will act as simulator which keep on reading from the file to get GPGGA data and extract Lat & Lon and show it on map or you can say act as dummy don t need of any hardware.
Now I will try to extract GPGGA data from the updating file and get link with map.
Nasir
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 04-29-2008
Member
Yellow Belt
 
Join Date: Mar 2008
Posts: 37
Re: problem while read NMEA.txt file

Hello,
Please let me know how to read text file again, if mine present text file ends up. As for looping the reading of file I tried else, in timer but it is not restarting mine text file again.
How can I get it to read the text file in a continuous loop instead of just ending at the end of the text file?
Hope to hear from u guys.
Regards.
nasir
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 04-30-2008
Member
Yellow Belt
 
Join Date: Mar 2008
Posts: 37
Re: problem while read NMEA.txt file

Hello,
Any body have an experience of using text file as I am able to read it line by line properly in timer but i need to read it again after it has finished. I use if & else. When mine file has finished it goes to else but I don't know how I can read it back.
Regards.Nasir
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 05-01-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,037
Re: problem while read NMEA.txt file

Hi,

Use ReadLine() to read again. You don't tell us what the problem is.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 05-01-2008
Member
Yellow Belt
 
Join Date: Mar 2008
Posts: 37
Re: problem while read NMEA.txt file

Hi,
Thanks.
When I use readline(); in timer it keeps on showing me text file line by line by using
Code:
 protected string text = " "; // assigned to allow first line to be read below
it works fine but when my file ends up its show error
Code:
An unhandled exception of type 'System.NullReferenceException' occurred in NMEA.exe
Additional information: Object reference not set to an instance of an object.
i tried for readline();again in else but how it will update mine location again as previously timer was doing.
I want mine file to start again after it ends up.
Regards.
Nasir
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10 (permalink)  
Old 05-01-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,037
Re: problem while read NMEA.txt file

Hi,

ReadLine() returns null at end of file. You have to check for null pointers like this:

Code:
if (text != null)
   // do something with text
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/problem-while-read-nmea-txt-file-7566.html

Posted By For Type Date
Programming MapPoint in .NET - MP2K Magazine This thread Refback 04-30-2008 03:16 PM
The Magazine for MapPoint - MP2K Magazine This thread Refback 04-26-2008 05:03 PM

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

BB 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
Problem to open Excel file Chiara MapPoint 2006/2009 Discussion 2 07-19-2006 06:54 AM
NMEA Standard Anonymous MapPoint 2006/2009 Discussion 2 06-17-2004 01:54 PM
Correctly Mapping NMEA Data Anonymous MapPoint 2006/2009 Discussion 1 03-18-2004 01:28 PM
nmea sentence Anonymous MapPoint 2006/2009 Discussion 0 03-09-2004 06:36 AM
Import NMEA-data from a file into mappoint Anonymous MapPoint 2006/2009 Discussion 2 11-19-2003 12:17 PM


All times are GMT -5. The time now is 03:49 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5
MP2K Magazine
Visitor Map

Ski Holidays French Alps
Ski holidays in the French Alps are a unique and exciting experience. There are a great range of resorts which are great value when you book with Holiday Hypermarket online.

Cruise Travel Agent
Book your cruise with Travel Counsellors. We are an award winning travel agent and can help plan your perfect cruise.

Jamaica Holiday
Fancy a Jamaica Holiday? Then visit dealchecker.co.uk and find out what the big deal is. Book a bargain when you book online.

Holidays to St Lucia
Holidays to St Lucia will leave you smiling. The spectacular scenery and the warmth of the locals make holidays to St Lucia unforgettable.

Tunisia
Tunisia enjoys excellent weather, golden beaches and a beautiful blue sea. Moving away from the beach you will find a country that has a rich and varied past. Discover the secrets of history yourself by exploring all the ruins.

Bargain Holidays
To plan your holidays at bargain prices, use Travel.co.uk to explore all the possibilities.

Portugal Holidays
We specialise in Portugal holidays. Visit our On The Beach website for more information.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53