PatrickIRL
Programmer
- Jun 25, 2003
- 383
I've done extensive research on this but I'm still stumped. I'm using the mscomm control to try to receive data from the serial port, albeit with no luck.
Originally I was using a weighing scales (Hampel) but couldn't get that to work so now I'm using a serial mouse I bought yesterday. Thing is, I've downloaded various OCXs and DLLs and can get them to work fine but when I try to do the same from VB, nada, zip. It seems like the OnComm event is never triggered. What the h**l am I doing wrong??
Thanks in advance, Patrick
Originally I was using a weighing scales (Hampel) but couldn't get that to work so now I'm using a serial mouse I bought yesterday. Thing is, I've downloaded various OCXs and DLLs and can get them to work fine but when I try to do the same from VB, nada, zip. It seems like the OnComm event is never triggered. What the h**l am I doing wrong??
Thanks in advance, Patrick
Code:
Option Explicit
Private Sub cmdExit_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
Unload Me
End Sub
Private Sub cmdPortClose_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
Private Sub cmdPortOpen_Click()
Dim lPort As Long
'''''''''''''''''''''''''''''''''
On Error GoTo errPort
'''''''''''''''''''''''''''''''''
If txtPort.Text <> "" Then
lPort = CLng(txtPort.Text)
Else
lPort = 1
End If
'''''''''''''''''''''''''''''''''
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
'''''''''''''''''''''''''''''''''
With MSComm1
If .PortOpen = False Then
.CommPort = lPort
.Settings = "9600,n,8,1"
.RThreshold = 1
.PortOpen = True
End If
End With
Exit Sub
errPort:
MsgBox Err.Description
txtPort.Text = ""
txtPort.SetFocus
End Sub
Private Sub MSComm1_OnComm()
Dim sBuffer
sBuffer = sBuffer & MSComm1.Input
Text1.Text = Text1.Text & sBuffer
End Sub