C++ serial comms to Reach RS

I’ve gotten a piece of generic serial reading code from the web, and I’ve been testing it reading from the usb port. My computer shows it’s in com3. I actually had a stream of empty data coming from it for a while, which showed through several readings the letters gpgss or something like that, then I don’t know what went down besides power for a while, and now I get no signals from the gps at all.

The code is below:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
int gpsData()
{
int ch;
char buffer[1];
HANDLE file;
COMMTIMEOUTS timeouts;
DWORD read, written;
DCB port;
HANDLE keyboard = GetStdHandle(STD_INPUT_HANDLE);
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD mode;
char port_name[128] = “\\.\COM3”;
char init[] = “”; // e.g., “ATZ” to completely reset a modem.
std::cout << “gps \n”;
file = CreateFile(port_name,GENERIC_READ || GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);

if (INVALID_HANDLE_VALUE == file) {
	system_error("opening file");
	return 1;
}

// get the current DCB, and adjust a few bits to our liking.
memset(&port, 0, sizeof(port));
port.DCBlength = sizeof(port);
if (!GetCommState(file, &port))
	system_error("getting comm state");
if (!BuildCommDCB("baud=19200 parity=n data=8 stop=1", &port))
	system_error("building comm DCB");
if (!SetCommState(file, &port))
	system_error("adjusting port settings");

// set short timeouts on the comm port.
timeouts.ReadIntervalTimeout = 1;
timeouts.ReadTotalTimeoutMultiplier = 1;
timeouts.ReadTotalTimeoutConstant = 1;
timeouts.WriteTotalTimeoutMultiplier = 1;
timeouts.WriteTotalTimeoutConstant = 1;
if (!SetCommTimeouts(file, &timeouts))
{
	system_error("setting port time-outs.");
}
if (!EscapeCommFunction(file, CLRDTR))
	system_error("clearing DTR");
Sleep(200);
if (!EscapeCommFunction(file, SETDTR))
	system_error("setting DTR");
std::string s = "";
std::string latty;
std::string longy;
int GPGLL = 0;
do
{
	// check for data on port and display it on screen.
	ReadFile(file, buffer, sizeof(buffer), &read, NULL);
	if (read)
	{
		std::stringstream ss;
		ss << buffer[0];//takes first char of buffer and puts it in stringstream
		ss >> s;
		std::string s;
		switch (GPGLL)
		{
		case 0:
			if (s == "G")
			{
				GPGLL += 1;
			}
			else
			{
				GPGLL = 0;
			}
			break;
		case 1:
			if (s == "P")
			{
				GPGLL += 1;
			}
			else
			{
				GPGLL = 0;
				if (s == "G")
				{
					GPGLL += 1;
				}
			}
			break;
		case 2:
			if (s == "G")
			{
				GPGLL += 1;
			}
			else
			{
				GPGLL = 0;
			}
			break;
		case 3:
			if (s == "L")
			{
				GPGLL += 1;
			}
			else
			{
				GPGLL = 0;
				if (s == "G")
				{
					GPGLL += 1;
				}
			}
			break;
		case 4:
			if (s == "L")
			{
				GPGLL += 1;
			}
			else
			{
				GPGLL = 0;
				if (s == "G")
				{
					GPGLL += 1;
				}
			}
			break;
		case 5:
			if ((s == "N") || (s == "S"))
			{
				if (s != "N")
				{
					std::string neg = "-";
					latty = neg + latty;
				}
				GPGLL += 1;
			}
			else
			{
				latty = latty + s;
			}
			break;
		default:
			if ((s == "W") || (s == "E"))
			{
				if (s != "W")
				{
					std::string neg = "-";
					longy = neg + longy;
				}
			}
			else
			{
				longy = longy + s;
			}
		}
		std::cout << s;
		if (GPGLL >= 6)
		{
			std::cout << "\n" << latty << "," << longy;
		}
	}
	else
	{
		std::cout << "didn't read \n";
		Sleep(1000);
	}
} while (GPGLL < 6);
CloseHandle(file);
return 0;

}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

All I ever get back is
gps
didn’t read
didn’t read
didn’t read

Any ideas on why it’s not talking anymore?
I am inside, but I always was, so I assume it can send something while still inside?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.