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

Re: GPS and web service confilict by Fabien

Fabien
Thu May 01 11:27:33 CDT 2008

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/


On 1 mai, 18:19, adal <adcoop...@gmail.com> wrote:
> 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:
>
> =A0 =A0 =A0 =A0 private void Connect_Click(object sender, EventArgs e)
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 string[] ports =3D SerialPort.GetPortNames();
> =A0 =A0 =A0 =A0 =A0 =A0 _serialPort =3D new SerialPort(ports[0]);
> =A0 =A0 =A0 =A0 =A0 =A0 _serialPort.ReadTimeout =3D 5000;
> =A0 =A0 =A0 =A0 =A0 =A0 _continue =3D true;
> =A0 =A0 =A0 =A0 =A0 =A0 _serialPort.Open();
>
> =A0 =A0 =A0 =A0 =A0 =A0 Thread readThread =3D new Thread(SerialRead);
> =A0 =A0 =A0 =A0 =A0 =A0 readThread.Start();
> =A0 =A0 =A0 =A0 =A0}
>
> =A0 =A0 =A0 =A0 private void SerialRead()
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 while (_continue)
> =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string Sentence =3D _serialPort.ReadLine()=
;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Thread.Sleep(1000);
> =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 }
>
> =A0 =A0 =A0 =A0 private void Disconnect_Click(object sender, EventArgs e)
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 _continue =3D false;
> =A0 =A0 =A0 =A0 =A0 =A0 _serialPort.Close();
> =A0 =A0 =A0 =A0 }
>
> =A0 =A0 =A0 =A0 =A0private void Webservice_Click(object sender, EventArgs =
e)
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 try
> =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 WebReference.ContentControlService webServ=
ice =3D new
> GPSTest.WebReference.ContentControlService();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0webService.contentSearch("xxxx");
> =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 catch (Exception pe)
> =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 MessageBox.Show(pe.Message);
> =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 }
>
> Thank you very much in advance for your sugession and hits.
>
> Adal


Re: GPS and web service confilict by adal

adal
Thu May 01 11:51:19 CDT 2008

On May 1, 11:27=A0am, Fabien <fab_00_2...@msn.com> wrote:
> 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.blogspo=
t.com/
>
> On 1 mai, 18:19, adal <adcoop...@gmail.com> wrote:
>
>
>
> > 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:
>
> > =A0 =A0 =A0 =A0 private void Connect_Click(object sender, EventArgs e)
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 string[] ports =3D SerialPort.GetPortNames();
> > =A0 =A0 =A0 =A0 =A0 =A0 _serialPort =3D new SerialPort(ports[0]);
> > =A0 =A0 =A0 =A0 =A0 =A0 _serialPort.ReadTimeout =3D 5000;
> > =A0 =A0 =A0 =A0 =A0 =A0 _continue =3D true;
> > =A0 =A0 =A0 =A0 =A0 =A0 _serialPort.Open();
>
> > =A0 =A0 =A0 =A0 =A0 =A0 Thread readThread =3D new Thread(SerialRead);
> > =A0 =A0 =A0 =A0 =A0 =A0 readThread.Start();
> > =A0 =A0 =A0 =A0 =A0}
>
> > =A0 =A0 =A0 =A0 private void SerialRead()
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 while (_continue)
> > =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string Sentence =3D _serialPort.ReadLine=
();
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Thread.Sleep(1000);
> > =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 }
>
> > =A0 =A0 =A0 =A0 private void Disconnect_Click(object sender, EventArgs e=
)
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 _continue =3D false;
> > =A0 =A0 =A0 =A0 =A0 =A0 _serialPort.Close();
> > =A0 =A0 =A0 =A0 }
>
> > =A0 =A0 =A0 =A0 =A0private void Webservice_Click(object sender, EventArg=
s e)
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 try
> > =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 WebReference.ContentControlService webSe=
rvice =3D new
> > GPSTest.WebReference.ContentControlService();
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0webService.contentSearch("xxxx");
> > =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 =A0 =A0 catch (Exception pe)
> > =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 MessageBox.Show(pe.Message);
> > =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 }
>
> > 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.

Re: GPS and web service confilict by Dick

Dick
Thu May 01 11:58:32 CDT 2008

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.



Re: GPS and web service confilict by adal

adal
Thu May 01 15:45:32 CDT 2008

On May 1, 11:27=A0am, Fabien <fab_00_2...@msn.com> wrote:
> 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.blogspo=
t.com/
>
> On 1 mai, 18:19, adal <adcoop...@gmail.com> wrote:
>
>
>
> > 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:
>
> > =A0 =A0 =A0 =A0 private void Connect_Click(object sender, EventArgs e)
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 string[] ports =3D SerialPort.GetPortNames();
> > =A0 =A0 =A0 =A0 =A0 =A0 _serialPort =3D new SerialPort(ports[0]);
> > =A0 =A0 =A0 =A0 =A0 =A0 _serialPort.ReadTimeout =3D 5000;
> > =A0 =A0 =A0 =A0 =A0 =A0 _continue =3D true;
> > =A0 =A0 =A0 =A0 =A0 =A0 _serialPort.Open();
>
> > =A0 =A0 =A0 =A0 =A0 =A0 Thread readThread =3D new Thread(SerialRead);
> > =A0 =A0 =A0 =A0 =A0 =A0 readThread.Start();
> > =A0 =A0 =A0 =A0 =A0}
>
> > =A0 =A0 =A0 =A0 private void SerialRead()
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 while (_continue)
> > =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string Sentence =3D _serialPort.ReadLine=
();
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Thread.Sleep(1000);
> > =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 }
>
> > =A0 =A0 =A0 =A0 private void Disconnect_Click(object sender, EventArgs e=
)
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 _continue =3D false;
> > =A0 =A0 =A0 =A0 =A0 =A0 _serialPort.Close();
> > =A0 =A0 =A0 =A0 }
>
> > =A0 =A0 =A0 =A0 =A0private void Webservice_Click(object sender, EventArg=
s e)
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 try
> > =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 WebReference.ContentControlService webSe=
rvice =3D new
> > GPSTest.WebReference.ContentControlService();
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0webService.contentSearch("xxxx");
> > =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 =A0 =A0 catch (Exception pe)
> > =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 MessageBox.Show(pe.Message);
> > =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 }
>
> > 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