Re: serialPort receive problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

.



Relevant Pages

  • Re: How To Change default error messages
    ... is it possible to selectively display custom error messages for the ... Private Sub Save_Vehicle_Click(DataErr As Integer, Response As Integer) ... Response = acDataErrDisplay ' Display Default message ...
    (microsoft.public.access.forms)
  • Re: How To Change default error messages
    ... is it possible to selectively display custom error messages for the ... Private Sub Save_Vehicle_Click(DataErr As Integer, Response As Integer) ... Response = acDataErrDisplay ' Display Default message ...
    (microsoft.public.access.forms)
  • Re: Generating a new Record
    ... You can use this when you want to display a custom message to the user. ... user wanted to save the new entry. ... If the response is Yes, ... Response argument to acDataErrContinue. ...
    (microsoft.public.access.gettingstarted)
  • Re: Generating a new Record
    ... You can use this when you want to display a custom message to the ... user wanted to save the new entry. ... If the response is Yes, ... Response argument to acDataErrContinue. ...
    (microsoft.public.access.gettingstarted)
  • Re: How To Change default error messages
    ... is it possible to selectively display custom error messages for the ... Private Sub Save_Vehicle_Click(DataErr As Integer, Response As Integer) ... > Response = acDataErrContinue ' Don't display the default message ...
    (microsoft.public.access.forms)