How to write a Json String into a serial port rs 232 using VBA before sending the data

Dear All;

I need help here to fix the the VBA Code below, what I'm trying to do is to have the pre converted Json string data and then send it to the rs 232 and receive the response at the the same time. The opening part of the machine is fine but the writing part show that there is no data supplied into the port, that is where my problem is.

' Write data to serial port.

    strData = JsonConverter.ConvertToJson(transaction, Whitespace:=3) & Chr$(13)

    lngStatus = CommWrite(intPortID, strData)

    lngSize = Len(strData)

    If lngStatus <> lngSize Then

    Beep

    MsgBox "No data found"

    ' Handle error.

    End If

Suprisingly if I send the data directly to the text file using the VBA code below I will be able to get the data if I open that text file as per link below:

Dim json As String

Dim theFileName  As Variant

json = JsonConverter.ConvertToJson(transaction, Whitespace:=3) & Chr$(13)

theFileName = "C:\Users\admini\Desktop\Leaders\VBA Json.txt"

Dim handle As Integer

handle = FreeFile

Open theFileName For Output As #handle

Print #handle, json 'jsonSerialization

Close #handle

I would do the test

lngSize = Len(strData)

also BEFORE calling CommWrite. No need to send empty data, right?

Are you using a PenCom product? The manufacturer may have more and better examples available. And don't just copy/paste. Understand.

-Tom.
Microsoft Access MVP
Phoenix, AZ

3 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thank you so much sir I will follow your advice.

Regards

Chris

Christopher Senior

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 503 Applies to: