hi,
i am developing a GUI for my project through MFC using visual basic 2008. down below is a part my code that i have written. the purpose of this code is to get GPS data (using marshallsoft GPS component) from serial port, display, and keep on updating the data. i am facing problem using While (1) loop to update GPS data continuously. implementing while loop (as shown in my code) causes the dialog box disappear, although mydialog.exe is shown running at background in the task bar.
any kind of help is appreciated.
thanks
//Variables CTextFile
int Code;
int LinesRX;
char Temp[256];
int decimal, precision = 12, sign;
//CString sDataBuffer(DataBuffer);
//LPCTSTR lpszDataBuffer = sDataBuffer;
CString str, Lat, Long, Alt, Azi, Dist;
CStringArray sensorval;
double Latgcs, Longcs, Altgcs, Compgcs;
double Distance, Azimuth, Angle;
double Latitude, Longitude, Altitude;
CTextFile Sensor;
BOOL res;
str=_T("E:\\sensorfile.txt");
Code = mgcAttach(MGC_KEY_CODE); // attach MGC component
if (mgcOpen(MGC_COM2)== 0)
SetDlgItemText(IDC_GPSPORT, (LPCTSTR) L"OK");
else
SetDlgItemText(IDC_GPSPORT, (LPCTSTR) L"Port Error");
res = Sensor.ReadTextFile(str, sensorval);
Latgcs = wcstod(sensorval[0], NULL);
SetDlgItemText(IDC_LATITUDE, sensorval[0]);
Longcs = wcstod(sensorval[1], NULL);
SetDlgItemText(IDC_LONGITUDE, sensorval[1]);
Altgcs = wcstod(sensorval[2], NULL);
SetDlgItemText(IDC_ALTITUDE, sensorval[2]);
Compgcs = wcstod(sensorval[3], NULL);
SetDlgItemText(IDC_NORTH, sensorval[3]);
while (1)
{
Code = mgcSetInteger(MGC_SET_SENTENCE_TYPE, MGC_SENTENCE_GPGGA);
mgcLockData(1);
Latitude = mgcLatitude();
Lat = _ecvt( Latitude, precision, &decimal, &sign );
SetDlgItemText(IDC_ACLAT, Lat);
Code = mgcGetData(GPGGA_LONGITUDE,(LPSTR)DataBuffer);
Longitude = atof (DataBuffer);
Long = _ecvt( Longitude, precision, &decimal, &sign );
SetDlgItemText(IDC_ACLONG, Long);
Code = mgcGetData(GPGGA_ALTITUDE,(LPSTR)DataBuffer);
Altitude = atof(DataBuffer);
Alt = _ecvt( Altitude, precision, &decimal, &sign );
SetDlgItemText(IDC_ACALT, Alt);
Distance = mgcGreatCircle(IDC_LATITUDE, IDC_LONGITUDE, IDC_ACLAT, IDC_ACLONG);
Dist = _ecvt( Distance, precision, &decimal, &sign );
SetDlgItemText(IDC_ACDIST, Dist);
Angle = mgcBearing (IDC_LATITUDE, IDC_LONGITUDE, IDC_ACLAT, IDC_ACLONG);
Azimuth = Angle / 60000.0;
Azi = _ecvt( Azimuth, precision, &decimal, &sign );
SetDlgItemText(IDC_ACBEAR, Azi);
mgcLockData(0);
}
return TRUE; // return TRUE unless you set the focus to a control
}