Page 1 of 2

M CODES!

Posted: Fri Sep 10, 2021 12:28 am
by ART
Hello, I am new here and new to gcodes and hoping to find some help.
What I'm trying to do via gcode write and string of letters and numbers to a .txt file using M120 and after each M120 use a .bat command file to read the string and use it as a variable to then associate it with .png file to display it, this even happens in several locations during the length of the gcode,
The problem is that the .txt file seams to be written at the end of the cycle so only the last M120/122 is recorded and the command calls the .dat file several more times than is called.
any suggestions? what am I missing.

Re: M CODES!

Posted: Fri Sep 10, 2021 12:37 am
by ART
[]this is how my .bat file looks like.

@echo off
FOR /F "tokens=* delims=" %%I in (C:\cncm\ncfiles\prtLABEL.txt) do (SET imagen=%%~nI)
Set MyVar=%imagen%
set MyVar=%MyVar: =%

"C:\Users\FileEXAMPLE\OutSide_K_Image\%MyVar%.bmp"

PAUSE

Re: M CODES!

Posted: Fri Sep 10, 2021 12:24 pm
by Sword
Not sure if I'm following you exactly, but each time M120 is passed, it will close the previous file and open a new one, overwriting the existing one. So you'll only get the last value. You might need to use a M00, M01, or M224/225 to wait for the bat file to do it's thing. There's also a L1 parameter for M130, but not sure what the outcome for that is, meaning can you continue after the shell command.

Others may chime in here, but we might need the whole file set to test along with you.

Re: M CODES!

Posted: Fri Sep 10, 2021 12:33 pm
by ART
Yes!, thanks for your help, in fact every time M120 is called M125 writes the text and M150 is immediately call to execute the information, then the machine moves to a different coordinate and does it all again.
regardless of what I do I only get the last call and .bat is called 3 times at once.

Re: M CODES!

Posted: Fri Sep 10, 2021 12:39 pm
by ART
Sword wrote: Fri Sep 10, 2021 12:24 pm Not sure if I'm following you exactly, but each time M120 is passed, it will close the previous file and open a new one, overwriting the existing one. So you'll only get the last value. You might need to use a M00, M01, or M224/225 to wait for the bat file to do it's thing. There's also a L1 parameter for M130, but not sure what the outcome for that is, meaning can you continue after the shell command.

Others may chime in here, but we might need the whole file set to test along with you.
I just updated my atest.cnc file to reflect a little better the real work it does or should do, hopefully. :!:

Re: M CODES!

Posted: Fri Sep 10, 2021 12:50 pm
by cncsnw
You might also need to put additional M120 calls between each operation.

For example:

Code: Select all

M120 "dummy.txt"
By using M120 to open a different file, you force CNC12 to flush and close the one that it previously had open. That should ensure that the contents have been written by the time you call M130.

Re: M CODES!

Posted: Fri Sep 10, 2021 2:31 pm
by ART
cncsnw wrote: Fri Sep 10, 2021 12:50 pm You might also need to put additional M120 calls between each operation.

For example:

Code: Select all

M120 "dummy.txt"
By using M120 to open a different file, you force CNC12 to flush and close the one that it previously had open. That should ensure that the contents have been written by the time you call M130.
yep, tried that and I'm still getting 3 extra .bat running at the same time for the first iteration and 1 for the second.
thanks for your help, I'm looking forward to find this bug and kill it.
atest.cnc
(943 Bytes) Downloaded 68 times

Re: M CODES!

Posted: Fri Sep 10, 2021 3:53 pm
by eng199
ART wrote: Fri Sep 10, 2021 2:31 pm yep, tried that and I'm still getting 3 extra .bat running at the same time for the first iteration and 1 for the second.
Are your runtime graphics on (parameter 150)? The plot is executing the .bat file extra times.

Try opening your file again with M121 before M130 to flush the data.
Also try M130 L1 command with a pause in the .bat to get a better idea when the command is actually running.

Re: M CODES!

Posted: Fri Sep 10, 2021 3:57 pm
by ART
eng199 wrote: Fri Sep 10, 2021 3:53 pm
ART wrote: Fri Sep 10, 2021 2:31 pm yep, tried that and I'm still getting 3 extra .bat running at the same time for the first iteration and 1 for the second.
Are your runtime graphics on (parameter 150)? The plot is executing the .bat file extra times.

Try opening your file again with M121 before M130 to flush the data.
Also try M130 L1 command with a pause in the .bat to get a better idea when the command is actually running.
*** Please advice me with syntax on the M130 L1.. I've not used it before, would you post an example of how to, please.
thanks
*** I'm displaying a .bmp file

Re: M CODES!

Posted: Fri Sep 10, 2021 4:04 pm
by eng199
Just toss an L1 in there like so:
M130 L1 "C:\cncm\ncfiles\print.bat"

page 13-16 in the v3.16 Mill manual I was looking at