- Posts: 66
- Thank you received: 0
Python interface how to detect file is not open?
7 years 8 months ago #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 to join the conversation.
7 years 8 months ago #126043
by BigJohnT
Replied by BigJohnT on topic Python interface how to detect file is not open?
Code:
#!/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
Please Log in to join the conversation.
7 years 8 months ago #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)
Please Log in to join the conversation.
Time to create page: 0.075 seconds
