Python interface how to detect file is not open?
09 Feb 2019 06:26 #126037
by bladekel
Python interface how to detect file is not open? was created by bladekel
Hello to all...
I'm trying to create a custom ui with python and I need to detect if an ngc file couldnt opened succesfully.
For this problem I'm using interpreter_errcode like;
self.s = self.emc.stat()
self.s.interpreter_errcode
but there is no return with this code..
Can anyone help me?
I'm trying to create a custom ui with python and I need to detect if an ngc file couldnt opened succesfully.
For this problem I'm using interpreter_errcode like;
self.s = self.emc.stat()
self.s.interpreter_errcode
but there is no return with this code..
Can anyone help me?
Please Log in or Create an account to join the conversation.
09 Feb 2019 11:03 #126043
by BigJohnT
Replied by BigJohnT on topic Python interface how to detect file is not open?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import linuxcnc
try:
s = linuxcnc.stat() # create a connection to the status channel
s.poll() # get current values
except linuxcnc.error, detail:
print "error", detail
sys.exit(1)
s.file # returns the current loaded file
The following user(s) said Thank You: bladekel
Please Log in or Create an account to join the conversation.
09 Feb 2019 11:59 #126052
by cmorley
Replied by cmorley on topic Python interface how to detect file is not open?
I might add that you should check the file name (using linuxcnc status) before you load the program, then check it after. If they are the same then the program probably loaded file.
eg gladevcp doe it like this (the code wont work for you but the idea is good):
def _load_file(self, filename):
if filename:
self.linuxcnc.mode(linuxcnc.MODE_AUTO)
old = self.gstat.stat.file
self.linuxcnc.program_open(filename)
if old == filename:
self.gstat.emit('file-loaded', filename)
eg gladevcp doe it like this (the code wont work for you but the idea is good):
def _load_file(self, filename):
if filename:
self.linuxcnc.mode(linuxcnc.MODE_AUTO)
old = self.gstat.stat.file
self.linuxcnc.program_open(filename)
if old == filename:
self.gstat.emit('file-loaded', filename)
The following user(s) said Thank You: bladekel
Please Log in or Create an account to join the conversation.
11 Feb 2019 08:47 #126192
by bladekel
Replied by bladekel on topic Python interface how to detect file is not open?
Thanks bro. Thats the way....
Please Log in or Create an account to join the conversation.
Time to create page: 0.128 seconds