Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
{
"cells": [
{
"cell_type": "code",
"execution_count": 122,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[34m\u001b[43m/dev/tty.Bluetooth-Incoming-Port\u001b[m\u001b[m \u001b[34m\u001b[43m/dev/tty.usbserial-DA010POJ\u001b[m\u001b[m\r\n"
]
}
],
"source": [
"! ls /dev/tty.*"
]
},
{
"cell_type": "code",
"execution_count": 123,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#! touch header.gcode body.gcode footer.gcode\n",
"! echo '{\"gc\":\"G28.2 Z0\"}' > body.gcode\n",
"#! echo '{\"gc\":\"G1 Z1100 F400\"}' >> body.gcode\n",
"! cat my_settings.json body.gcode footer.gcode > run.gcode "
]
},
{
"cell_type": "code",
"execution_count": 124,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"z\":{\"am\":1,\"vm\":200,\"fr\":400,\"tm\":1000,\"jm\":600000000,\"jh\":400000000,\"jd\":0.0100,\"sn\":3,\"sx\":0,\"sv\":200,\"lv\":150,\"lb\":10.000,\"zb\":0.000}}\r\n",
"{\"3\":{\"tr\":2.0}}\r\n",
"{\"gc\":\"G28.2 Z0\"}\r\n"
]
}
],
"source": [
"! cat run.gcode"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"From this wiki page https://github.com/synthetos/TinyG/wiki/JSON-Details\n",
"\n",
"`\"f\":[<protocol_version>, <status_code>, <input_available>, <checksum>]`"
]
},
{
"cell_type": "code",
"execution_count": 125,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"r\": {\n",
" \"z\": {\n",
" \"fr\": 400, \n",
" \"sx\": 0, \n",
" \"lb\": 10.0, \n",
" \"am\": 1, \n",
" \"vm\": 200, \n",
" \"zb\": 0.0, \n",
" \"sv\": 200, \n",
" \"lv\": 150, \n",
" \"jm\": 600, \n",
" \"tm\": 1000.0, \n",
" \"jh\": 400, \n",
" \"sn\": 3, \n",
" \"jd\": 0.01\n",
" }\n",
" }, \n",
" \"f\": [\n",
" 1, \n",
" 0, \n",
" 140, \n",
" 337\n",
" ]\n",
"}\n",
"{\n",
" \"r\": {\n",
" \"3\": {\n",
" \"tr\": 2.0\n",
" }\n",
" }, \n",
" \"f\": [\n",
" 1, \n",
" 0, \n",
" 17, \n",
" 6730\n",
" ]\n",
"}\n",
"{\n",
" \"r\": {\n",
" \"gc\": \"G28.2Z0\"\n",
" }, \n",
" \"f\": [\n",
" 1, \n",
" 0, \n",
" 18, \n",
" 8130\n",
" ]\n",
"}\n"
]
}
],
"source": [
"import serial\n",
"import time\n",
"import json \n",
" \n",
"s = serial.Serial( port='/dev/tty.usbserial-DA010POJ', baudrate=115200 ) # copied from above \n",
" \n",
"with open( 'run.gcode','r' ) as f:\n",
"\n",
" s.write(\"\\r\\n\\r\\n\")\n",
" time.sleep(2)\n",
" s.flushInput() \n",
"\n",
" for line in f:\n",
" l = line.strip() \n",
" s.write(l + '\\n') \n",
" raw_out = s.readline() # waits for a carriage return \n",
" json_out = json.loads( raw_out )\n",
" \n",
" # print the output \n",
" print json.dumps( json_out, indent=2 )\n",
"\n",
"s.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
526d19316This file is pinned to the selected release. Download the original to open it in your design tool.