Error Message when Sending Json data to RS 232

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc used Ask the Experts™
on
Hi All;

Im having the same error messages when sending data and receiving Json string using RS 232, before I start working on the gadget I want a second eye to  take a look on the code below, please  note the following :

9600 baud is converted to 64 bytes

All the  two codes for sending & receiving as well as for converting received data are called from the main code that has the data for sending since once the data is received by the gadget then the gadget is supposed to send a signature back instantly.

Receiving code


Private Sub CmdTaxReceive_Click()
Dim strData As String
Dim lngStatus As Long
Dim strError As String
Dim intPortID As Integer
' Read maximum of 64 bytes from serial port.
    lngStatus = CommRead(intPortID, strData, 64)

If lngStatus > 0 Then
        ' Process data.
 ElseIf lngStatus < 0 Then
      lngStatus = CommGetError(strError)
      MsgBox "COM Error: " & strError
      Stop
    End If
    
    lngStatus = CommFlush(intPortID)
    
    If lngStatus <> 0 Then
      lngStatus = CommGetError(strError)
      MsgBox "COM Error: " & strError
      Stop
    End If
' Reset modem control lines.
    lngStatus = CommSetLine(intPortID, LINE_RTS, False)
    lngStatus = CommSetLine(intPortID, LINE_DTR, False)
 ' Close communications.
    Call CommClose(intPortID)

End Sub

Open in new window

Sending code


Private Sub CmdSendTax_Click()
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    Dim lngStatus As Long
    Dim strError  As String
    Dim strData   As String
    Dim lngSize As Long

    ' Initialize Communications
    lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
        "baud=9600 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
End Sub

Open in new window



Calling them on the same form but on the main code


Call CmdTaxReceive_Click
Call CmdSendTax_Click
Call CmdEmp_Click

Open in new window



Where do I go wrong????



Auditing-tools.png


Blank-Invoices-Details.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012
Commented:
Did you initialize the com port?    In the article's sample database, the form frmGetWeight has code in the OnLoad event to open the port.

 You can't receive on the port until you initialize it.

 Also, the receive code is closing the port....so your only going to be able to do one receive and then you'll get errors after that.

 For your process, which is started by the OnClick, you will want to:

1. Initialize the port

2. Send/Receive as needed, which might be multiple times.  You will probably have a loop.

3. Close the port.

HTH,
Jim.
Thank so much I have see the problem here , let me fix it.

Regards

Chris

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial