Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Flag for Zambia

asked on 

How to use Loop in the serial port programming

After working throughout last night on the serial USB Port to find out exactly what was causing Ms Access to hang/restart before finishing the second invoice,I discovered fortunately the main issue,Firstly, I had to use the note pad to divert the actual data that was coming out from the gadget to analysis it line by line including the commas & other characters and the results after comparing it with the gadget manual provided turned out as below:

(1) The QR code details were missing or not coming out of the gadget
(2) The CRC was also missing
(3) The closing Braces & Square brackets were also missing

Conclusion only 90% of the data were being extracted from the port leaving 10% inside, that is why Ms Access had a problem of hanging/restarting.

Help required

Extra VBA code to loop through the CommRead Function to force all the data to come out of the serial port before process any data and writing to the table. I'm trying the code below but it appears I'm missing it somewhere:

CommRead Function

' Read maximum of 2034 bytes from serial port.
    lngStatus = CommRead(intPortID, strData, 2036)
    'Do loop
    Do While lngStatus > 0
    If lngStatus < 0 Then
    Exit Do
    Set json = JsonConverter.ParseJson(Chr(91) & Mid(strData, 8) & Chr(34) & "}" & Chr(93))
    On Error Resume Next
    End If

Open in new window

ProgrammingMicrosoft AccessVBAJSON

Avatar of undefined
Last Comment
Jim Dettman (EE MVE)

8/22/2022 - Mon