C # serial communication with u-blox gps

I have a GPS from u-blox.com with a USB connection and a driver. The driver installs the virtual COM port that appears when a USB connection is made. Using the hyperterminal, I can monitor the flow of data from the GPS.

Then I need data in my program, not so simple ...

I implemented some methods using the serialPort class for reading from GPS, but was unsuccessful. I programmed several readers and writers of serial devices before in C #, but that stops me.

As an example, simple code in simpleSerial will not give you anything unless you unplug the USB port and replace it.

I tried reading it with Matlab, which works great, but since the rest of my program, which needs GPS data, is in C #, this does not completely fix the problem.

Are there some high level C # things in the serialPort class that I can work around? Or are there any known issues with reading USB serial ports that I believe works like my GPS?

+4
source share
9 answers

If you can communicate with GPS using HyperTerminal, then there is basically no reason why you shouldn't be in C #. Are you sure that you have correctly configured the serial port, in particular, data transfer rate, data bit, stop bits, parity and flow control?

You can use SysInternals PortMon to view low-level I / O and compare how HyperTerminal and your C # program configure each Serial Port. Perhaps this will provide some useful information.

+1
source

I have successfully used the SerialPort class in .Net 2 also with gps on a virtual machine. Your virtual comport driver seems to be a bit disabled. If you cannot find a newer driver, I would suggest you call WinAPI functions to read the serial port.

Look at this code, for example: http://www.codeproject.com/KB/system/SerialPortComm.aspx

+1
source

Get it from u-blox support.

The following hex command will force the watchdog to reset on the GPS module.

B5 62 06 04 04 00 00 00 00 00 0E 64

this is a low level command for ARM7 uP in GPS It works with all u-blox GPS receivers.

byte[] data = new byte[]{0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x64}; sp.Write(data, 0, data.Length); 

This works for me.

+1
source

Not sure if this is the problem you are facing.

I noticed that if RX_FLAG is used with the SetCommMask API, GetOverlappedResult does not seem to return after the first WaitCommEvent. It looks like the API expects something to happen until the com mask is reset (at least this is what I observed). However, there is still some data received if you go and read the port, after which the device no longer responds. In this case, you will need to disconnect and reinstall the device so that it answers again.

However, if RX_CHAR is used instead, GetOverLappedResult returns with the correct status, and the device is working properly.

We hope this information helps.

0
source

The problem is that an error occurs in the USB serial port drivers or in Microsoft's implementation of their SerialPort classes. I had the same problems with Serial USB adapters using chips created by Prolific (and therefore Prolific drivers).

I could not narrow down the problem exactly, but now that the .NET Framework source code is available, I will try to go into SerialPort and see what the problem is.

A workaround is to use a different serial access class. Before .Net 2.0, I wrote the SerialStream class, and for some reason, it works great with the same USB serial adapters that the SerialPort class will not work with.

You can grab my class at http://www.6bit.com/download/SerialStream.zip I have provided the same code to some other GPS programmers over the years, and they have also had success with it.

0
source

I used the following code to communicate via USB with Arduino, it sends and receives bytes from Arduino. It just doesn't talk to GPS, but hopefully it helps!

  public static byte ReadByte() { byte byteRead = new byte(); SerialPort port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One); port.Open(); int byteValue = port.ReadByte(); port.Close(); byteRead = Convert.ToByte(byteValue); return byteRead; } public static void SendByte(byte packet) { SerialPort port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One); port.Open(); byte[] writeByte = new byte[1]; writeByte[0] = packet; port.Write(writeByte, 0, 1); port.Close(); } 
0
source

It turned out the same problem with U-Blox GPS, but she managed to solve this problem by turning on the DTR and RTS properties. Now I can read NMEA sentences perfectly. One of the problems that I discovered is that I still have to remove and replace my GPS with a USB port from time to time. Hope this helps.

0
source

I ran into a similar problem in the application that I wrote, and the problem turned out to be that we tried SerialPort.WriteLine , which sends \r\n to end the line when I really just needed to send \n . When I switched to SerialPort.Write with \n added to the end, everything worked as in HyperTerminal.

-1
source

Try using handshake / flow control. They are also useful when using the usb-serial adapter.

-1
source

All Articles