请高手看下,API串口通讯问题?只接收到第一个字符。
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As OVERLAPPED) As Long》》》》》》》》》》》》》》》
Public Function ReadData(fhdata As String, Optional lngSize As Long = 255, Optional Outtime As Long = 2000, Optional txtRecv As TextBox) As Long
On Error GoTo Routine_Exit '打开错误陷阱
If (com_Handle = 0) Then
ReadData = 0
Exit Function
End If
Dim lngBytesRead As Long
Dim fReadStat As Long
Dim lngErrorFlags As Long
Dim lngStatus As Long
Dim udtCommStat As COMSTAT
'读数据
If ClearCommError(com_Handle, lngErrorFlags, udtCommStat) <= 0 Then
PurgeComm com_Handle, PURGE_RXABORT Or PURGE_RXCLEAR
End If
fhdata = Space$(255)
fReadStat = ReadFile(com_Handle, ByVal fhdata, lngSize, fReadStat, m_OverlappedRead)
txtRecv.Text = txtRecv.Text & Trim$(fhdata)
ClearInBuf '清除缓冲区
ReadData = lngBytesRead
Exit Function
Routine_Exit:
ReadData = 0
End Function