locked
Serialport Class RRS feed

  • Question

  • I am using the Serialport Class to receive strings of text from a serial device.  However, if I write to the port, the stream freezes.  I am assuming that it need to stop the read and “prepare” the port for writing and I am not correctly doing so, however I cannot seem to find the “command string” to do so in the Visual Studio 2005 Documentation.  Can someone please point me to the right location?  Thanks.

     

    Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

    If e.EventType <> IO.Ports.SerialData.Chars Then Exit Sub

    Dim SerialData As String

    SerialData = SerialPort1.ReadExisting

    BeginInvoke(New ReadTextCallback(AddressOf Me.ReadText), SerialData)

    End Sub

    .............

    Me.SerialPort1.WriteLine(">A" & text)

     

    Tuesday, July 11, 2006 3:41 AM

Answers

  • Reading and writing a serial port is independent of each other, the class maintains two separate streams.  It is odd that WriteLine() stalls.  The only thing I can think of is that the transmit buffer is filled to capacity and waiting for the device to turn on the handshake.  Try setting SerialPort1.Handshake = Handshake.None...

    Also avoid opening and closing the port frequently, deadlocks have been reported if you do that.

    Wednesday, July 12, 2006 6:06 PM
    Moderator