Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSComm.ComEvent not firing

Status
Not open for further replies.

longbeard

Programmer
Aug 4, 2008
6
0
0
US
Can anyone see a problem with this code? I'm testing with a USB scanner, tho I want to eventually use a raster. It doesn't seem to get past the Form Load. Data appears in the text box, but I'm not sure if it is serial, because it never gets to the OnComm event. ENTER key doesn't fire it, either.

Option Explicit
Public prod As String
Public lot As String
Public scan As String
Public Inbuff As String

Private Sub Form_Load()
With MSComm1
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
End With

txtscandata.Text = ""

End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Inbuff = Inbuff & MSComm1.Input
scan = MSComm1.Input
If Len(Trim(Inbuff)) >= 12 Then
Call HandleInput

Else
Exit Sub
End If

End Select

End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
Sub HandleInput()
txtscandata.SelLength = Len(txtscandata.Text)
'txtscandata.SelText = InBuff
txtscandata.Text = scan
prod = Mid(scan, 1, 6)
MsgBox prod, scan, txtscandata.Text


scan = ""
Inbuff = ""
End Sub
 
I changed scanners. I'm using a serial MS-860. I've checked for communication and I can get data in Hyperterminal and ESP. When Stepping thru, .portopen is false and I cannot make it open. I've added error handling, but it still won't open. I've made sure Hyperterm. and other programs which may use the port are closed. The actual error number now is 8012 (port not open). Any takers on this?

========================================================
Private Sub Form_Load()
On Error GoTo commerr
With MSComm1

MSComm1.CommPort = 1
MSComm1.PortOpen = False
MSComm1.Handshaking = comRTS
MSComm1.RThreshold = 1
MSComm1.RTSEnable = True
MSComm1.Settings = "9600,E,7,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True

End With
txtscandata.Text = ""
commerr:
If Err.Number = 8005 Then
MSComm1.PortOpen = True
Resume Next
End If

End Sub
============================================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top