Sharing Serial port through COM Objects


2005-07-28 11:09:40 PM
cppbuilder48
First of all I wanted to say I'm pre-beginner in COM so, please be patient
or suggest a site where I can find what I want!
I'm planning on building a GPS infomation server with provides GPS
information. The GPS will be connected to a machine through serial port in
the network and clients would use COM to acess this information.
I have an CNMEA class that provides means to read NMEA data from port. I use
it in programs like this:
CNMEA *pNmea = new CNMEA;
NMEA_BOD Bod;
SYSTEMTIME stTime;
pNmea->Init("COM1",4800); //Opens port and set baudrate
while(!Finish)
{
pNmea->ReadPort();//read data from port to buffer
pNmea->ParseLine();//parse every desired data from buffer to holder of
NMEA protocol sentences
pNmea->GetBOD(&Bod,&stTime);// read BOD NMEA sentence data
}
I was thinking of using a TThread pointer that wrapps a CNMEA.
class CNMEAThread:public TThread
{
protected:
CNMEA *pNmea;
NMEA_RMC Rmc;
SYSTEMTIME RmcTag;
public:
DOUBLE LatLon[2];
void __fastcall Execute();
}
CNMEAThread::CNMEAThread()
{
pNmea = new CNMEA;
pNmea->Init("COM1",4800);
}
CNMEAThread::~CNMEAThread()
CNMEAThread::Execute()
{
while(!Terminated)
{
pNmea->ReadPort();
pNmea->ParseLine();
if(pNmea->GetRmc(Rmc,&RmcTag))//returns true if there was a Rmc
sentence in data buffer
{
LatLon[0] = Rmc.Posicao.Latitude;
LatLon[1] = Rmc.Posicao.Longitude;
}
}
}
I'm planning to use an static pointer to a CNMEAThread pointer (CNMEAThread
*pThread) to provide data to the interface.
Questions:
Am I going to commit code suicide doing this kind of thinking?
How do I force my server to be instaciated only once in a single machine?
How do I force my static pThread to be created only at the first object
instance and destroyed when the last instance is closed?
Thank you all in advance,
Marcus Monteiro