# Extrude Documentation

## Introduction

Extrude requires pySerial installed for this module to work. If you are using Fedora it is available on yum (run "sudo yum install pyserial").
To actually control the reprap requires write access to the serial device, running as root is one way to get that access.
Extrude is a python script to display and extrude a gcode file. It controls the extruder and movement. It can read linear and helical move commands. It saves a log file with the suffix _log.

## Example

This example displays and extrudes a gcode file. This example is run in a terminal as root in the folder which contains Hollow Square.gcode, and extrude.py.

    >>> import reprap.extrude as extrude
    Extrude has been imported.
    The gcode files in this directory that are not log files are the following:
    ['Hollow Square.gcode']

    >>> extrude.display()
    File Hollow Square.gcode is being displayed.
    reprap.serial = serial.Serial(0, 19200, timeout = 60)
    reprap.cartesian.x.active = True
    reprap.cartesian.y.active = True
    reprap.cartesian.z.active = True
    reprap.extruder.active = True
    reprap.cartesian.x.setNotify()
    reprap.cartesian.y.setNotify()
    reprap.cartesian.z.setNotify()
    reprap.cartesian.x.limit = 2523
    reprap.cartesian.y.limit = 2000
    reprap.cartesian.homeReset( 200, True )
    ( GCode generated by March 29,2007 Skeinforge )
    ( Extruder Initialization )
    M100 P210
    M103
    reprap.extruder.setMotor(reprap.CMD_REVERSE, 0)
    ..
    many lines of gcode and extruder commands
    ..
    reprap.cartesian.homeReset( 600, True )
    reprap.cartesian.free()
    The gcode log file is saved as Hollow Square_log.gcode

    >>> extrude.displayFile("Hollow Square.gcode")
    File Hollow Square.gcode is being displayed.
    ..
    The gcode log file is saved as Hollow Square_log.gcode

    >>> extrude.displayFiles(["Hollow Square.gcode"])
    File Hollow Square.gcode is being displayed.
    ..
    The gcode log file is saved as Hollow Square_log.gcode

    >>> extrude.displayText("
    ( GCode generated by March 29,2007 Skeinforge )
    ( Extruder Initialization )
    ..
    many lines of gcode
    ..
    ")

    reprap.serial = serial.Serial(0, 19200, timeout = 60)
    reprap.cartesian.x.active = True
    reprap.cartesian.y.active = True
    reprap.cartesian.z.active = True
    reprap.extruder.active = True
    reprap.cartesian.x.setNotify()
    reprap.cartesian.y.setNotify()
    reprap.cartesian.z.setNotify()
    reprap.cartesian.x.limit = 2523
    reprap.cartesian.y.limit = 2000
    reprap.cartesian.homeReset( 200, True )
    ( GCode generated by March 29,2007 Skeinforge )
    ( Extruder Initialization )
    M100 P210
    M103
    reprap.extruder.setMotor(reprap.CMD_REVERSE, 0)
    ..
    many lines of gcode and extruder commands
    ..
    reprap.cartesian.homeReset( 600, True )
    reprap.cartesian.free()

    Note: On my system the reprap is not connected, so I get can not connect messages, like:

    >>> extrude.extrude()
    File Hollow Square.gcode is being extruded.
    reprap.serial = serial.Serial(0, 19200, timeout = 60)
    reprap.cartesian.x.active = True
    reprap.cartesian.y.active = True
    reprap.cartesian.z.active = True
    reprap.extruder.active = True
    reprap.cartesian.x.setNotify()
    Error: Serial timeout
    Error: ACK not recieved
    ..

    On a system where a reprap is connected to the serial port, you should get the following:

    >>> extrude.extrude()
    File Hollow Square.gcode is being extruded.
    ..
    The gcode log file is saved as Hollow Square_log.gcode

    >>> extrude.extrudeFile("Hollow Square.gcode")
    File Hollow Square.gcode is being extruded.
    ..
    The gcode log file is saved as Hollow Square_log.gcode

    >>> extrude.extrudeFiles(["Hollow Square.gcode"])
    File Hollow Square.gcode is being extruded.
    ..
    The gcode log file is saved as Hollow Square_log.gcode

    >>> extrude.extrudeText("
    ( GCode generated by March 29,2007 Skeinforge )
    ( Extruder Initialization )
    ..
    many lines of gcode
    ..
    ")

    reprap.serial = serial.Serial(0, 19200, timeout = 60)
    reprap.cartesian.x.active = True
    reprap.cartesian.y.active = True
    reprap.cartesian.z.active = True
    reprap.extruder.active = True
    reprap.cartesian.x.setNotify()
    reprap.cartesian.y.setNotify()
    reprap.cartesian.z.setNotify()
    reprap.cartesian.x.limit = 2523
    reprap.cartesian.y.limit = 2000
    reprap.cartesian.homeReset( 200, True )
    ( GCode generated by March 29,2007 Skeinforge )
    ( Extruder Initialization )
    M100 P210
    M103
    reprap.extruder.setMotor(reprap.CMD_REVERSE, 0)
    ..
    many lines of gcode and extruder commands
    ..
    reprap.cartesian.homeReset( 600, True )
    reprap.cartesian.free()

## Display Commands

### display

Parse a gcode file and display the commands.
extrude.display( filename = '' )

- filename - Name of the file. If no filename is specified, parse all the gcode files which are not log files in this folder.

Returns: Nothing

### displayFile

Parse a gcode file and display the commands.
extrude.displayFile( filename )

- filename - Name of the file.

Returns: Nothing

### displayFiles

Parse gcode files and display the commands.
extrude.displayFiles( filenames )

- filenames - List of filenames.

Returns: Nothing

### displayText

Parse a gcode text and display the commands.
extrude.displayText( gcodeText )

- gcodeText - Gcode text.

Returns: Gcode text and commands.

## Extrude Commands

### extrude

Parse a gcode file and send the commands to the extruder. This function requires write access to the serial device, running as root is one way to get that access.
extrude.extrude( filename = '' )

- filename - Name of the file. If no filename is specified, parse all the gcode files which are not log files in this folder.

Returns: Nothing

### extrudeFile

Parse a gcode file and send the commands to the extruder. This function requires write access to the serial device, running as root is one way to get that access.
extrude.extrudeFile( filename )

- filename - Name of the file.

Returns: Nothing

### extrudeFiles

Parse gcode files and send the commands to the extruder. This function requires write access to the serial device, running as root is one way to get that access.
extrude.extrudeFiles( filenames )

- filenames - List of filenames.

Returns: Nothing

### extrudeText

Parse a gcode text and send the commands to the extruder. This function requires write access to the serial device, running as root is one way to get that access.
extrude.extrudeText( gcodeText )

- gcodeText - Gcode text.

Returns: Gcode text and commands.