
Need help on sending character to comm in echo mode
You can't use the SThreshold event to control the maximum number of
characters to send. It is designed to be used where you are sending strings
of variable length and you need an event to indicate when the send buffer
should be refilled with new characters to send, or when the send buffer is
empty, ie, all data has been sent.
Instead of using comEvSend use a loop to send your string character by
character, waiting either for confirmation or a timeout at each character.
Dim Waiting as Boolean
Private Sub Comm1_OnComm()
Select Case Comm1.CommEvent
Case comEvReceive
' compare received character with sent character
Timer1.Enabled = False
Waiting = False
End Select
End Sub
Private Sub send_string(daten As Variant)
Dim i As Integer
daten = daten & vbCr
For i = 1 to len(daten)
Waiting = True
Timer1.Enabled = True
Comm1.Output = mid(daten,i,1)
While Waiting = True
' DoEvents
Wend
Next i
End Sub
Private Sub Timer1_Timer()
MsgBox "TimeOut!"
Timer1.Enabled = False
Waiting = False
End Sub
--
Jeff Richards
Quote:
> Hello,
> I need some help sending characters to the serial port with eVB. The
> device runs in echo mode. That means it receives a string character by
> character. The Pocket PC (IPAQ) has to wait for the echo before
> sending the next character.
> The problem is : the whole output buffer will be sent no matter the
> value of SThreshold.
> My code :
> Private Sub Comm1_OnComm()
> Select Case Comm1.CommEvent
> Case comEvSend
> Timer1.Enabled = True
> Case comEvReceive
> ' compare received character with sent character
> Timer1.Enabled = False
> End Select
> End Sub
> Private Function send_string(daten As Variant) As Boolean
> Dim i, ZeilenNummer As Integer
> Dim tmpStr, PrgSchritt As String
> Dim lpBytesWritten, lDummy As Long
> On Error Resume Next
> send_string = True
> daten = daten & vbCr
> Comm1.Output = daten
> End Function
> Sub port_open()
> On Error Resume Next
> 'Set input to text mode
> Comm1.InputMode = 0
> 'Read whole buffer
> Comm1.InputLen = 0
> 'Set com port
> Comm1.CommPort = 1
> 'configure comm port settings to 9600 bd, 8 Bit, no parity, 1
> Startbit
> Comm1.Settings = "9600,N,8,1"
> 'no handshaking
> Comm1.Handshaking = 0
> Comm1.PortOpen = True
> Comm1.RThreshold = 1
> Comm1.SThreshold = 1
> End Sub
> Sub port_close()
> On Error Resume Next
> If Comm1.PortOpen Then Comm1.PortOpen = False
> End Sub
> .
> .
> .
> port_open
> send_string("test")
> port_close
> thanks for help
> Holger