GRBL 1.1 Send and Receive

Hi Guys!

I’m trying to create a Program in vb.net for sending G-Code to my GRBL 1.1 Machine, and Receive Data from it.

So sending works like a charm, I used a Backgroundworker with the following code:

    Dim sLines As String() = Code.Lines
    For i As Integer = 0 To sLines.Length - 1
        Dim j As Integer = i
        Me.Invoke(Sub() CurrentCode.Text = sLines(j))
        MillPort.WriteLine(sLines(i))
        MillPort.ReadLine()
    Next

as you can see I WriteLine to the USB Port and execute a ReadLine to release the buffer of the machine, its working fine, but I don’t know how to get Data back from the machine, at first I want to get back the coordinates (WPos, MPos)
but I don’t know any good way to do this.

Hope someone can help

King regards

I believe that the format of the returned information from grbl changed from 0.9 to 1.1, but the commands are the same. You can read about it here:

Start by looking at the report mask $10 and the status command ?

This should get you started.

Hey Larry Thanks for your reply!

I know I have to send a “?” but I want to see my coordinates when G-Code is running in realtime, and this is my problem.

I send a ? with a timer each 200ms, and I think this migth kill the buffer of my machine. If I do as I said, the machine stops randomly where it wants. I’m looking for a code or a method to send a line of code and receive in realtime the coordinates.

King regards

Ok, I’m speculating here, which usually gets me in trouble but here goes anyway.

Sending a command (? is one) is the only way I know to get the current machine/work position from grbl.

My guess is that since that is slow and would tie up grbl with un-necessary overhead, the sending programs just parse the G-code and report position as they send it to grbl.

Don’t jump all over me, just tell me I’m wrong. I can take it.:smiley:

I believe to do this you would have to attach some external DRO (digital read out) equipment to the X-carve.

You don’t do anything with the content returned by that ReadLine? It contains at least the first part of the response from Grbl.

1 Like

Actually as far as I can tell, Grbl returns the current position in both work coordinates as well as machine coordinates fairly continuously. Real-time might be stretching it a bit, but it’s good enough for fun observation. You won’t want to rely on it for doing more complicated logic since the position isn’t truly real-time current unless the machine is quiescent.

This might be a page worth looking at:

There’s probably an update for GRBL 1.1 on the GRBL 1.1 page.

No it doesn’t. You have to ask for it. Grbl is a command/response system.

Since the original poster was looking for real-time, I assumed that he didn’t mean near real-time. Even near real-time is stretching it.

True.

Also, true.

@JustinBusby That’s a really good link. Thanks…

Did you look at the way easel is doing it yet?

I was looking into a problem for a forum member one time and I put a USB monitor on the line to see what Easel was doing wrong. I believe that was Easel Local version 2.7, but I’m not sure at this point.

As a side issue I noticed that the USB monitor showed that Easel was banging away on grbl with a lot of status requests.

Naive option, checking status every N lines

Sub SendCode()
  Dim sLines As String() = Code.Lines
  Dim howManyLines As Integer = 10
  For i As Integer = 0 To sLines.Length - 1
    Dim j As Integer = i
    Me.Invoke(Sub() CurrentCode.Text = sLines(j))
    MillPort.WriteLine(sLines(i))
    MillPort.ReadLine()
    ' Get status/location every Nth line
    If i Mod howManyLines = 0 Then
      millPort.WriteLine("?")
      Dim statusResult As String = millPort.ReadLine()
      ' Process the line...
    End If
  Next
End Sub

Better method, checking no more often than every 10Hz, per the GRBL developer’s recommendation.

We recommend querying Grbl for a ? real-time status report at no more than 5Hz. 10Hz may be possible, but at some point, there are diminishing returns and you are taxing Grbl’s CPU more by asking it to generate and send a lot of position data.
https://github.com/grbl/grbl/wiki//Interfacing-with-Grbl#grbl--help-message

Here’s code for 4hz, just to be safe.

Sub SendCode()
  Dim checkMilliseconds As Double = 250D 
  Dim nextCheck As DateTime = DateTime.Now.AddMilliseconds(checkMilliseconds) 
  Dim sLines As String() = Code.Lines
  For i As Integer = 0 To sLines.Length - 1
    Dim j As Integer = i
    Me.Invoke(Sub() CurrentCode.Text = sLines(j))
    MillPort.WriteLine(sLines(i))
    MillPort.ReadLine()
    ' Get status/location every Nth line
    If DateTime.Now > nextCheck Then
      millPort.WriteLine("?")
      Dim statusResult As String = millPort.ReadLine()
      nextCheck = DateTime.Now.AddMilliseconds(checkMilliseconds)
    End If
  Next
End Sub

$EaselLocal/lib/parser.js - var onGrblReport = function (d)
Has a comment // format is <[status],MPos:[x],[y],[z],WPos:[x],[y],[z],Pin:|0|>.
Seems to indicate they’re expecting $10=3 or $10=19 (16=Limit Pins).

Parsing the MPos:X,Y,Z and WPos:X,Y,Z should be fine…

@Phobos, You’ve seen the implementation from UGS https://github.com/grbl/Universal-G-Code-Sender/blob/master/src/com/willwinder/universalgcodesender/SerialCommunicator.java and https://github.com/grbl/grbl/blob/master/doc/script/simple_stream.py, right?

@JeremySimmons

No, the format of that line indicates that they are expecting grbl 1.0c (and maybe 1.1e I haven’t checked the format there) and a $10 setting of 35 ($10=35) which is MPos, WPos, and Probe.

For further info:

correct.
sorry for not being more thourough and causing confusion