Bonxy
First of all, I must clarify, I haven't used VB express till now. But, on the face of it, you need to do something differently.
Code:
'--------------------------------------------------------------------------
Using comPort As SerialPort = My.Computer.Ports.OpenSerialPort("COM1", 9600)
comPort.DtrEnable = True
comPort.Write("S")
' All data transfer code goes here.
End Using
'All the above works
'------------------------------------------------------------------------
'All below does not work
Dim buffer As New StringBuilder()
Using comPort As SerialPort = My.Computer.Ports.OpenSerialPort("COM1")
Do
Dim line As String = comPort.ReadLine()
If line Is Nothing Then
Exit Do
Else
buffer.AppendLine(line)
End If
Loop
End Using
'--------------------------------------------------------------------------
The above code of yours needs to be modified so that the using block encompasses the entire code. Something like this
Code:
'--------------------------------------------------------------------------
Using comPort As SerialPort = My.Computer.Ports.OpenSerialPort("COM1", 9600)
comPort.DtrEnable = True
comPort.Write("S")
' All data transfer code goes here.
'All the above works
'------------------------------------------------------------------------
'All below does not work
Dim buffer As New StringBuilder()
Do
Dim line As String = comPort.ReadLine()
If line Is Nothing Then
Exit Do
Else
buffer.AppendLine(line)
End If
Loop
End Using
'--------------------------------------------------------------------------
I suspect that the OpenSerialPort method destroys whatever data is held in the receiver buffer uptil that time. So, you should try and see if you can open the serial port at the start of your program and close it at the end of your program. Rest of the time, just use it without the using/endusing clauses.
Hope this helps
Jerson
Bookmarks