- Posts: 49
- Thank you received: 0
GladeVCP + Python: error handling during G38.2
6 years 1 month ago #182071
by aekhv
GladeVCP + Python: error handling during G38.2 was created by aekhv
Hi everyone,
I trying to catch errors during executing G38.2 and sometime it works fine, but sometimes not... Please point me what I'm doing wrong.
I have a simple GladeVCP panel with a button and textview component, python code is below.
Few times my code works fine, errors during G38.2 catching correctly:
But sometime it finished with OK, but it should not:
I think the problem is in error_poll() function, but I have no idea what I have missed. Hope for your help, guys.
Sources:
I trying to catch errors during executing G38.2 and sometime it works fine, but sometimes not... Please point me what I'm doing wrong.
I have a simple GladeVCP panel with a button and textview component, python code is below.
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import linuxcnc
from datetime import datetime
class HandlerClass:
# Prints message in following format: current time + text + LF code
def msg(self, text):
end_iter = self.buffer.get_end_iter()
self.buffer.insert(end_iter, "%s %s\n" % (datetime.now().strftime('%H:%M:%S'), text))
self.textview.scroll_to_mark(self.buffer.get_insert(), 0)
# Returns -1 if LinuxCNC error detected
def error_poll(self):
error = self.e.poll()
if error:
kind, text = error
if kind in (linuxcnc.NML_ERROR, linuxcnc.OPERATOR_ERROR):
return -1
return 0
# Switching to MDI mode
def set_mdi_mode(self):
self.command.mode( linuxcnc.MODE_MDI )
self.command.wait_complete()
# Switching to manual mode
def set_manual_mode(self):
self.command.mode( linuxcnc.MODE_MANUAL )
self.command.wait_complete()
# Line by line G-Code execution
def gcode(self, s):
for s in s.split("\n"):
self.command.mdi(s)
self.command.wait_complete()
if self.error_poll() == -1:
return -1
return 0
# On button click
def on_button_clicked(self, widget, data = None):
self.msg("Button pressed...");
# Set MDI mode
self.set_mdi_mode()
# A simple G-Code
cmd = """G91
G38.2 X-20 F300
G90"""
# Executing G-Code
if self.gcode(cmd) == -1:
self.msg("ERROR!")
else:
self.msg("OK!")
# Set manual mode
self.set_manual_mode()
# INIT FUNCTION
def __init__(self, halcomp, builder, useropts):
self.builder = builder
self.stat = linuxcnc.stat()
self.command = linuxcnc.command()
self.e = linuxcnc.error_channel()
self.textview = builder.get_object("textview")
self.buffer = self.textview.get_property('buffer')
# Welcome message
end_iter = self.buffer.get_end_iter()
self.buffer.insert(end_iter, "Welcome!\n\n")
# HANDLERS
def get_handlers(halcomp, builder, useropts):
return [HandlerClass(halcomp, builder, useropts)]
Few times my code works fine, errors during G38.2 catching correctly:
Attachment not found
But sometime it finished with OK, but it should not:
Attachment not found
I think the problem is in error_poll() function, but I have no idea what I have missed. Hope for your help, guys.
Sources:
Attachment not found
Please Log in to join the conversation.
6 years 1 month ago #182094
by cmorley
Replied by cmorley on topic GladeVCP + Python: error handling during G38.2
Error handling like this will not be reliable.
Linuxcnc can only send error messages to one reader.
it's a race condition on who gets it.
In qtvcp we worked around this by having qtvcp read the error then send that to all other registered listeners (using STATUS messages)
You would need to tap into AXIS's error handling some how and send a message to gladevcp (like maybe x11 client messages as AXIS slready has this capability) to do this.
it's not impossible but I'm not an AXIS expert.
Chris
Linuxcnc can only send error messages to one reader.
it's a race condition on who gets it.
In qtvcp we worked around this by having qtvcp read the error then send that to all other registered listeners (using STATUS messages)
You would need to tap into AXIS's error handling some how and send a message to gladevcp (like maybe x11 client messages as AXIS slready has this capability) to do this.
it's not impossible but I'm not an AXIS expert.
Chris
Please Log in to join the conversation.
6 years 1 month ago #182174
by aekhv
Replied by aekhv on topic GladeVCP + Python: error handling during G38.2
Hi Chris,
Thanks a lot for your reply, I have to think about it. Also I found another way (probably), I will try to get global parameter #5070 (G38 probe result) from my python code, maybe this will be best solution for me.
Thanks a lot for your reply, I have to think about it. Also I found another way (probably), I will try to get global parameter #5070 (G38 probe result) from my python code, maybe this will be best solution for me.
Please Log in to join the conversation.
6 years 1 month ago #182178
by cmorley
Replied by cmorley on topic GladeVCP + Python: error handling during G38.2
That's a great idea to try!
Please Log in to join the conversation.
6 years 1 month ago #182543
by aekhv
Replied by aekhv on topic GladeVCP + Python: error handling during G38.2
It looks like I found pretty simple and worked solution, the modified part of my source code is below:
Code:
...
# Line by line G-Code execution
def gcode(self, s):
for l in s.split("\n"):
self.command.mdi(l)
# Default wait_complete() timeout is 5 seconds,
# so 30 seconds should be enough for slow G38 operations
self.command.wait_complete(30)
#if self.error_poll() == -1:
# return -1
return 0
# On button click
def on_button_clicked(self, widget, data = None):
self.msg("Button pressed...");
# Set MDI mode
self.set_mdi_mode()
# A simple G-Code
cmd = """G91
G38.2 X-20 F300
G90"""
# Executing G-Code
self.gcode(cmd)
# Check probe status
self.stat.poll()
if self.stat.probe_tripped == False:
self.msg("ERROR!")
else:
self.msg("OK!")
# Set manual mode
self.set_manual_mode()
...
Please Log in to join the conversation.
Time to create page: 1.120 seconds
