如何取消从 232 卢比收到的阅读限制
How to remove the restriction on reading received from Rs 232
我们使用的是 运行 波特率为 115200 的小工具,现在 VBA 为 232 卢比需要对读取接收到的数据设置限制,但小工具不需要该限制。
我们的小工具对从 RS 232 接收的数据没有任何限制,我们如何才能取消该限制?而且口岸必须24小时开放,怎么办?
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
Dim lngStatus As Long
Dim strError As String
Dim strData As String
' Initialize Communications
lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
"baud=115200 parity=N data=8 stop=1")
If lngStatus <> 0 Then
' Handle error.
lngStatus = CommGetError(strError)
MsgBox "COM Error: " & strError
End If
' Set modem control lines.
lngStatus = CommSetLine(intPortID, LINE_RTS, True)
lngStatus = CommSetLine(intPortID, LINE_DTR, True)
' Write data to serial port.
lngSize = Len(strData)
lngStatus = CommWrite(intPortID, strData)
If lngStatus <> lngSize Then
' Handle error.
End If
' Read maximum of 14400 bytes from serial port.
lngStatus = CommRead(intPortID, strData, 14400)
If lngStatus > 0 Then
' Process data.
ElseIf lngStatus < 0 Then
' Handle error.
End If
' Reset modem control lines.
lngStatus = CommSetLine(intPortID, LINE_RTS, False)
lngStatus = CommSetLine(intPortID, LINE_DTR, False)
' Close communications.
Call CommClose(intPortID)
(1)解除接收数据限制
(2) 端口必须保持24小时开放
如果将此代码 lngStatus = CommRead(PortID, strData,14400) 更改为 lngStatus = CommRead(PortID, strData) 那么我会遇到编译错误吗?
enter image description here
用无限循环试试这个代码:
While True
' Read maximum of 14400 bytes from serial port.
lngStatus = CommRead(intPortID, strData, 14400)
If lngStatus > 0 Then
' Process data.
ElseIf lngStatus < 0 Then
' Handle error.
End If
wend
但也许您应该将批量大小从 14400 更改为更适合您情况的另一个值。
我们使用的是 运行 波特率为 115200 的小工具,现在 VBA 为 232 卢比需要对读取接收到的数据设置限制,但小工具不需要该限制。
我们的小工具对从 RS 232 接收的数据没有任何限制,我们如何才能取消该限制?而且口岸必须24小时开放,怎么办?
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
Dim lngStatus As Long
Dim strError As String
Dim strData As String
' Initialize Communications
lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
"baud=115200 parity=N data=8 stop=1")
If lngStatus <> 0 Then
' Handle error.
lngStatus = CommGetError(strError)
MsgBox "COM Error: " & strError
End If
' Set modem control lines.
lngStatus = CommSetLine(intPortID, LINE_RTS, True)
lngStatus = CommSetLine(intPortID, LINE_DTR, True)
' Write data to serial port.
lngSize = Len(strData)
lngStatus = CommWrite(intPortID, strData)
If lngStatus <> lngSize Then
' Handle error.
End If
' Read maximum of 14400 bytes from serial port.
lngStatus = CommRead(intPortID, strData, 14400)
If lngStatus > 0 Then
' Process data.
ElseIf lngStatus < 0 Then
' Handle error.
End If
' Reset modem control lines.
lngStatus = CommSetLine(intPortID, LINE_RTS, False)
lngStatus = CommSetLine(intPortID, LINE_DTR, False)
' Close communications.
Call CommClose(intPortID)
(1)解除接收数据限制 (2) 端口必须保持24小时开放
如果将此代码 lngStatus = CommRead(PortID, strData,14400) 更改为 lngStatus = CommRead(PortID, strData) 那么我会遇到编译错误吗?
enter image description here
用无限循环试试这个代码:
While True
' Read maximum of 14400 bytes from serial port.
lngStatus = CommRead(intPortID, strData, 14400)
If lngStatus > 0 Then
' Process data.
ElseIf lngStatus < 0 Then
' Handle error.
End If
wend
但也许您应该将批量大小从 14400 更改为更适合您情况的另一个值。