Redirecting output of command to a file, how?
-
I am completely new to Gcode metacommands, sorry. I am trying to write an event macro file and would like to redirect the output of a command to another file. How do I do that?
For example:
In the macro file driver-stall.g I would like to redirect the output of M114 (get current position) to the file driver-stall.txt. I tried this:
echo >>"driver-stall.txt M114
but it does not work. I get
Error: line 4 column 27: meta command: unknown value 'M114'After reading the corresponding documentation I could not find or recognize a solution, give me a hint please.
-
@Triet Alright, after "rewording" the command this way
M114 >>"driver-stall.txt"
I get no error, but the output of M114 is not redirected, it is displayed in the console instead.
Getting nearer, but I still need your help, thanks. -
@Triet There isn't a way to redirect the output of a command to a file, apart from using event logging with M929. echo is used to write a text string, not the response of a command, either to the console or a file. Also, the M114 can't take the >> modifier to send it's output elsewhere, so that won't work either.
M114 effectively just reports values from the Object Model. So you could just query the OM directly and output that using echo, eg:
echo >>position.txt "X:" ^ move.axes[0].userPosition , "Y:" ^ move.axes[1].userPosition , "Z:" ^ move.axes[2].userPosition , "E0:" ^ move.extruders[0].position
This will create a file called "position.txt" in the /sys folder, with something like the following in it:
X:50.000 Y:0.000 Z:10.000 E0:-0.0
userPosition is the position at the end of the current move. If you want the current position during a move, use move.axes[0].machinePosition. You can look up the variables in the Object Model plug in if you need others to be reported.
Ian
-
I would like to redirect the output of M114 (get current position) to the file driver-stall.txt.
From the GCode dictionary, M114:
Note: there is no agreed definition of what the response to M114 should be. We try to keep the M114 response compatible with other firmwares as far as we can, but this is not always possible. Users writing applications which need to fetch current positions from RepRapFirmware 3 are recommended to use object model queries instead.
So, querying the object model is the way to go. You need to become familiar with the GCode meta commands - looks like you already came across that.
As usual, @droftarts was faster, so I just add a (tested) sample of how to write some coordinates from the object model into an executable G92 command in the macro file whose name is stored in the variable var.fName:
echo >>{var.fName} "G92 X"^{move.axes[0].machinePosition}^" Y"^{move.axes[1].machinePosition}^" Z"^{move.axes[2].machinePosition}
-
@infiniteloop @droftarts
Thanks, with your help I managed to achieve my goal.
I come accross with metacommands every other month or so, I think I need to engage more systematically in that matter.