Note that there are some explanatory texts on larger screens.

plurals
  1. PORead information from a serial port in VB.net 2008
    text
    copied!<p>I'm at a brick wall!</p> <p>I have a teperature PCB that reports the temp back via serial port.</p> <p>I can open Hyper Terminal and receive all the data I want - so I know the unit is working... but I want to create a VB app so I can use the data received.</p> <p>When I run the program I get this error:</p> <pre><code>System.TimeoutException: The operation has timed out. at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count, Int32 timeout) at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count) at System.IO.Ports.SerialPort.InternalRead(Char[] buffer, Int32 offset, Int32 count, Int32 timeout, Boolean countMultiByteCharsAsOne) at System.IO.Ports.SerialPort.ReadTo(String value) at System.IO.Ports.SerialPort.ReadLine() at Temperature.Form1.ReadFromCom() in C:\Documents and Settings\asamuel\Desktop\VB Project Sollutions\Temperature2\Temperature\Form1.vb:line 43 </code></pre> <p>Can someone PLEASE help me! I'm going mad!</p> <p>In hyper terminal the data comes through like this:</p> <pre><code>R V1.0 2002-01-06 20:37:37 C 1 0027.00 2 0027.00 3 0027.06 4 0027.18 1 0027.00 2 0027.00 3 0027.06 4 0027.18 1 0027.00 2 0027.06 </code></pre> <p>My VB app code looks like this:</p> <pre><code>Imports System Imports System.IO.Ports Imports System.Threading Public Class Form1 Dim SerialPort1 As New SerialPort Dim readThread As Thread = New Thread(AddressOf ReadFromCom) Dim abortThread As Boolean Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Button1.Text Is "Start Capture" Then Try abortThread = False SerialPort1.Open() readThread.Start() Button1.Text = "Stop Capture" Catch ex As Exception MsgBox("Another program is already using COM1." &amp; vbCrLf &amp; vbCrLf &amp; _ "Please try again later", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "COM1 Not Available") End Try ElseIf Button1.Text Is "Stop Capture" Then abortThread = True Button1.Text = "Start Capture" End If End Sub Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With SerialPort1 .PortName = "COM1" .BaudRate = 2400 .Parity = Parity.None .DataBits = 8 .StopBits = 1 .ReadTimeout = 500 End With End Sub Public Sub ReadFromCom() While abortThread = False Try Dim message As String = SerialPort1.ReadLine updateStatus("Received: " &amp; message) Catch ex As TimeoutException updateStatus(ex.ToString) End Try End While End Sub Public Delegate Sub updateStatusDelegate(ByVal newStatus As String) Public Sub updateStatus(ByVal newStatus As String) If Me.InvokeRequired Then Dim upbd As New updateStatusDelegate(AddressOf updateStatus) Me.Invoke(upbd, New Object() {newStatus}) Else TextBox1.Text = newStatus &amp; vbCrLf &amp; vbCrLf &amp; TextBox1.Text End If End Sub End Class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload