Re: serialPort receive problem
- From: "James Hahn" <jhahn@xxxxxxxxx>
- Date: Wed, 17 Jun 2009 18:39:34 +1000
The ReadExisting method will return whatever data is available at the serial port. If nothing is displayed then you should assume that nothing was available. That would be expected, as the serial port data could not have been transmitted, and a response received, in the time that you have allowed between the Write command and the ReadExisting call.
Data will be available at the serial port if the BytesToRead function returns a positive value. You should call ReadExisting only after confirming that there are bytes to be read, or following a DataReceived event.
"tzhumi" <fren4uu@xxxxxxxxxxxxxx> wrote in message news:f732599c-4d3e-48bb-9888-678782754a2a@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,
I have a class that creates an instance of the seril Port.
Every thing works fine except whenever I receive data I cannot display
the
recieved data. I get no errors but the recived data seems to be empty.
when I try to display it in a text box nothing happens.
I have socket stuff in the same class and it's recieve callbacks work
just
fine and displays just fine.
Here is my code:
Sub OpenComPort()
Try
If Not SerialPort1.IsOpen Then
SerialPort1.PortName = cmbPorts.SelectedItem.ToString
If cmbBitRate.SelectedIndex > 0 Then
SerialPort1.BaudRate = CInt
(cmbBitRate.SelectedItem)
End If
SerialPort1.Parity = Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Open()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub btnOn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOn.Click
SendCommand("I2" + eot)
End Sub
Private Sub SendCommand(ByVal command As String)
Dim response As String = ""
SerialPort1.Write(command)
response = SerialPort1.ReadExisting
textbox1.text=response
End sub
When I send the command the controller responds to the command and it
should return the response by some ascii characters. But I am unable
to display the response from it...Thank you for any help
.
- References:
- serialPort receive problem
- From: tzhumi
- serialPort receive problem
- Prev by Date: Big problem with a selfmade dialog
- Next by Date: Re: serialPort receive problem
- Previous by thread: serialPort receive problem
- Next by thread: Re: serialPort receive problem
- Index(es):
Relevant Pages
|