|
-
Feb 15th, 2009, 07:20 PM
#1
Thread Starter
New Member
[RESOLVED] Program hangs when closing serial port
I have a VB.Net 2008 app that I have converted from VB6 which reads data from a weight scale connected to a serial port. I am able to read the received data and display it on the screen, but when I go to Stop the reading and attempt to close the serial port, the app hangs.
Private Delegate Sub ShowWeight(ByVal tWeight As String)
Private Sub comScale_DataReceived(ByVal sender As Object, ByVal e
As System.IO.Ports.SerialDataReceivedEventArgs) Handles
comScale.DataReceived
ReadWeight(comScale.ReadLine())
End Sub
Private Sub ReadWeight(ByVal tWeight As String)
On Error GoTo ErrScale
If TextBox1.InvokeRequired Then
TextBox1.Invoke(New ShowWeight(AddressOf ReadWeight), tWeight)
Else
TextBox1.Text = tWeight
End If
strInput = TextBox1.Text
End Sub
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command1.Click
Select Case Command1(Index).Tag
Case "Stop"
RemoveHandler comScale.DataReceived, AddressOf
comScale_DataReceived
If comScale.IsOpen Then comScale.Close() 'HANGS HERE
Case "Start"
If comScale.IsOpen Then comScale.Close()
Call Get_ComPort() 'Set Port Properties
AddHandler comScale.DataReceived, AddressOf
comScale_DataReceived 'add handler
comScale.Open()
End Select
End Sub
Many Thanks for any help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|