|
Yes Andrew, i have tried it. But it couldn't solve the problem.
Regards,
Raja.
|
|
|
|
|
Hi, Raja,
In that case, I really cannot help much. However, you may try my class that has been working for me for a couple of years now.
To use my class:
kgvCSerialCom gpsPort;
CString csPortName;
csPortName.Format(_T("COM%d"),port_num);
//Baud Rate: 4800
//Data Bits: 8
//Parity: None
//Stop Bits: 1
//No Flow Control
// 9600 8 odd 1
if( !gpsPort.OpenPort(csPortName) ) return 0;
if( !gpsPort.ConfigurePort(m_gpsBaudRate, m_gpsByteSize,
m_gpsfParity, m_gpsParity, m_gpsStopBits) ) return 0;
if( !gpsPort.SetupComm(getGpsPort(),1200,1200) ) return 0;
if( !gpsPort.PurgeComm(getGpsPort(),PURGE_RXCLEAR) ) return 0;
//
char gpsString[600];
unsigned long bytesRead;
//
for(int i=0; i<1000; i++) { // stop after 10 minute
bytesRead = 0;
BOOL bReadOk = ReadFile( kgvGpsApi::GpsApi.getGpsPort(),
gpsString, 512, &bytesRead, 0 );
if( bReadOk && bytesRead>0 ) {
gpsString[bytesRead] = '\0';
//write to a file or display somewhere
}
Sleep(500);
}
gpsPort.ClosePort();
Please note that, I have not tested the above code. It only serves as an example.
*****************************************
***** Header file ******* kgvCSerialCom.h
*****************************************
#pragma once
// SerialCom.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CSerialCom window
//////////////////////////////////////////////////////////////////////
// SerialCom.h: implementation of the CSerialCom class.
// Written by Shibu K.V (shibukv@erdcitvm.org)
// Copyright (c) 2002
//
// To use CSerialCom, follow these steps:
// - Copy the files SerialCom.h & SerialCom.cpp and paste it in your
// Projects Directory.
// - Take Project tab from your VC++ IDE,Take Add to Project->Files.Select files
// SerialCom.h & SerialCom.cpp and click ok
// - Add the line #include "SerialCom.h" at the top of your Dialog's Header File.
// - Create an instance of CSerialCom in your dialogs header File.Say
// CSerialCom port;
// Warning: this code hasn't been subject to a heavy testing, so
// use it on your own risk. The author accepts no liability for the
// possible damage caused by this code.
//
// Version 1.0 7 Sept 2002.
//////////////////////////////////////////////////////////////////////
class kgvCSerialCom //: public CWnd
{
// Construction
public:
kgvCSerialCom();
HANDLE hComm;
DCB m_dcb;
COMMTIMEOUTS m_CommTimeouts;
BOOL m_bPortReady;
BOOL bWriteRC;
BOOL bReadRC;
DWORD iBytesWritten;
DWORD iBytesRead;
DWORD dwBytesRead;
// Implementation
public:
BOOL ReadByte(BYTE &resp);
BOOL WriteByte(BYTE bybyte);
BOOL OpenPort(const CString &portname);
BOOL SetCommunicationTimeouts(DWORD ReadIntervalTimeout,DWORD ReadTotalTimeoutMultiplier,DWORD ReadTotalTimeoutConstant,DWORD WriteTotalTimeoutMultiplier,DWORD WriteTotalTimeoutConstant);
BOOL ConfigurePort(DWORD BaudRate,BYTE ByteSize,DWORD fParity,BYTE Parity,BYTE StopBits);
virtual ~kgvCSerialCom();
void ClosePort();
BOOL IsPortReady( ) const { return m_bPortReady && hComm!=INVALID_HANDLE_VALUE; };
};
*********************************
*** Source file kgvCSerialCom.cpp
*********************************
// SerialCom.cpp : implementation file
//
#include "stdafx.h"
#include "kgvSerialCom.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// SerialCom.cpp: implementation of the CSerialCom class.
// Written by Shibu K.V (shibukv@erdcitvm.org)
// Copyright (c) 2002
//
// To use CSerialCom, follow these steps:
// - Copy the files SerialCom.h & SerialCom.cpp and paste it in your
// Projects Directory.
// - Take Project tab from your VC++ IDE,Take Add to Project->Files.Select files
// SerialCom.h & SerialCom.cpp and click ok
// - Add the line #include "SerialCom.h" at the top of your Dialog's Header File.
// - Create an instance of CSerialCom in your dialogs header File.Say
// CSerialCom port;
// Warning: this code hasn't been subject to a heavy testing, so
// use it on your own risk. The author accepts no liability for the
// possible damage caused by this code.
//
// Version 1.0 7 Sept 2002.
//////////////////////////////////////////////////////////////////////
// CSerialCom
kgvCSerialCom::kgvCSerialCom()
{
hComm=INVALID_HANDLE_VALUE;
}
kgvCSerialCom::~kgvCSerialCom()
{
if( hComm!=INVALID_HANDLE_VALUE ) CloseHandle(hComm);
}
//BEGIN_MESSAGE_MAP(kgvCSerialCom, CWnd)
//{{AFX_MSG_MAP(kgvCSerialCom)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
//END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// kgvCSerialCom message handlers
// Example : OpenPort(L"COM2");
//
BOOL kgvCSerialCom::OpenPort( const CString &portname)
{
CString csPTN =_T("\\\\.\\"); //_T("//./");
#if WINVER > 0x0410
csPTN += portname;
#else
csPTN =portname;
#endif
hComm = CreateFile( csPTN,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
0,
0);
//
// hGpsPort = CreateFile(csPort, GENERIC_READ | GENERIC_WRITE,
// 1,NULL, OPEN_EXISTING,0,NULL);
return hComm!=INVALID_HANDLE_VALUE;
}
BOOL kgvCSerialCom::ConfigurePort(DWORD BaudRate, BYTE ByteSize,
DWORD fParity, BYTE Parity, BYTE StopBits)
{
if( hComm==INVALID_HANDLE_VALUE ) return FALSE;
if((m_bPortReady = GetCommState(hComm, &m_dcb))==0){
#ifdef _DEBUG
AfxMessageBox(L"GetCommState Error",MB_OK+MB_ICONERROR,-1);
#endif
CloseHandle(hComm);
hComm = INVALID_HANDLE_VALUE;
return false;
}
m_dcb.BaudRate = BaudRate;
m_dcb.ByteSize = ByteSize;
m_dcb.Parity =Parity ;
m_dcb.StopBits =StopBits;
m_dcb.fParity=fParity;
/*
m_dcb.fBinary=TRUE;
m_dcb.fDsrSensitivity=false;
m_dcb.fOutX=false;
m_dcb.fInX=false;
m_dcb.fNull=false;
m_dcb.fAbortOnError=TRUE;
m_dcb.fOutxCtsFlow=FALSE;
m_dcb.fOutxDsrFlow=false;
m_dcb.fDtrControl=DTR_CONTROL_DISABLE;
m_dcb.fDsrSensitivity=false;
m_dcb.fRtsControl=RTS_CONTROL_DISABLE;
m_dcb.fOutxCtsFlow=false;
m_dcb.fOutxCtsFlow=false;
*/
m_bPortReady = SetCommState(hComm, &m_dcb);
if(m_bPortReady ==0){
CloseHandle(hComm);
hComm = INVALID_HANDLE_VALUE;
return false;
}
return true;
}
BOOL kgvCSerialCom::SetCommunicationTimeouts(DWORD ReadIntervalTimeout,
DWORD ReadTotalTimeoutMultiplier,
DWORD ReadTotalTimeoutConstant,
DWORD WriteTotalTimeoutMultiplier,
DWORD WriteTotalTimeoutConstant)
{
if( hComm==INVALID_HANDLE_VALUE ) return FALSE;
if((m_bPortReady = GetCommTimeouts (hComm, &m_CommTimeouts))==0) return false;
m_CommTimeouts.ReadIntervalTimeout =ReadIntervalTimeout;
m_CommTimeouts.ReadTotalTimeoutConstant =ReadTotalTimeoutConstant;
m_CommTimeouts.ReadTotalTimeoutMultiplier =ReadTotalTimeoutMultiplier;
m_CommTimeouts.WriteTotalTimeoutConstant = WriteTotalTimeoutConstant;
m_CommTimeouts.WriteTotalTimeoutMultiplier =WriteTotalTimeoutMultiplier;
m_bPortReady = SetCommTimeouts (hComm, &m_CommTimeouts);
if(m_bPortReady ==0){
CloseHandle(hComm);
hComm = INVALID_HANDLE_VALUE;
return false;
}
return true;
}
BOOL kgvCSerialCom::WriteByte(BYTE bybyte)
{
iBytesWritten=0;
if( hComm==INVALID_HANDLE_VALUE ) return FALSE;
if(WriteFile(hComm,&bybyte,1,&iBytesWritten,NULL)==0) return false;
else return true;
}
BOOL kgvCSerialCom::ReadByte(BYTE &resp)
{
BYTE rx;
resp=0;
DWORD dwBytesTransferred=0;
if( hComm==INVALID_HANDLE_VALUE ) return FALSE;
if (ReadFile (hComm, &rx, 1, &dwBytesTransferred, 0)){
if (dwBytesTransferred == 1){
resp=rx;
return true;
}
}
return false;
}
void kgvCSerialCom::ClosePort()
{
if( hComm==INVALID_HANDLE_VALUE ) CloseHandle(hComm);
hComm = INVALID_HANDLE_VALUE;
return;
}
|
|
|
|
|
Hello,
I have written an application that use the following USB GPS receiver
http://www.pocketgpsworld.com/fortuna-u2-gps.php[^]
Everything is great, well kind of, I hook out the $GPGGA line, take it apart and give it to my user as data for MS Autoroutes import data wizard. Now, that requires a degree decimal format, however, during this phase I noticed that my co-ordinates are about 300-400 metres out??? Sure enough my conversion from the output (degrees, minutes, seconds) is good but the data is bad. So I've tested the other GPS unit at work and sure enough same result - duff data. However, if I plug them both into Autoroute directly - no problem ~10m accuracy.
So what is the trick I'm missing? I know that I must match GPS and Autoroute datums but both use WGS-84 (apparently). I cannot seem to get to the bottom of this quickly. Anyone any ideas?
BTW coversions are ((((seconds/60) + minutes)/60)+ degrees). About 3 or four decimal place accurate but not as accurate as MS Autoroute on the same data.
You can please some of the people all of the time and all of the people some of the time but not all of the people all of the time.
|
|
|
|
|
Here is the data problem
Oh here is a for instance.
Portmon read data:
$GPGGA,072916.333,5125.1361,N,00058.5236,W,1,05,2.6,98.9,M,47.3,0.10012362129: ,,,,,,,3.6,2.6,2.3*3B..
Which I see as
5125.1361N and 000058.5236W = +51.42044722 and -0.98121111. Unfortunately the data, when replotted on mapping s/w, is just not accurate. However, MS autoroute with the same data gives the more correct value of +51.41891 and -0.97521. I just want to know how to mimic the same fudge.
You can please some of the people all of the time and all of the people some of the time but not all of the people all of the time.
|
|
|
|
|
Ok - answered this myself.
NMEA standard is degrees and minutes - not as I thought degrees, minutes and seconds
Therefore 5125.1361N = 51°25.1361' not 51°25'13.61".
You can please some of the people all of the time and all of the people some of the time but not all of the people all of the time.
|
|
|
|
|
is there a small park or lake next to your place (35° 44.56' N 51° 30.669' E) ? referring to maps.google.com there should be. teheran looks nice (at least from above ). that's me: 47.060264° N 15.468658° E
|
|
|
|
|
Yeah. Did you see Tehran or Shiraz? Take a look at Shiraz, the cultural capital of Iran.
Best regards,
A. Riazi
|
|
|
|
|
i haven't been to iran yet but i should go there someday.
regards
|
|
|
|
|
If you want to visit Iran, visit these cities:
Shiraz,
Esfahan (Isfahan),
Kashan,
Tabriz,
Kerman
Best regards,
A. Riazi
|
|
|
|
|
Hi there,
I'm doing a project where I need to map positions - longitude and latitiude - to a coordinate system in order to display a dot representing current location as well as a trail of the route up to latest known location. Can you point me in a direction of how to best accomplish this task? Maybe with sample code?
Great article!
|
|
|
|
|
to implement the project depends on what language you are master of.But few tips and direction are;
1. If you are matlab user it is easy.Read the data via serial port(example code available on mathworks site:file name=SerialGPS.zip). Then use the simple command to plot the data recieved. It is all given in the sample code as mentioned.
2. For C++, see the artticle of Mr A Riazi on this page of www.codeproject.com. Article name is:"Add GPS support to your desktop"
3. For VB application, see "Writing Your Own GPS Applications: Part I&II",By Jon Person(on same site)
4. For free software,"GPSNMEA" is a free program to
display and log data from a GPS reciever.
Contributed by Wolfgang.Pieper@psychol.uni-giessen.de
hope it fills your appetite
regards
Arslan
|
|
|
|
|
Hi!
Thanks for great work!
This code is what I really want.
I bought a GPS made by DeLORME.
my COM port is COM5.
Of course, I could check if this COM5 port works correctly using Hyperterminal of MS.
Hyperterminal showed me stable communication status.
The problem is the initial OpenPort command works well.
But, whenever the new thread is invoked after the thread is terminated, OpenPort() failed.
So, I tried to modify this code so that it invoked a thread one time.
That means one thread continue to loop.
Unfortunate, after about 1~3 min, this application is blocked somewhere.
Before being blocked, data parsing is perfect!
The debugger didnot give me any useful information, since they stopped anywhere internal of ReadFile()or debugger
also didnot work. Of course, I can not use GetLastError(), either.
Obviously, ReadFile() have a problem. I just guessed memory might be leak somewhere. but
the possibility is very low.
What I know exactly is that everytime, in the same assembly code position, this code stopped.
I wonder I must use ReadFileEX() for the async read.
Could you give me any hint or any idea?
ILMO JUNG.
|
|
|
|
|
Hi,
I got the code of serial communication from another article. Please contact the author of that article.
Best regards,
A. Riazi
|
|
|
|
|
Thanks for very early answer!
ILMO JUNG.
|
|
|
|
|
For the reference,
I add these.
My GPS has WAAS ability and it is NMEA0183 compatible.
[TRACE result in the debug windows]
Source is "OS:"
CompanyName ""
At 06:36.12 AM UTC, you were at Latitude 29 41.78100 North, Longitude 95 23.41380 West, a GPS fix was not available, 0 satellites are in use.
At 06:36.12 AM UTC, you were at Latitude 29 41.78100 North, Longitude 95 23.41380 West, making 0.000000 knots, track made good 0.000000 degrees true.
At 06:36.13 AM UTC, you were at Latitude 29 41.77730 North, Longitude 95 23.39340 West, based upon a GPS fix, 4 satellites are in use.
At 06:36.13 AM UTC, you were at Latitude 29 41.77730 North, Longitude 95 23.39340 West, making 0.000000 knots, track made good 0.000000 degrees true.
At 06:36.14 AM UTC, you were at Latitude 29 41.77870 North, Longitude 95 23.39640 West, based upon a GPS fix, 4 satellites are in use.
At 06:36.14 AM UTC, you were at Latitude 29 41.77870 North, Longitude 95 23.39640 West, making 0.000000 knots, track made good 0.000000 degrees true.
..(application and VS is stopped)
[Hyper Terminal Results]
$Version 231.000.000ES-01501
$GPS Port B : User Protocol
$TOW: 110187
$WK: 1315
$POS: -520859 -5520454 3141153
$CLK: 95012
$CHNL:12
$Baud rate: 4800 System clock: 24.553MHz
$HW Type: S2AM
$Asic Version: 0x23
$Clock Source: GPSCLK
$Internal Beacon: None
$LED Flash rate : OnTime: 10 , OffTime: 10
$GPGGA,063723.749,2941.7788,N,09523.3966,W,0,00,50.0,-45.9,M,-23.7,M,0.0,0000*6A
$GPGSA,A,1,,,,,,,,,,,,,50.0,50.0,50.0*05
$GPGSV,3,1,09,23,61,333,00,16,53,041,38,20,43,223,00,03,33,140,00*78
$GPGSV,3,2,09,13,30,321,00,01,25,122,38,25,17,072,00,19,15,162,00*71
$GPGSV,3,3,09,27,08,277,00*4F
$GPRMC,063723.749,V,2941.7788,N,09523.3966,W,0.00,0.00,210305,,*03
$GPGGA,063724.749,2941.7800,N,09523.4153,W,1,03,19.5,-45.9,M,-23.7,M,0.0,0000*61
....
|
|
|
|
|
hi ,
i am able to get GPS data using nmea0183 and able to get the latitude and longitude . i want to know how i can convert them to xyz co-ordinates.
can anybody help me
|
|
|
|
|
Sorry! I can't read your message.
A. Riazi
|
|
|
|
|
Hi,
I am new to this field.So can u clear my following doubts
1)If two persons A and B have GPS Receivers, can each of them see where the other person is?.
|
|
|
|
|
No! GPS only send some basic data to sattellite and recieve location and ... data from sattellite. There is no communication between other GPSs.
A. Riazi
|
|
|
|
|
Well, but the answer can be YES, if this is for example a "Pocket-PC" device, and an application is provided to get the location and "Send" it via Wi-Fi or GPRS (depending on the distance between A and B) between the units..
Cheers
Alex
|
|
|
|
|
Good idea!!!
A. Riazi
|
|
|
|
|
I have A garmin GPS unit and a motorola microcontroller. The laptop I have USB/serially reads the incoming messages, parses the data, does some analysis of the data and then tried to steer the vehicle to a particluar destination using a steering motor and digital potentiometer to control acceleration. I have 12Volt switches to power the steering and 5 volts for the pot. I need a way to serially send '1''s and '0''s to the microcontroller as to control certain aspects of the vehicle. Basically I need 5 volts or 0 volts to turn the steering motor left or right and i need 5 volts to turn the pot on and accelerate. SO i have the C++ program serially reading data in and then i need to send other data out serially to a micro. Is serial port manipulation easy in VC++?
Alex
|
|
|
|
|
You can find various articles about serial port manipulation on codeproject!
Also see System section.
A. Riazi
|
|
|
|
|
Thats a cool article...
I wonder if car rental companies, etc, use this very technique to track there cars remotely.
Very cool none the less...now I wanna go out a get a new GPS...so I can play with this code.
Well done!
Cheers
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
The remote car tracker needs an active antenna to send location of car to some reciever. This technique requires some money!
A. Riazi
|
|
|
|
|