vbams-accessserial-portrs

How to remove the restriction on reading received from Rs 232


We are using a gadget that is running at 115200 baud , now the VBA for Rs 232 require inserting a limit on reading data received but the gadget does not require that restriction.

The gadget we have does not require any of restriction for data received from RS 232 , how can we remove that restriction? And the port must remain 24 hours open , how do we do it?

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) Remove the restriction of data received (2) The port must remain 24 hours open

If change this code lngStatus = CommRead(PortID, strData,14400) to lngStatus = CommRead(PortID, strData) then I get compile error?

enter image description here


Solution

  • Try this code with infinite loop:

        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
    

    But may be you should change size of batch from 14400 to another value that is more suitable for your situation.