Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

Increasing com port reading efficiency

$
0
0
So I just completed my first test of reading data coming through a com port (usb gps, using usb->com driver). However, I'd like to pick some minds about the actual process that may be better than what I am doing.

When I connect to my com port (hardcoded for now), I hook the data received event handler. Inside this method, I did a .ReadExisting() with output going to a listbox. I noticed that the com port is sending data very fast which is awesome and expected. I noticed that the data is not sent in complete lines.

I then made a class level stringbuilder and kept appending the .ReadExisting() strings to the stringbuilder. After each append, I attempted to check the new text of the stringbuilder for "GPGGA" and removed it. If already removed once, and found "GPGGA" again, we have a complete line. I realize this is not a very correct way to test for a complete line... After a complete line is found, I parse the data into a latitude/longitude (with some code help from codeproject). The lat/long code I'm using has splits, converstions to doubles, and more conversions back to strings...

After appending, testing, and parsing, I seem to get results about 1/sec. I know the gps puck sends complete lines more often than that. I also know that by setting a breakpoint after a while, the stringbuilder is appending faster than it's tested/parsed.

I've read a couple places that a good way is to read the incoming received data into a byte buffer and test that, having a separate method to actually do the parsing. I don't really want to have a thread constantly running just waiting to parse data. However, a constantly running thread to do the testing and parsing might not be a bad idea.

The only problem, I don't know how to work with bytes, or the .Read() with arguments for a byte,count,etc. Does anyone have any good leeway for a more efficient way of going about this?

Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>