Hi,
Don't know much about BNComm but with MSComm you'd do something like
VB Code:
Private Sub cmdSend_Click()
MSComm1.Output strMyData
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.ComEvent
Case comEvReceive
Do
strData = strData & MSComm1.Input
Loop Until MSComm1.InBufferCount = 0
If strData = "OK" then
'
' Chip has responded with OK
'
Else
'
' Chip has responded with something else
'
End If
End Select
End Sub
With MSComm you have to set RThreshold value to non zero (recommend 1) in order to have the OnComm event trigger.
You should also be able to Poll the device in a loop:
VB Code:
Private Sub cmdSend_Click()
MSComm1.Output strMyData
'
' Loop until something is received
'
Do Until MSComm1.ComEvent = comEvReceive
DoEvents
Loop
Do
strData = strData & MSComm1.Input
Loop Until MSComm1.InBufferCount = 0
If strData = "OK" then
'
' Chip has responded with OK
'
Else
'
' Chip has responded with something else
'
End If
End Sub
If you choose the Polling option it would be 'safe' to have a timeout in the loop waiting for a response, just in case the device is switched off or otherwise unavailable. You could put a timer on the Form and set its interval to a reasonable timeout period and when that triggers, stop the loop.
eg
VB Code:
Dim boTimeout as Boolean ' This should be in the Declaration Section
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 2000 ' 2000 = 2 Seconds
End Sub
Private Sub Timer1_Timer()
boTimeout = True
End Sub
Private Sub cmdSend_Click()
MSComm1.Output strMyData
'
' Loop until something is received
' or the request times out
'
boTimeout = False
Timer1.Enabled = True
Do Until MSComm1.ComEvent = comEvReceive Or boTimeout = True
DoEvents
Loop
If boTimeout = False Then
Do
strData = strData & MSComm1.Input
Loop Until MSComm1.InBufferCount = 0
If strData = "OK" then
'
' Chip has responded with OK
'
Else
'
' Chip has responded with something else
'
End If
Else
MsgBox "Equipment hasn't responded after " & Timer1.Interval / 1000 & " Seconds"
End if
End Sub
InBufferCount is the number of bytes in the input buffer waiting to be read.
comEvReceive is the constant assigned to the .ComEvent property when a receive event occurs.
I suspect that BNComm has similar capabilities and properties
Regards
Doug