python M-CODE to write active program on a file

More
06 Apr 2022 15:57 #239450 by ioiotutu
Hi,
i try to write the active program name on a file with M190 code inside g-code program. For this i created M190 file:

************************************ M190 code
#!/usr/bin/env python
import sys
import hal
import linuxcnc
import time

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)

x=s.file.split("/")
prg_file=open('/home/max/test', 'a')
prg_file.write(time.strftime("%Y/%m/%d")+','+ time.strftime("%H:%M:%S") +','+ x[len(x)-1] '+'\n')
prg_file.close()
*********************************** end M190 code

G-Code name file example test.ngc:

G90
G0X0Y0
M190
M2

All work fine, into the file test there is "test.ngc" string with date and time.
I have a problem if inside the g-code file there is a tool change call (M6T1).
I have remapped M6 code to a soubroutine "change.ngc" that run on M6Txx call and after M190 call i find into the file the string "change.ngc" instead of "test.ngc".
Probably python code "s.file" read the last called soubroutine !
Is there a way to read active program from axis interface?
I would do a logfile where inside there is   g-code program name+date+time  to count  program worked in a day.

Thanks,
Michele
 

Please Log in or Create an account to join the conversation.

More
07 Apr 2022 00:26 #239485 by cakeslob
os.path.basename(loaded_file)
This is what im using to get the currently loaded file in axis. Im not sure if it will do the same thing with a remap

Please Log in or Create an account to join the conversation.

More
07 Apr 2022 06:56 #239511 by ioiotutu
os.path.basename(loaded_file) method return the tail of path of "loaded_file".
If loaded_file="/home/max/aaa.ngc"

os.path.basename(loaded_file) return "aaa.ngc"

How to assign loaded_file ?

Thanks.

Please Log in or Create an account to join the conversation.

Time to create page: 0.190 seconds
Powered by Kunena Forum