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.
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.
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.
I believe to do this you would have to attach some external DRO (digital read out) equipment to the X-carve.
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.
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.
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. Interfacing with Grbl · grbl/grbl Wiki · GitHub
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:,[y],[z],WPos:,[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…
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.