Welcome to Our Community

Some features disabled for guests. Register Today.

GRBL Line skipping GCode

Discussion in 'Control Software' started by s-fr, Nov 3, 2017.

  1. s-fr

    s-fr New
    Builder

    Joined:
    Nov 3, 2017
    Messages:
    4
    Likes Received:
    0
    Hello Guys!

    I programmed my own GUI for using my homemade CNC Maschine. And I got a very nasty problem with that. First of all, this is how I stream GCode

    1. I load the GCode into a Listbox and use this Code for streaming

    Code:
            For Me.i = 0 To CodeBox.Items.Count - 1
                SerialPort1.WriteLine(CodeBox.Items.Item(i))
                SerialPort1.ReadLine()
                Me.Invoke(Sub() CurrentCode.Text = CodeBox.Items.Item(i))
                Me.Invoke(Sub() CalculatePercent())
                Me.Invoke(Sub() ProgramTimer.Start())
                Me.Invoke(Sub() InterpretCode())
                Me.Invoke(Sub() OpticalSelection())
            Next i
            Me.Invoke(Sub() ProgramEnd())
    The problem itself is, that it SOMETIMES skips lines of my GCode. I tried so many things since weeks to eliminate this problem, set down the writebuffer of my SerialPort to 128. But the problem is the issue is not everytime. For me it seems to be a Buffer overflow.

    Is skipping lines a known problem? Is there a solution for this?

    Hope someone can help

    thanks a lot
     
  2. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    15,096
    Likes Received:
    4,320
    You need to control the flow. Either wait for Grbl to send 'ok' before sending a new line, or count the characters and monitor the the available buffer. Interfacing with Grbl · grbl/grbl Wiki · GitHub explains the high level mechanisms. Or look at the comms server Claudio and I wrote Github.com/LaserWeb/lw.comm-server (serial to websocket bridge)
     
    David the swarfer likes this.
  3. s-fr

    s-fr New
    Builder

    Joined:
    Nov 3, 2017
    Messages:
    4
    Likes Received:
    0
    Ok I wrote the code to control if I get an ok from the machine like that:

    Code:
        Private Sub BWAuto_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BWAuto.DoWork
            For Me.i = 0 To CodeBox.Items.Count - 1
                If answer.Contains("ok") Then
                    SerialPort1.WriteLine(CodeBox.Items.Item(i))
                    answer = SerialPort1.ReadLine()
                End If
    
                Me.Invoke(Sub() CurrentCode.Text = CodeBox.Items.Item(i))
                Me.Invoke(Sub() CalculatePercent())
                Me.Invoke(Sub() InterpretCode())
                Me.Invoke(Sub() OpticalSelection())
                Me.Invoke(Sub() ProgramTimer.Start())
                Me.Invoke(Sub() WriteLog())
            Next i
            Me.Invoke(Sub() ProgramEnd())
        End Sub
    
    And wrote the "answers" in a log file and tadaaa what I got was this:

    Code:
    1 - G54   [ [MSG:Pgm End]
    The first thing I write in each code is "G54, G55, ... or whatever" and at this point it respond "MSG:pgm End" and not "ok". Can anybody tell me please why do I get a Programm End for sending a simple G54 Command instead of an "ok"??


    King regards
     
  4. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    15,096
    Likes Received:
    4,320
    Code:
    [MSG:Pgm End] - M2/30 program end message to denote g-code modes have been restored to defaults according to the M2/30 g-code description.
    
    Should only trigger for M2 or M30 commands...

    Test your expected responses by connecting to Grbl directly using minicom/putty/other serial terminal and sending your lines one by one to monitor the responses.
    Once you confirm it really is Grbl responding incorrectly, report it at Issues · gnea/grbl · GitHub

    (PS G54 is the default WCS, so perhaps its just reporting theres nothing to reset?) (Try G55)

    Perhaps your sender garbles the commands while sending?
     
  5. s-fr

    s-fr New
    Builder

    Joined:
    Nov 3, 2017
    Messages:
    4
    Likes Received:
    0
    I have a SingleBlock function in my GUI so I sent the same code with confirming each line and it works like a charm no error or wrong error Message is produced. But its the same code except the confirmation

    Automatic Code
    Code:
        Private Sub BWAuto_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BWAuto.DoWork
            For Me.i = 0 To CodeBox.Items.Count - 1
                If answer.Contains("ok") Or answer.Contains("[MSG:Pgm End]") Then
                    SerialPort1.WriteLine(CodeBox.Items.Item(i))
                    answer = SerialPort1.ReadLine()
                End If
    
                Me.Invoke(Sub() CurrentCode.Text = CodeBox.Items.Item(i))
                Me.Invoke(Sub() CalculatePercent())
                Me.Invoke(Sub() InterpretCode())
                Me.Invoke(Sub() OpticalSelection())
                Me.Invoke(Sub() ProgramTimer.Start())
                Me.Invoke(Sub() WriteLog())
            Next i
            Me.Invoke(Sub() ProgramEnd())
        End Sub
    

    SingleBlock Code
    Code:
        Private Sub BWSingle_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BWSingle.DoWork
            For Me.i = 0 To CodeBox.Items.Count - 1
                
     If answer.Contains("ok") Then
                    SerialPort1.WriteLine(CodeBox.Items.Item(i))
                    answer = SerialPort1.ReadLine()
                End If
                Me.Invoke(Sub() CurrentCode.Text = CodeBox.Items.Item(i))
                Me.Invoke(Sub() CalculatePercent())
                Me.Invoke(Sub() InterpretCode())
                Me.Invoke(Sub() OpticalSelection())
                Me.Invoke(Sub() WriteLog())
                MessageBox.Show(CodeBox.Items.Item(i).ToString)
            Next i
            Me.Invoke(Sub() ProgramEnd())
        End Sub
    
     
  6. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    15,096
    Likes Received:
    4,320
    If wait for OK is giving you issues, try character counting (as per Grbl Wiki linked above). Thats what we use on Lw.comm-server (Nodejs though, not familiar with your language. Our server has a lot more code though)
     
  7. s-fr

    s-fr New
    Builder

    Joined:
    Nov 3, 2017
    Messages:
    4
    Likes Received:
    0
    Can you give me a Code example written in vb or C# for Char Counting?
     
  8. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    15,096
    Likes Received:
    4,320
    Sadly no. But google for Grbl Hosts, check the various options, some may be in VB or C. Maybe GrblPanel, Candle, etc, and most are open source with clear links to their source code, usually also on github
     
  9. phil from seattle

    phil from seattle Journeyman
    Builder

    Joined:
    Mar 17, 2017
    Messages:
    315
    Likes Received:
    138
    Maybe this is a dumb question but why not just use one of the various programs like GRBL-panel, bCNC, ...? The developers have worked out all the issues to squeeze the most performance out of GRBL running on an arduino.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice