Sitelet https://github.com/ryansturmer/node-gcode/commit/df4c3e8c2da542fbf48fa222e6b4f1d2ad7cee51
Skip to content

Commit df4c3e8

Browse files
committed
Update README.md
1 parent 16760a5 commit df4c3e8

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

‎README.md‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
# node-gcode
22
GCode interpreter and simulator for node.js
33

4-
To use:
4+
Installation
5+
------------
6+
Install from npm
7+
```
8+
npm install gcode
9+
```
510

11+
Parsing a G-code File
12+
---------------------
613
```js
714
gcode = require('gcode')
815
gcode.parseFile('example.nc', function(err, data) {
9-
console.log(data);
16+
console.log(JSON.stringify(data));
1017
})
1118
```
1219

13-
The data returned by the `parseFile` callback is a list of G-code blocks, where every block is an object mapping word letters (G, M, X,Y,Z, etc) to their arguments. Every G-code block includes a line number, which appears as an N-word (lol) even if no line number was supplied in the original G-code file. In this case, the N-word is null. In most cases, the arguments are simply numbers, but in the case of an expression, parameter value, or unary operator value, the arguments are returned as an expression tree that must be evaluated.
20+
The data returned by the `parseFile` callback is a list of G-code blocks, where each block is an object with a `num` property (the G-code line number) and a `words` property (the list of G-code words on that line) Each G-code word is a list of two items, the word letter (G, M, X,Y,Z, etc.) and the word argument. Word arguments are typically numbers, but the parser supports full expressions, including parameter values, so in the event that an expression or parameter value is provided, an expression-tree-like object is returned that must be evaluated. Currently, this is left as an exercise for the reader.
21+
22+
The output of the above example might look like this:
1423

1524
```js
16-
[ { N: null, G: 17 },
17-
{ N: null, G: 1, X: 1, Y: 2, Z: 3, F: 120 },
18-
{ N: null, G: 1, Z: 0 },
19-
{ N: null, G: 1, Z: -0.125, F: 240 },
20-
{ N: null, G: 2, I: 2, J: 3.5, K: 0 },
21-
{ N: null, G: 1, X: 1, Y: 3 },
22-
{ N: null, G: 1, X: 0, Y: 0, Z: 0 },
23-
{ N: null, G: 0, X: 0, Y: 0, Z: 0, F: 300 },
24-
{ N: null, G: 0, X: { left: 3, right: 5, op: '+' } } ]
25+
[{"N":null,"words":[["G",17]]},
26+
{"N":null,"words":[["G",1],["X",1],["Y",2],["Z",3],["F",120]]},
27+
{"N":null,"words":[["G",1],["Z",0]]},
28+
{"N":null,"words":[["G",1],["Z",-0.125],["F",240]]},
29+
{"N":null,"words":[["G",0],["X",{"left":3,"right":5,"op":"+"}]]}]
2530
```
2631

2732
G-code Interpreters

0 commit comments

Comments
 (0)