|
1 | 1 | # node-gcode |
2 | 2 | GCode interpreter and simulator for node.js |
3 | 3 |
|
4 | | -To use: |
| 4 | +Installation |
| 5 | +------------ |
| 6 | +Install from npm |
| 7 | +``` |
| 8 | +npm install gcode |
| 9 | +``` |
5 | 10 |
|
| 11 | +Parsing a G-code File |
| 12 | +--------------------- |
6 | 13 | ```js |
7 | 14 | gcode = require('gcode') |
8 | 15 | gcode.parseFile('example.nc', function(err, data) { |
9 | | - console.log(data); |
| 16 | + console.log(JSON.stringify(data)); |
10 | 17 | }) |
11 | 18 | ``` |
12 | 19 |
|
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: |
14 | 23 |
|
15 | 24 | ```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":"+"}]]}] |
25 | 30 | ``` |
26 | 31 |
|
27 | 32 | G-code Interpreters |
|
0 commit comments