2 Replies - 16520 Views - Last Post: 06 September 2007 - 09:27 PM Rate Topic: -----

#1 xda  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-September 07

read data from serial port

Post icon  Posted 05 September 2007 - 07:18 AM

Imports System
Imports System.IO.Ports

Public Class Form2

	Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		Try

			SerialPort1 = New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One)

			SerialPort1.Open()
		Catch ex As System.IO.IOException
			TextBox2.Text = "IO exception " + ex.Message
		End Try
	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Try

			TextBox1.Text = ""
			TextBox1.Text = SerialPort1.ReadChar()
		Catch ex As System.IO.IOException
			TextBox2.Text = ex.Message
		End Try
	End Sub
End Class



Hi all, I'm trying to read data from the serial port of the pocket pc phone but i have problem reading it. I get stuck/ freeze when i click the Button1 button.

My pocket pc phone does not have a physical serial port on it. It is connected with a designated serial cable (1 end to connect with the pocket pc, the other end is d male 9-pin serial port) and the serial port from the designated serial cable is attached with a null modem to a microcontroller.

Is there any error i make in my coding? Urgent help please..

Is This A Good Question/Topic? 0
  • +

Replies To: read data from serial port

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: read data from serial port

Posted 05 September 2007 - 12:21 PM

Well I can't duplicate what you are doing because of your setup, so I can't tell you for sure what is going on but a few things I noticed is that your ReadChar is Synchronus meaning it may end up blocking (freeze while waiting for input). So what I would recommend is putting that on a separate thread. Secondly I would make sure that a timeout is specified so that after some period of time, you will get a timeout.

Now once you open up the port connection, are you putting any data onto the port from the pocket pc? I mean, does it have anything to read on the line already when it attempts to ReadChar?

Just a few ideas I am throwing out there. :)
Was This Post Helpful? 0
  • +
  • -

#3 xda  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-September 07

Re: read data from serial port

Posted 06 September 2007 - 09:27 PM

View PostMartyr2, on 5 Sep, 2007 - 12:21 PM, said:

Well I can't duplicate what you are doing because of your setup, so I can't tell you for sure what is going on but a few things I noticed is that your ReadChar is Synchronus meaning it may end up blocking (freeze while waiting for input). So what I would recommend is putting that on a separate thread. Secondly I would make sure that a timeout is specified so that after some period of time, you will get a timeout.

Now once you open up the port connection, are you putting any data onto the port from the pocket pc? I mean, does it have anything to read on the line already when it attempts to ReadChar?

Just a few ideas I am throwing out there. :)



Hi Martyr2 and ALL, I noticed that whenever I tried to read or send data to desktop using hyperterminal, I had an error message saying "An error message cannot be displayed because an optional resource cannot be found". My PDA phone is installed with microsoft .NET CF 2.0. How could I resolve this error?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1