GPS and web service confilict

  • Thread starter Thread starter adal
  • Start date Start date
A

adal

I have an app read location from external GPS and send request to a
webservice server using lat and longti as an input.

I use SerialPort class(c#, CF2.0) to read data from GPS, and it works
fine. However, after my serial port is opened. My webservice request
is always failed and I got an exception "Unable to connect to the
remote server". Here is my code:

private void Connect_Click(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
_serialPort = new SerialPort(ports[0]);
_serialPort.ReadTimeout = 5000;
_continue = true;
_serialPort.Open();

Thread readThread = new Thread(SerialRead);
readThread.Start();
}

private void SerialRead()
{
while (_continue)
{
string Sentence = _serialPort.ReadLine();
Thread.Sleep(1000);
}
}

private void Disconnect_Click(object sender, EventArgs e)
{
_continue = false;
_serialPort.Close();
}

private void Webservice_Click(object sender, EventArgs e)
{
try
{
WebReference.ContentControlService webService = new
GPSTest.WebReference.ContentControlService();
webService.contentSearch("xxxx");
}
catch (Exception pe)
{
MessageBox.Show(pe.Message);
}
}

Thank you very much in advance for your sugession and hits.

Adal
 
Hi,

Very strange, try to use nativ code to access your serial port.

BR

Fabien Decret (Device Application Development MVP)
Windows Embedded Consultant

ADENEO (ADESET)http://www.adeneo.adetelgroup.com/|http://fabdecret.blogspot.com/

I have an app read location from external GPS and send request to a
webservice server using lat and longti as an input.
I use SerialPort class(c#, CF2.0) to read data from GPS, and it works
fine. However, after my serial port is opened. My webservice request
is always failed and I got an exception "Unable to connect to the
remote server". Here is my code:
        private void Connect_Click(object sender, EventArgs e)
        {
            string[] ports = SerialPort.GetPortNames();
            _serialPort = new SerialPort(ports[0]);
            _serialPort.ReadTimeout = 5000;
            _continue = true;
            _serialPort.Open();
            Thread readThread = new Thread(SerialRead);
            readThread.Start();
         }
        private void SerialRead()
        {
            while (_continue)
            {
                string Sentence = _serialPort.ReadLine();
                Thread.Sleep(1000);
            }
        }
        private void Disconnect_Click(object sender, EventArgs e)
        {
            _continue = false;
            _serialPort.Close();
        }
         private void Webservice_Click(object sender, EventArgs e)
        {
            try
            {
                WebReference.ContentControlService webService = new
GPSTest.WebReference.ContentControlService();
                 webService.contentSearch("xxxx");
            }
            catch (Exception pe)
            {
                MessageBox.Show(pe.Message);
            }
        }
Thank you very much in advance for your sugession and hits.
Adal- Hide quoted text -

- Show quoted text -

Thank you for your reply, Fabien. This code works under windows.
 
Hi,

Why use a thread for reads? The SerialPort object already creates a
background read thread. Thus, a second thread is frosting with no sugar.
Just use the DataAvailable event - receive events are generated in the
SerialPort background thread context.

My suggestion, "the simpler code, the better."

Perhaps your web service problems will be resolved.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
Hi,

Very strange, try to use nativ code to access your serial port.

BR

Fabien Decret (Device Application Development MVP)
Windows Embedded Consultant

ADENEO (ADESET)http://www.adeneo.adetelgroup.com/|http://fabdecret.blogspot.com/

I have an app read location from external GPS and send request to a
webservice server using lat and longti as an input.
I use SerialPort class(c#, CF2.0) to read data from GPS, and it works
fine. However, after my serial port is opened. My webservice request
is always failed and I got an exception "Unable to connect to the
remote server". Here is my code:
        private void Connect_Click(object sender, EventArgs e)
        {
            string[] ports = SerialPort.GetPortNames();
            _serialPort = new SerialPort(ports[0]);
            _serialPort.ReadTimeout = 5000;
            _continue = true;
            _serialPort.Open();
            Thread readThread = new Thread(SerialRead);
            readThread.Start();
         }
        private void SerialRead()
        {
            while (_continue)
            {
                string Sentence = _serialPort.ReadLine();
                Thread.Sleep(1000);
            }
        }
        private void Disconnect_Click(object sender, EventArgs e)
        {
            _continue = false;
            _serialPort.Close();
        }
         private void Webservice_Click(object sender, EventArgs e)
        {
            try
            {
                WebReference.ContentControlService webService = new
GPSTest.WebReference.ContentControlService();
                 webService.contentSearch("xxxx");
            }
            catch (Exception pe)
            {
                MessageBox.Show(pe.Message);
            }
        }
Thank you very much in advance for your sugession and hits.
Adal- Hide quoted text -

- Show quoted text -

Yes native code works. SerialPort class for cf has defect. Thanks
 
Back
Top