Bwdev

Bwdev

  • NA
  • 3
  • 0

SerialPort.ReadLine throwing IO Operation aborted error

Oct 8 2007 10:57 AM
Hello,

First, I'm not a C# developer.  I do primarily PHP but need to access a gps device so was trying to get some C# code to work.  Basically I have code that is run on the button click of a form.  I have a gps plugged in sitting on COM3.  The gps came with a small utility and that seems to at least get some data (I can't actually get a signal from where I am but the utility seems to get something coming across).  When I run the code and click the button, I get the following error on opening the serial port.

The I/O operation has been aborted because of either a thread exit or an application request.


Here is my code:
             SerialPort Serial = new SerialPort("COM3");
            Serial.BaudRate = 4800;
            Serial.Open();
            string gps_data = Serial.ReadLine();
            string uri = "http://mysite.com/?gps=" + gps_data;
            Serial.Close();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();


Should I be using Read and not read line?  If so, how?
Thanks!

Answers (1)