Commit dff07ac1 authored by Chris DeLuca's avatar Chris DeLuca

Add syntax highlighting to readme code samples

parent e38998cc
...@@ -187,19 +187,21 @@ To use printcore you need python (ideally 2.6.x or 2.7.x) and pyserial (or pytho ...@@ -187,19 +187,21 @@ To use printcore you need python (ideally 2.6.x or 2.7.x) and pyserial (or pytho
See pronsole for an example of a full-featured host, the bottom of printcore.py for a simple command-line See pronsole for an example of a full-featured host, the bottom of printcore.py for a simple command-line
sender, or the following code example: sender, or the following code example:
#to send a file of gcode to the printer ```python
from printrun.printcore import printcore #to send a file of gcode to the printer
from printrun import gcoder from printrun.printcore import printcore
p=printcore('/dev/ttyUSB0',115200) # or p.printcore('COM3',115200) on Windows from printrun import gcoder
gcode=[i.strip() for i in open('filename.gcode')] # or pass in your own array of gcode lines instead of reading from a file p=printcore('/dev/ttyUSB0',115200) # or p.printcore('COM3',115200) on Windows
gcode = gcoder.LightGCode(gcode) gcode=[i.strip() for i in open('filename.gcode')] # or pass in your own array of gcode lines instead of reading from a file
p.startprint(gcode) # this will start a print gcode = gcoder.LightGCode(gcode)
p.startprint(gcode) # this will start a print
#If you need to interact with the printer:
p.send_now("M105") # this will send M105 immediately, ahead of the rest of the print #If you need to interact with the printer:
p.pause() # use these to pause/resume the current print p.send_now("M105") # this will send M105 immediately, ahead of the rest of the print
p.resume() p.pause() # use these to pause/resume the current print
p.disconnect() # this is how you disconnect from the printer once you are done. This will also stop running prints. p.resume()
p.disconnect() # this is how you disconnect from the printer once you are done. This will also stop running prints.
```
## PLATERS ## PLATERS
...@@ -225,10 +227,12 @@ When the 3D viewer is enabled, the controls are the following: ...@@ -225,10 +227,12 @@ When the 3D viewer is enabled, the controls are the following:
on localhost port 7978, which provides print progress information. on localhost port 7978, which provides print progress information.
Here is a sample Python script querying the print status: Here is a sample Python script querying the print status:
import xmlrpclib ```python
import xmlrpclib
rpc = xmlrpclib.ServerProxy('http://localhost:7978') rpc = xmlrpclib.ServerProxy('http://localhost:7978')
print rpc.status() print rpc.status()
```
## CONFIGURATION ## CONFIGURATION
...@@ -271,94 +275,110 @@ All macros are saved automatically immediately after being entered. ...@@ -271,94 +275,110 @@ All macros are saved automatically immediately after being entered.
Example 1, simple one-line alias: Example 1, simple one-line alias:
PC> macro where M114 ```python
PC> macro where M114
```
Instead of having to remember the code to query position, you can query the position: Instead of having to remember the code to query position, you can query the position:
PC> where ```python
X:25.00Y:11.43Z:5.11E:0.00 PC> where
X:25.00Y:11.43Z:5.11E:0.00
```
Example 2 - macros to switch between different slicer programs, using "set" command to change options: Example 2 - macros to switch between different slicer programs, using "set" command to change options:
PC> macro use_slicer ```python
Enter macro using indented lines, end with empty line PC> macro use_slicer
..> set sliceoptscommand Slic3r/slic3r.exe --load slic3r.ini Enter macro using indented lines, end with empty line
..> set slicecommand Slic3r/slic3r.exe $s --load slic3r.ini --output $o ..> set sliceoptscommand Slic3r/slic3r.exe --load slic3r.ini
Macro 'use_slicer' defined ..> set slicecommand Slic3r/slic3r.exe $s --load slic3r.ini --output $o
PC> macro use_sfact Macro 'use_slicer' defined
..> set sliceoptscommand python skeinforge/skeinforge_application/skeinforge.py PC> macro use_sfact
..> set slicecommand python skeinforge/skeinforge_application/skeinforge_utilities/skeinforge_craft.py $s ..> set sliceoptscommand python skeinforge/skeinforge_application/skeinforge.py
Macro 'use_sfact' defined ..> set slicecommand python skeinforge/skeinforge_application/skeinforge_utilities/skeinforge_craft.py $s
Macro 'use_sfact' defined
```
Example 3, simple parametric macro: Example 3, simple parametric macro:
PC> macro move_down_by ```python
Enter macro using indented lines, end with empty line PC> macro move_down_by
..> G91 Enter macro using indented lines, end with empty line
..> G1 Z-{0} ..> G91
..> G92 ..> G1 Z-{0}
..> ..> G92
..>
```
Invoke the macro to move the printhead down by 5 millimeters: Invoke the macro to move the printhead down by 5 millimeters:
PC> move_down_by 5 ```python
PC> move_down_by 5
```
For more powerful macro programming, it is possible to use python code escaping using ! symbol in front of macro commands. For more powerful macro programming, it is possible to use python code escaping using ! symbol in front of macro commands.
Note that this python code invocation also works in interactive prompt: Note that this python code invocation also works in interactive prompt:
PC> !print "Hello, printer!" ```python
Hello printer! PC> !print "Hello, printer!"
Hello printer!
PC> macro debug_on !self.p.loud = 1
Macro 'debug_on' defined PC> macro debug_on !self.p.loud = 1
PC> debug_on Macro 'debug_on' defined
PC> M114 PC> debug_on
SENT: M114 PC> M114
X:0.00Y:0.00Z:0.00E:0.00 Count X:0.00Y:0.00Z:0.00 SENT: M114
RECV: X:0.00Y:0.00Z:0.00E:0.00 Count X:0.00Y:0.00Z:0.00 X:0.00Y:0.00Z:0.00E:0.00 Count X:0.00Y:0.00Z:0.00
RECV: ok RECV: X:0.00Y:0.00Z:0.00E:0.00 Count X:0.00Y:0.00Z:0.00
RECV: ok
```
You can use macro command itself to create simple self-modify or toggle functionality: You can use macro command itself to create simple self-modify or toggle functionality:
Example: swapping two macros to implement toggle: Example: swapping two macros to implement toggle:
PC> macro toggle_debug_on ```python
Enter macro using indented lines, end with empty line PC> macro toggle_debug_on
..> !self.p.loud = 1 Enter macro using indented lines, end with empty line
..> !print "Diagnostic information ON" ..> !self.p.loud = 1
..> macro toggle_debug toggle_debug_off ..> !print "Diagnostic information ON"
..> ..> macro toggle_debug toggle_debug_off
Macro 'toggle_debug_on' defined ..>
PC> macro toggle_debug_off Macro 'toggle_debug_on' defined
Enter macro using indented lines, end with empty line PC> macro toggle_debug_off
..> !self.p.loud = 0 Enter macro using indented lines, end with empty line
..> !print "Diagnostic information OFF" ..> !self.p.loud = 0
..> macro toggle_debug toggle_debug_on ..> !print "Diagnostic information OFF"
..> ..> macro toggle_debug toggle_debug_on
Macro 'toggle_debug_off' defined ..>
PC> macro toggle_debug toggle_debug_on Macro 'toggle_debug_off' defined
Macro 'toggle_debug' defined PC> macro toggle_debug toggle_debug_on
Macro 'toggle_debug' defined
```
Now, each time we invoke "toggle_debug" macro, it toggles debug information on and off: Now, each time we invoke "toggle_debug" macro, it toggles debug information on and off:
PC> toggle_debug ```python
Diagnostic information ON PC> toggle_debug
Diagnostic information ON
PC> toggle_debug
Diagnostic information OFF PC> toggle_debug
Diagnostic information OFF
```
When python code (using ! symbol) is used in macros, it is even possible to use blocks/conditionals/loops. When python code (using ! symbol) is used in macros, it is even possible to use blocks/conditionals/loops.
It is okay to mix python code with pronsole commands, just keep the python indentation. It is okay to mix python code with pronsole commands, just keep the python indentation.
For example, following macro toggles the diagnostic information similarily to the previous example: For example, following macro toggles the diagnostic information similarily to the previous example:
!if self.p.loud: ```python
!self.p.loud = 0 !if self.p.loud:
!print "Diagnostic information OFF" !self.p.loud = 0
!else: !print "Diagnostic information OFF"
!self.p.loud = 1 !else:
!print "Diagnostic information ON" !self.p.loud = 1
!print "Diagnostic information ON"
```
Macro parameters are available in '!'-escaped python code as locally defined list variable: arg[0] arg[1] ... arg[N] Macro parameters are available in '!'-escaped python code as locally defined list variable: arg[0] arg[1] ... arg[N]
...@@ -369,20 +389,24 @@ Therefore it is best to use pronsole commands, which easily contain majority of ...@@ -369,20 +389,24 @@ Therefore it is best to use pronsole commands, which easily contain majority of
Some useful python-mode-only variables: Some useful python-mode-only variables:
!self.settings - contains all settings, e.g. ```python
port (!self.settings.port), baudrate, xy_feedrate, e_feedrate, slicecommand, final_command, build_dimensions !self.settings - contains all settings, e.g.
You can set them also via pronsole command "set", but you can query the values only via python code. port (!self.settings.port), baudrate, xy_feedrate, e_feedrate, slicecommand, final_command, build_dimensions
!self.p - printcore object (see USING PRINTCORE section for using printcore object) You can set them also via pronsole command "set", but you can query the values only via python code.
!self.cur_button - if macro was invoked via custom button, the number of the custom button, e.g. for usage in "button" command !self.p - printcore object (see USING PRINTCORE section for using printcore object)
!self.gwindow - wx graphical interface object for pronterface (highly risky to use because the GUI implementation details may change a lot between versions) !self.cur_button - if macro was invoked via custom button, the number of the custom button, e.g. for usage in "button" command
!self.gwindow - wx graphical interface object for pronterface (highly risky to use because the GUI implementation details may change a lot between versions)
```
Some useful methods: Some useful methods:
!self.onecmd - invokes raw command, e.g. ```python
!self.onecmd("move x 10") !self.onecmd - invokes raw command, e.g.
!self.onecmd("!print self.p.loud") !self.onecmd("move x 10")
!self.onecmd("button "+self.cur_button+" fanOFF /C cyan M107") !self.onecmd("!print self.p.loud")
!self.project - invoke Projector !self.onecmd("button "+self.cur_button+" fanOFF /C cyan M107")
!self.project - invoke Projector
```
## USING HOST COMMANDS ## USING HOST COMMANDS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment