Skip to content
This repository has been archived by the owner on Apr 7, 2019. It is now read-only.

Commit

Permalink
Update protocols for Grbl 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gerritv committed Oct 12, 2016
1 parent afad27a commit 7532c48
Show file tree
Hide file tree
Showing 12 changed files with 445 additions and 162 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
This file documents changes made:
V1.0.9.7 - 2016 Oct 12
- Adapt to new Gbrl 1.1a reports, etc.
- Added button to clear Pin states, makes them latch on even a single report
V1.0.9.6 - 2016 Aug 27
- Change spacebar to control Hold/Resume Issue #62
- Enable use of Enter for Grbl Settings and Offsets
Expand Down
3 changes: 3 additions & 0 deletions Grbl-Panel/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
This file documents changes made:
V1.0.9.7 - 2016 Oct 12
- Adapt to new Gbrl 1.1a reports, etc.
- Added button to clear Pin states, makes them latch on even a single report
V1.0.9.6 - 2016 Aug 27
- Change spacebar to control Hold/Resume Issue #62
- Enable use of Enter for Grbl Settings and Offsets
Expand Down
2 changes: 1 addition & 1 deletion Grbl-Panel/GrblGcode.vb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Partial Class GrblGui
_runMode = False
gcodeview.fileMode = False

If Not (data.StartsWith("$") Or data.StartsWith("?")) Then
If (data.StartsWith("$J") Or Not (data.StartsWith("$") Or data.StartsWith("?"))) Then
' add to display
' _gui.gcodeview.Insert(data, 0)
With gcodeview
Expand Down
9 changes: 5 additions & 4 deletions Grbl-Panel/GrblGui.vb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Imports System.Threading.Thread

Public Class GrblGui

Public GrblVersion As Integer ' 0 for 0.x, 1 for 1.x version
Public WithEvents grblPort As GrblIF ' Public so that the timer thread can see grblPort
Private status As GrblStatus ' For status polling
Private jogging As GrblJogging ' for jogging control
Expand All @@ -15,7 +16,7 @@ Public Class GrblGui
Public state As GrblState ' to track gcode state
Public settings As GrblSettings ' To handle Settings related ops
Public ovrrides As GrblOverrides ' to display overrides
Public pins As GrblPins ' to display pin states
Public pins As GrblPins ' to display Pin states

Private _exitClicked As Boolean = False ' to separate Close (x) from File/Exit

Expand Down Expand Up @@ -491,7 +492,7 @@ Public Class GrblGui
gbSettingsPosition.Enabled = False
gbGrblSettings.Enabled = False

btnStatusGetParser.Enabled = False
btnStatusClearPins.Enabled = False
Case "Disconnected"
' We are not connected so not much you can do
gbJogging.Enabled = False
Expand All @@ -506,7 +507,7 @@ Public Class GrblGui
gbSettingsPosition.Enabled = False
gbGrblSettings.Enabled = False

btnStatusGetParser.Enabled = False
btnStatusClearPins.Enabled = False
Case "Idle"
' General use, no gcode streaming
gbJogging.Enabled = True
Expand All @@ -521,7 +522,7 @@ Public Class GrblGui
gbSettingsPosition.Enabled = True
gbGrblSettings.Enabled = True

btnStatusGetParser.Enabled = True
btnStatusClearPins.Enabled = True
End Select
End Sub

Expand Down
11 changes: 9 additions & 2 deletions Grbl-Panel/GrblJogging.vb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ Partial Class GrblGui
Case "Z-"
gcode.sendGCodeLine(createJogCommand("Z-"))
End Select
gcode.sendGCodeLine("G90")
If GrblVersion = 0 Then
gcode.sendGCodeLine("G90")
End If
End Sub

Private Sub cbSettingsMetric_CheckedChanged(sender As Object, e As EventArgs) Handles cbSettingsMetric.CheckedChanged
Expand Down Expand Up @@ -134,7 +136,12 @@ Partial Class GrblGui
Public Function createJogCommand(ByVal axis As String) As String
' Builds a jog command from various inputs
' Jog in incremental mode, leave parser in absolute mode!
Return "G91 " + whichUnits() + " G01 " + axis + whichDistance() + " F" + whichFeedRate()
If GrblVersion = 0 Then
Return "G91 " + whichUnits() + " G01 " + axis + whichDistance() + " F" + whichFeedRate()
End If
If GrblVersion = 1 Then
Return "$J=G91" + whichUnits() + axis + whichDistance() + " F" + whichFeedRate()
End If
End Function
''' <summary>
''' Return value of current Distance Increment
Expand Down
86 changes: 65 additions & 21 deletions Grbl-Panel/GrblOverrides.vb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Partial Class grblgui
''' Class to handle overrides related functionality
''' </summary>
Public Enum overrideChars
CMD_SAFETY_DOOR = 132 '0x84
CMD_DEBUG_REPORT = 133 '0x85 ' Only When DEBUG enabled, sends debug report In '{}' braces.
CMD_FEED_OVR_RESET = 144 '0x90 ' Restores feed override value To 100%.
CMD_SAFETY_DOOR = 132 '0x84
CMD_JOG_CANCEL = 133 ' 0x85
CMD_DEBUG_REPORT = 133 '0x86 ' Only When DEBUG enabled, sends debug report In '{}' braces.
CMD_FEED_OVR_RESET = 144 '0x90 ' Restores feed override value To 100%.
CMD_FEED_OVR_COARSE_PLUS = 145 '0x91
CMD_FEED_OVR_COARSE_MINUS = 146 ' 0x92
CMD_FEED_OVR_FINE_PLUS = 147 ' 0x93
Expand All @@ -17,12 +18,14 @@ Partial Class grblgui
CMD_RAPID_OVR_MEDIUM = 150 '0x96
CMD_RAPID_OVR_LOW = 151 ' 0x97
' CMD_RAPID_OVR_EXTRA_LOW 0x98 ' *Not SUPPORTED*
CMD_SPINDLE_OVR_RESET = 153 ' 0x99 ' Restores spindle override value To 100%.
CMD_SPINDLE_OVR_RESET = 153 ' 0x99 ' Restores spindle override value To 100%.
CMD_SPINDLE_OVR_COARSE_PLUS = 154 ' 0x9A
CMD_SPINDLE_OVR_COARSE_MINUS = 155 ' 0x9B
CMD_SPINDLE_OVR_FINE_PLUS = 156 ' 0x9C
CMD_SPINDLE_OVR_FINE_MINUS = 157 '0x9D
CMD_SPINDLE_OVR_STOP = 158 '0x9E
CMD_SPINDLE_OVR_STOP = 158 '0x9E aka Toogle Spindle Stop
CMD_TOGGLE_FLOOD = 160 ' 0xA0
CMD_TOGGLE_MIST = 161 ' 0xA1
End Enum
Public Class GrblOverrides
Private _gui As GrblGui
Expand Down Expand Up @@ -58,20 +61,43 @@ Partial Class grblgui

Public Sub showOverrides(ByVal data As String)

Dim _ovrIndex As Integer
Dim _ovr As String()

_ovrIndex = data.LastIndexOf("OVR:")
If _ovrIndex = -1 Then
Return
Else
data = data.Remove(data.Length - 3, 3) ' Remove > and vbCrLf
' We have Grbl V1.0 or later so display overrides
_ovr = data.Substring(_ovrIndex + 4).Split(",")
tbFeedOvr.Text = _ovr(0) + "%"
tbRapidOvr.Text = _ovr(1) + "%"
tbSpindleOvr.Text = _ovr(2) + "%"
' Process Override values, Grbl 1.x only
If data.Contains("Ov:") Or data.Contains("T:") Then
data = data.Remove(data.Length - 3, 3)
Dim statusMessage = Split(data, "|")
For Each item As String In statusMessage
Dim portion() As String = Split(item, ":")
Select Case portion(0)
Case "Ov"
Dim ovr = Split(portion(1), ",")
tbFeedOvr.Text = ovr(0) + "%"
tbRapidOvr.Text = ovr(1) + "%"
tbSpindleOvr.Text = ovr(2) + "%"
If Not data.Contains("T") Then
btnSpindleOverride.BackColor = Color.Transparent
End If
Case "T"
If portion(1).Contains("S") Then
btnSpindleOverride.BackColor = Color.Crimson
End If
If portion(1).Contains("F") Then
If btnFloodOverride.BackColor = Color.Crimson Then
btnFloodOverride.BackColor = Color.Transparent
Else
btnFloodOverride.BackColor = Color.Crimson
End If
End If
If portion(1).Contains("M") Then
If btnMistOverride.BackColor = Color.Crimson Then
btnMistOverride.BackColor = Color.Transparent
Else
btnMistOverride.BackColor = Color.Crimson
End If
End If
End Select
Next
End If

End Sub
''' <summary>
''' Handles the Click event of the btnFeedOverride controls.
Expand Down Expand Up @@ -137,9 +163,27 @@ Partial Class grblgui
grblPort.sendData(Chr(overrideChars.CMD_SPINDLE_OVR_RESET))
End Select
End Sub
''' <summary>
''' Handle toggle of some overrides, constrained by present state
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub btnToggleOverride_Click(sender As Object, e As EventArgs) Handles btnSpindleOverride.Click, btnMistOverride.Click, btnFloodOverride.Click
' Spindle toggle only in Hold
' Coolant and Mist in Idle,Run or Hold
Dim btn As Button = sender
Select Case DirectCast(btn.Tag, String)
Case "SpindleOverride"
grblPort.sendData(Chr(overrideChars.CMD_SPINDLE_OVR_STOP))

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnRapidMinus.Click

grblPort.sendData(Chr(overrideChars.CMD_DEBUG_REPORT))
If btnSpindleOverride.BackColor = Color.Crimson Then
btnSpindleOverride.BackColor = Color.Transparent
End If
Case "FloodOverride"
grblPort.sendData(Chr(overrideChars.CMD_TOGGLE_FLOOD))
Case "MistOverride"
grblPort.sendData(Chr(overrideChars.CMD_TOGGLE_MIST))
End Select
' btn colour changes based on T:SFM response handled in showOverrides()
End Sub
End Class
76 changes: 52 additions & 24 deletions Grbl-Panel/GrblPins.vb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ Partial Class GrblGui
_gui.gbPinStatus.Visible = value
If value = True Then
With _gui
.cbLimitX.Visible = True
.cbLimitY.Visible = True
.cbLimitZ.Visible = True
.cbProbePin.Visible = True
.cbResetAbort.Visible = True
.cbFeedHold.Visible = True
Expand All @@ -76,38 +79,63 @@ Partial Class GrblGui
Public Sub showGrblPins(ByVal data As String)
Dim pos As Integer

If data(0) = vbLf Or data(0) = vbCr Then
Return ' nothing to do
End If
If data = vbCrLf Then Return

' Show X, Y, Z limit pin state
If Not pins.LimitsSeen Then
If data.Contains("Lim:") Or data.Contains("Pin:") Then
' We are on Grbl 0.9
If GrblVersion = 0 And data.Contains("Lim:") Then
' We need to show Limit pins
If Not pins.LimitsSeen Then
pins.LimitsSeen = True
End If
End If

If Not pins.PinsSeen Then
If data.Contains("Pin:") Then
pins.PinsSeen = True
End If
End If

If data.Contains("Lim:") Or data.Contains("Pin:") Then
' We need to show Limit pins
pos = InStr(data, "Lim:") + InStr(data, "Pin:")
pos = InStr(data, "Lim:")
cbLimitZ.Checked = (data(pos + 3) = "1")
cbLimitY.Checked = (data(pos + 4) = "1")
cbLimitX.Checked = (data(pos + 5) = "1")
End If

' pos 6 and 8 are delimiters "|"
If data.Contains("Pin:") Then
' Show other pins
cbProbePin.Checked = (data(pos + 7) = "0")
cbStartResume.Checked = (data(pos + 9) = "1")
cbFeedHold.Checked = (data(pos + 10) = "1")
cbResetAbort.Checked = (data(pos + 11) = "1")
' Are we on Grbl 1.0 or later?
If GrblVersion = 1 And data(0) = "<" Then
If data.Contains("Pn:") Then
' Show other pins
Dim pinlist As String
If Not pins.PinsSeen Then
pins.PinsSeen = True
End If
data = data.Remove(data.Length - 3, 3)
Dim statusMessage = Split(data, "|")
For Each item As String In statusMessage
Dim portion() As String = Split(item, ":")
Select Case portion(0)
Case "Pn"
pinlist = portion(1)
cbProbePin.Checked = InStr(pinlist, "P")
cbDoorOpen.Checked = InStr(pinlist, "D")
cbFeedHold.Checked = InStr(pinlist, "H")
cbResetAbort.Checked = InStr(pinlist, "R")
cbStartResume.Checked = InStr(pinlist, "S")

cbLimitX.Checked = InStr(pinlist, "X")
cbLimitY.Checked = InStr(pinlist, "Y")
cbLimitZ.Checked = InStr(pinlist, "Z")
End Select
Next
' We don't clear, use the provided button.
' This makes the pin occurance latch
End If
End If
End Sub


Private Sub btnStatusClearPins_Click(sender As Object, e As EventArgs) Handles btnStatusClearPins.Click
' Clear pins if set
cbProbePin.Checked = False
cbDoorOpen.Checked = False
cbFeedHold.Checked = False
cbResetAbort.Checked = False
cbStartResume.Checked = False

cbLimitX.Checked = False
cbLimitY.Checked = False
cbLimitZ.Checked = False
End Sub
End Class
Loading

0 comments on commit 7532c48

Please sign in to comment.