home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "COMMUTIL"
- '
- ' This function checks the input port and retrieves the
- ' contents of the input buffer. Returns the empty string
- ' if no characters were found.
- '
- Function GetChars$()
- Dim csbuf As COMSTAT
- Dim instring$
- Dim charsread%
-
- If CommID% < 0 Then Exit Function ' Make sure port is open
-
- ' Is there space for the data?
-
- di% = GetCommError(CommID%, csbuf)
-
- If csbuf.cbInQue = 0 Then ' No characters found
- GetChars$ = ""
- Exit Function
- End If
-
- instring$ = String$(csbuf.cbInQue, 0)
-
- ' A real application would check for an error here
- di% = ReadComm(CommID%, instring$, csbuf.cbInQue)
-
- charsread% = Abs(di%)
- If charsread% = csbuf.cbInQue Then instring$ = instring$ + GetChars$()
-
- GetChars$ = instring$
-
- End Function
-
-
- '
- ' Sends the characters specified. Changes tosend$ to
- ' the characters that do not fit into the output buffer
- '
- Sub SendChars(tosend$)
- Dim csbuf As COMSTAT
- Dim outstring$
-
- If CommID% < 0 Then Exit Sub ' Make sure port is open
-
- ' Is there space for the data?
-
- di% = GetCommError(CommID%, csbuf)
-
- If BufferSize% - csbuf.cbOutQue < Len(tosend$) Then
- ' This is an error - a real application would somehow
- ' need to notify the calling function that it could
- ' only write part of the data so that the calling
- ' function would know what to do next.
- ' What we do is only write the portion of the string
- ' that fits, then change tosend$ to exclude the data
- ' written.
- outstring$ = Left$(tosend$, BufferSize% - csbuf.cbOutQue)
- tosend$ = Mid$(tosend$, BufferSize% - csbuf.cbOutQue + 1)
- Else
- outstring$ = tosend$
- tosend$ = ""
- End If
-
- ' A real application would check for an error here
- di% = WriteComm(CommID%, outstring$, Len(outstring$))
- End Sub
-
-