I am building an app that communicates to an Elm327 divice on my com port,
I need to know how to do thiss, I have made a smaller app for testing, I can connect to device, I know this as the device then sends me a message, now I need to know how to send the command
"AT DP" and receive its response?
please help.

Dani AI

Generated

For and : sending back-to-back AT commands reliably requires an event‑driven flow, not a blocking loop or blind pauses. Let MSComm’s OnComm (comEvReceive) drive when the next command goes out: queue outgoing commands, send one, accumulate the incoming bytes in the OnComm handler, detect the device’s end‑of‑response marker, then send the next queued command. Blocking loops (Do...Loop waiting for CommEvent) stop VB’s message pump and prevent OnComm from firing.

A simple pattern (VB6/MSComm) — queue + OnComm + prompt detection:

' module-level
Private cmdQueue As Collection
Private waiting As Boolean
Private buf As String
Private Const PROMPT = ">"

Private Sub Form_Load()
    Set cmdQueue = New Collection
    MSComm1.InputLen = 0
    MSComm1.RThreshold = 1
End Sub

Public Sub EnqueueCommand(cmd As String)
    cmdQueue.Add cmd
    TrySendNext
End Sub

Private Sub TrySendNext()
    If waiting Then Exit Sub
    If cmdQueue.Count = 0 Then Exit Sub
    Dim c As String
    c = cmdQueue(1)
    cmdQueue.Remove 1
    MSComm1.Output = c & Chr$(13)
    waiting = True
    buf = ""
    ' start a timeout timer here if desired
End Sub

Private Sub MSComm1_OnComm()
    If MSComm1.CommEvent = comEvReceive Then
        buf = buf & MSComm1.Input
        If InStr(buf, PROMPT) > 0 Or InStr(buf, "OK") > 0 Then
            ' process buf (strip echoes/CR/LF)
            waiting = False
            TrySendNext
        End If
    End If
End Sub

Practical tips:

  • Send an initial ATE0 to turn off echo (makes parsing simpler) and look for the > prompt — ELM327 uses that to signal readiness.
  • Use InputLen = 0 to read all available data and RThreshold to control OnComm granularity.
  • Add a small timeout (Timer) to recover if a response never arrives.
  • If HyperTerminal works but your app doesn't, compare baud/parity/handshake settings and ensure your code isn’t blocking the UI thread.

This approach scales: queue thousands of commands and the loop will keep throughput high while still waiting for each response.

Ok I have tried

Private Sub Command3_Click()
MSComm1.Output = "at dp"
Mscomm1_onComm
End Sub
Private Sub Command3_Click()
MSComm1.Output = "at dp"
End Sub
Private Sub Command3_Click()
SendBytes "AT DP"


End Sub
Public Sub SendBytes(ByteString)
Dim ByteArray As Variant
ByteArray = Split(ByteString, " ")
For i = 0 To UBound(ByteArray)
    MSComm1.Output = Chr(CInt("&h" & ByteArray(i)))
Next
End Sub

Nothing results in a reply from the device?
Can anyone help me?

Finally figured out how to send, I was missing vbCR for carrage return I take it.

MSComm1.Output = "at dp" &vbCr

The next issue I have is, When I click my connect button, I need to send 2 commands right away, but now I only get the response from the first command, obviuosly I need to put a pause in between the 2 command fires, but have not worked with timers, could some one tell me how to configure a timer between two commands? or even better how to pause the second command until we receive a reponse from device for first command?

I am close to getting a pause timer but the ore I think about it, later on this will be useless as I will be firing many commands and want it to be fast and not pausing, so a way of waiting for a reply before firing next command would be better, something like

If (MSComm1.CommEvent = comEvReceive) Then
Next
Else Loop

I have tried many variations, this one doesnt throw and error but still doesn't work

If (MSComm1.CommEvent = comEvSend) Then
Do
Loop
Else
MSComm1.Output = "AT DP" & vbCr
End If

Any suggestions?

I'm trying for this too, with hyperterminal everything is going fine and phone sending response but when i send data with mscomm to the phone it doesn't send response :(((

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.