serial port will not trigger data received event.

Hello All,

I have this problem that is driving me crazy. First I need to say that the test bed is a virtual null modem and another piece of software I have written that sends data serially. I am able to get this to work flawlessly using MSCOMM, but I want to figure out why it will not work with VB2005 express Serial port. Here is the serial port code.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'MSComm1.PortOpen = True

'MSComm1.RThreshold = 1

If SerialPort1.IsOpen = False Then SerialPort1.Open()

If RadioButton1.Checked = True Then warn_charge()

If RadioButton2.Checked = True Then warn_discharge()

'My.Computer.Audio.Play("C:\Program Files\Windows NT\Pinball\sound28.wav")

End Sub

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

datain = ReceiveSerialData()

data_disect()

End Sub

Function ReceiveSerialData() As String

' Receive strings from a serial port.

Dim returnStr As String = ""

Using com16 As IO.Ports.SerialPort = _

My.Computer.Ports.OpenSerialPort("COM16")

Do

Dim Incoming As String = com16.ReadLine()

If Incoming Is Nothing Then

Exit Do

Else

returnStr &= Incoming & vbCrLf

End If

Loop

End Using

Return returnStr

End Function

Com 16 Is the right comm port. I have the baud rate set at 9600 on both ends. It just won't trigger the data received event.

Any Ideas

Thanks,

Todd



Answer this question

serial port will not trigger data received event.

  • DeliDaba

    Thanks Ed,

    Yes I did try enabling the dtr line. It just doesn't make sense. The only thought I have is that VB2005 'serial port' just doesn't like Virtual Null ports. I haven't tried this theory out yet with an actual hard cable, but from everything I have read the code should be working,so, It has to be hardware.

    Any other ideas


  • Sonia Pignorel

    Have you tried enabling DTR line

    Ed



  • serial port will not trigger data received event.