Hello Everyone.
I'll start off by saying i'm pretty new to c# so its probably me not finding the right code.
I am interfacing some harware with my pc and use c# to handle the data from them.
I have a GPS which I have plugged in to a usb port. The GPS talks NMEA sentences. I used to be able to simply open a connection to the device and the nmea sentences started flowing in. My problem is, how on earth do I do this in c#?
Is there a way like opendevice(byterate, port) or am I in for some late nights?
Help is much appreciated.
Thanks.
Loading
Dr SpackPosted Dec 10, 2007, 8:19 AM
when your gps device creates a COM Port (I am pretty sure
that it can do it) then you can use the following code
snippets to start with:
using System.IO.Ports;
// ...
SerialPort port = new SerialPort(
port.DataReceived += new SerialDataReceivedEventHandler( port_DataReceived );
port.Open();
//...
// Cleanup
port.DataReceived -= new SerialDataReceivedEventHandler( port_DataReceived );
port.Close();
//...
private void port_DataReceived( object sender, SerialDataReceivedEventArgs e )
{
string nmea;
try
{
if( _port.BytesToRead == 0 )
return;
nmea = _port.ReadExisting();
System.Console.Write( nmea );
}
catch( Exception ex )
{
handle Exception or not!?
}
}
You just have to figure out the parameters
Good luck.