Protocol Syntax
Protocol Overview
Commands will be sent in packets. All commands are query/response. The master in each pair will always initiate communications, never the slave. All packets are synchronous; they will wait for a response from the reprap before sending the next packet. The firmware will continue rendering buffered commands while receiving new commands and replying to them.
Command Buffering
To ensure smooth motion, as well as to support print queueing, we'll want certain commands to be queued in a buffer. This means we won't get immediate feedback from any queued command. To this end we will break commands down into two categories: action commands that are put in the command buffer, and query commands that require an immediate response. In order to make it simple to differentiate the commands on the firmware side, we will break them up into two sets: commands numbered 0-127 will be query commands, and commands numbered 128-255 will be action commands to be put into the buffer. The firmware can then simply look at the highest bit to determine which type of packet it is.
Every packet gets precisely one response packet. Action commands can be batched and sent as a single packet, which will get a single response (error) code. Query commands must be sent in their own packet. Only action or query commands can be sent in a single packet. The first byte of the command payload will determine the nature of the entire packet. Thus, you cannot mix query and action commands in a single packet!
Command Types
Range
| Type
| Description
|
0-127
| Query Commands
| Commands that can be executed immediately, and thus do not need to be queued. Generally return pre-calculated information and should be fast.
|
128-255
| Action Commands
| Commands that must be executed one at a time, and in a particular order. These commands should be buffered for smooth operation. Many of there commands may take up a large amount of time to complete.
|
Packet structure
Command packets are sent from the Master to the Slave. This can either be from the Host CPU to the Master uC or from the Master uC to the Slave uC. It consists of a two-byte header, a variable-length payload, and a 1 byte CRC footer.
The packet consists of:
Index
|
Name
|
Details
|
0
|
Start byte
|
This byte always has the value 0xD5 and is used to ensure synchronization.
|
1
|
Length
|
This byte indicates the length of the payload (excluding the header and CRC) in bytes.
|
2...
|
Payload
|
The packet payload. This is appended to the buffer and either immediately executed and removed (if a query type) or buffered for execution (if an action type).
|
Length+2
|
CRC
|
This is the 8-bit iButton/Maxim CRC of the payload.
|
Command length is implicit in the command structure; no explicit separator is needed.
Command structure
The payload of a packet consists of one or more commands. Each command contains a header, as follows:
Index
|
Name
|
Details
|
0
|
Command
|
The command code to send to the device.
|
1-N
|
Arguments
|
Arguments to this command (details below as 'command payload').
|
Response Packets
Response packets look just like command packets. The only difference is the payload is always guaranteed to contain a response code as the first byte, as described below.
Response Packet Payload Structure
Index
|
Name
|
Details
|
0
|
Response Code
|
This is a standard response code that is included with all packets and is described below.
|
1-N
|
Response Data
|
This contains response-specific data. Length is implicit based on the command being responded-to.
|
If the command was a non-request command, the response data is always empty.
Response Code Values
Response Code
|
Interpretation
|
0
|
Generic error, packet discarded.
|
1
|
Success.
|
2
|
Action buffer overflow, entire packet discarded.
|
3
|
CRC mismatch, packet discarded.
|
4
|
Query packet too big, packet discarded.
|
5
|
Command not supported.
|
6
| Success; expect more packets. Used when a single reponse packet cannot contain the entire message to be retrieved.
|
Data Formats
The protocol is a byte-oriented protocol. Payloads may contain various information in a variety of formats, but will generally be limited to the formats described below. Multi-byte datatypes will always be transmitted in Little-endian mode. Remember, this means that the least significant byte ("littlest") byte is sent first! For a more in-depth discussionof little-endian storage, see:
http://en.wikipedia.org/wiki/Endianness#Little-endianVarious Data Types
Type
| Range
|
uint8
| 0 to 255
|
uint16
| 0 to 65,535
|
int16
| -32767 to 32,767
|
| uint32 | 0 to 4,294,967,295
|
int32
| -2,147,483,647 to 2,147,483,647
|
Master Microcontroller Commands (3-axis controller)
0 - Get Version - Query firmware for version information
This command allows the host and firmware to exchange version numbers. It also allows for simple automated discovery of the firmware. Version numbers will always be stored as a single number, Arduino / Processing style. Thus, the versions will be 0 to 65535.
Payload (2 bytes) - host version
uint16: Host Version.
Response (2 bytes) - firmware version
uint16: Firmware Version
1 - Init - Initialize firmware to boot state
Initialization consists of:
-
resetting current position to 0,0,0
-
clearing command buffer
-
setting range to eeprom value (if it exists) otherwise its 0.
Payload (0 bytes)
Response (0 bytes)
2 - Get Available Buffer Size - Determine how much free memory we have for buffering.
This command will let us know how much buffer space we have available for action commands. It can be used to determine if and when the buffer is available for writing. If we are writing to the SD card, it will generally always report the maximum number of bytes available.
Payload (0 bytes)
Response (4 bytes)
uint32: number of bytes available in the command buffer.
3 - Clear Buffer - Empty the command buffer
This command will empty our buffer, and reset all pointers, etc to the beginning of the buffer. If writing to an SD card, it will reset the file pointer back to the beginning of the currently open file. Obviously, it should halt all execution of action commands as well.
Payload (0 bytes)
Response (0 bytes)
4 - Get Position - Get the current position of the tool
Useful for determining current position of the toolhead. It is up to the host software to add or subtract the toolhead offset to determine the actual position of the toolhead. It will also return the status of the various endstops for diagnostic information.
Payload (0 bytes)
Response (13 bytes)
int32: current x position, in steps
int32: current y position, in steps
int32: current z position, in steps
uint8: bits marked for endstop status: (7-0) : | N/A | N/A | z max | z min | y max | y min | x max | x min |
5 - Get Range - Get the maximum range of travel on all axes.
When find axes maximums is called, it will record the maximum as the range. internally, it will keep track of its range and this function will simply report that internal value. We cannot assume that there are endstop switches for all axes at both min and max positions. The firmware will know this, so the "Find Axes min/max" commands may be partially no-ops in this case. The firmware should always respect this range and never go beyond it.
Payload (0 bytes)
Response (12 bytes)
uint32: x range, units in steps
uint32: y range, units in steps
uint32: z range, units in steps
6 - Set Range - Set the maximum range of travel on all axes.
This command tells the firmware what its maximum range of travel is. The firmware should always respect this. This should be recorded into the eeprom for future usage.
Payload (12 bytes)
uint32: x range, units in steps
uint32: y range, units in steps
uint32: z range, units in steps
Response (0 bytes)
7 - Abort Immediately - Stop Machine, Shut Down Job Permanently
This function is intended to be used to terminate a print during printing. Extruder and accessories off, steppers disabled, everything shuts down.
Payload (0 bytes)
Response (0 bytes)
8 - Pause / Unpause - Halt Execution Temporarily
This function is intended to be called infrequently by the end-user in order to make build-time adjustments immediately and easily. No buffers or other run-time variables are changed. The pause command should also prompt the firmware to send a pause command to the toolhead.
On pause, it stops all movement, stops extrusion, moves up a 'safe z' amount, and waits for new commands.
On unpause, it lowers to original Z, optionally restarts extrusion, and resumes movement.
agm: Currently we do not do the "safe Z" backoff. I'd like to introduce that as a parameter instead.
Payload (0 bytes)
Response (0 bytes)
9 - Probe - Move in Z axis (negative) until probe hits something
This command will wait until the buffer is clear to avoid conflicts. It will also prevent any buffered commands from executing for the duration of the probe.
Payload (6 bytes)
uint32: feedrate (in microseconds between steps) (max 71.58 minutes)
uint16: timeout (in seconds before abort) (max = 18 hours) (default = 1 minute)
Response (4 bytes)
uint32: Z position when probe has been triggered.
10 - Tool Query - Query a tool for information
This command is for sending a query to the tool. The master firmware will then pass the query along to the appropriate tool, as well as passing the response back as well. This allows the tool specific commands to be developed independently between.
Payload (2 + N bytes) uint8: the index of the tool to query
uint8: the query command for the tool.
N bytes: command specific payload, variable size.
Response (0-N bytes) 0-N bytes: the command specific response, if any.
11 -
Is Finished - See if the machine is currently doing anything
This command lets us know if the machine is finished executing its current command queue.
Payload (0 bytes)
Response (1 byte)
uint8: 0 if still in progress; 1 if finished.
12 - Read from EEPROM
Read the specified number of bytes from the given offset in the EEPROM and return it in the response packet. The maximum read size is 32 bytes.
Payload (3 bytes)
uint16: the offset of the read
uint8: the number of bytes to return, N. N <= 16.
Response (N bytes)
N bytes: the data read from the EEPROM.
13 - Write to EEPROM
Write the given bytes to the EEPROM starting at the specified location. The maximum payload size is 16 bytes. WARNING: this operation can be potentially slow (about 3.3ms * N) and will block all other operations. It's not recommended to write to the EEPROM while a build is in progress.
Payload (3+N bytes)
uint16: the offset of the write
uint8: the length of the data
N bytes: the data to write
Response (1 byte)
uint8: the number of bytes successfully written.
14 - Capture to file Capture all subsequent commands up to the next "end capture" command to a file with the given name on the SD card. The file will be stored in the root of the fat16 filesystem on the SD card. The maximum file name length permitted is 12 characters, including the '.' and file name extension. Welcome to the brave new world of MS-DOS 2.0!
Payload (N bytes) N bytes: the name of the file in ascii, terminated with a null
Response (1 byte) uint8: response code
- 0 if operation was successful
- 1 if no SD card was present
- 2 if SD card init failed
- 3 if partition table could not be read
- 4 if filesystem could not be opened
- 5 if root directory could not be opened
- 6 if SD card is locked
15 - End capture Complete an ongoing file capture.
Payload (0 bytes)
Response (4 bytes) uint32: the total size of the capture in bytes
16 - Playback capture
Play back a file containing captured data to the makerbot.
The maximum file name length permitted is 12 characters, including the '.' and file name extension. While the makerbot is in playback mode, it will only respond to pause, unpause, and stop commands.
Payload (N bytes)
N bytes: the name of the file in ascii, terminated with a null
Response (1 byte)
uint8: response code
- 0 if playback successfully initiated
- 1 if no SD card was present
- 2 if SD card init failed
- 3 if partition table could not be read
- 4 if filesystem could not be opened
- 5 if root directory could not be opened
- 7 if file was not found
17 - Reset Reset the board remotely. Useful for reprogramming the board without having to fiddle with switches. The board will reset immediately after sending the response.
Payload (0 bytes)
Response (0 bytes)
18 - Get next filename Retrieve the next valid filename from the SD card. If a non-zero value is passed to the "restart" parameter, the file list will begin again from the start of the directory. The file list state will be reset if any other SD operations are performed.
Payload (1 byte)
uint8: restart (0 to continue reading, 1 to begin anew)
Response (N+1 bytes) uint8: an SD response code, one of the following:
- 0 if operation was successful
- 1 if no SD card was present
- 2 if SD card init failed
- 3 if partition table could not be read
- 4 if filesystem could not be opened
- 5 if root directory could not be opened
N bytes: the name of the file in ascii, terminated with a null. If the operation was unsuccessful, this will be the empty string. Even if there was an SD card error, the null string should be returned.
Buffered Commands:
This command has been eliminated in favor of absolute point queueing.
128 - Queue point, Incremental
This point adds a point to the point queue. It sends the step information as a relative position from the current position aka a delta. This allows us to send the points as 2 byte data types in order to save space. Since it is relative and incremental, we can move the toolhead to any position we desire with a series of commands.
Payload (10 bytes)
int16: x delta (units are steps, always relative)
int16: y delta (units are steps, always relative)
int16: z delta (units are steps, always relative)
uint32: dda speed (in microseconds between steps on the max delta)
//uint8: timer1 prescaler value (as specified in the atmega644p datasheet)
//uint16: timer1 count-up-to value (number of ticks to count up to before triggering interrupt)
129 - Queue point, Absolute
This queues a point to move to, but it is an absolute position. This may make it easier to implement the host software, but it is much larger than the incremental points which will reduce your available command buffer size.
Payload (16 bytes)
int32: x coordinate (units are steps, always absolute)
int32: y coordinate (units are steps, always absolute)
int32: z coordinate (units are steps, always absolute.)
uint32: dda speed (in microseconds between steps on the max delta)
130 - Set Position
This command sets the current position of the toolhead. Useful for a variety of things.
Payload (12 bytes)
int32: x position, in steps
int32: y position, in steps
int32: z position, in steps
131 - Find Axes Minimums - Blocking seek to hardware min switches, w/ timeout
This function will find the hardware minimum. It will home all axes at the same time, so it is up to the host software to generate two separate homing commands if you want to home the Z axis separately.
Payload (7 bytes)
uint8: axes flags, where bits 2-0 represent which axes to home: | N/A | N/A | N/A | N/A | N/A | Z | Y | X |
uint32: feedrate (in microseconds between steps) (max 71.58 minutes)
uint16: timeout (in seconds before abort) (max = 18 hours) (default = 5 minutes)
132 - Find Axes Maximums - Blocking seek to hardware max switches w/ timeout
This function will find the hardware maximum, or position overflow (2^32), whichever is first.
It should also record this to the eeprom for future use. This function fill move all axes simulataneously, so it is important to generate two separate commands if you want to seek the Z axis separately.
Payload (7 bytes)
uint8: axes flags, where bits 2-0 represent which axes to home: | N/A | N/A | N/A | N/A | N/A | Z | Y | X |
uint32: feedrate (in microseconds between steps) (max 71.58 minutes)
uint16: timeout (in seconds before abort) (max = 18 hours) (default = ??)
133 - Delay - Simply stop and wait.
Exactly what it says.
Payload (4 bytes)
uint32: delay period (in microseconds) (max 71.58 minutes)
134 - Change Tool - Switch to a new tool
This will trigger a tool change. If the firmware supports automated tool changing, it will initiate its tool-changing routine. If it doesn't, it simply updates its currently selected tool and moves on.
Payload (1 byte)
uint8: index/address of the desired tool to select
135 - Wait For Tool Ready - Wait until a tool is ready before proceeding
This command is used to tell the machine to wait (for example for the extruder to heat up, etc.) It will poll the device with the 'are you ready' command until it responds affirmative
Payload (5 bytes)
uint8: the index of the tool to wait for before printing.
uint16: the delay between query packets sent to the tool head in milliseconds (default: 100 milliseconds)
uint16: the timeout before continuing without tool ready in seconds (default: 1 minute)
136 - Tool Action Command - Send an action command to a tool for execution
This command is for sending an action to the command. The
master firmware will then pass the query along to the appropriate tool,
as well as passing the response back as well.
Payload (3 + N bytes)
uint8: the index of the tool to query
uint8: the command for the tool.
uint8: the length of the command payload (N)
N bytes: command specific payload, variable size.
137 - Enable/Disable Axes - Explicitly power or depower steppers
This command is used to explicitly power steppers on or off. Generally, it is used to shut down the steppers after a build to save power and avoid generating excessive heat.
Payload (1 byte)
uint8: bitfield
bit 7: 1 to enable, 0 to disable
bit 6,5,4,3: ignored
bit 2: Z axis
bit 1: Y axis
bit 0: X axis