This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
communications [2016/09/13 03:31] Matthew Upp |
communications [2020/06/07 04:44] (current) Matthew Upp [Table] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Sample code for web interface ===== | + | ~~NOTOC~~ |
- | Source: http:// | + | ====== Communications ====== |
+ | ---- | ||
- | More API will be add soon. | + | ===== Commands ===== |
- | **Send GCODE M565 to start print file cache.gc** | + | ==== G-code ==== |
+ | Standard Marlin compatible G-codes can be found at the [[http:// | ||
+ | <wrap lo>//Not all standard G-code are supported by the MP Select Mini.//</ | ||
+ | |||
+ | See the [[g-code|G-code]] page for information about software to use and how to send G-code. | ||
+ | \\ | ||
+ | |||
+ | |||
+ | ==== Extended G-code ==== | ||
+ | See the [[extended_g-code_table|Extended G-code Table]] for G-code that is more or less specific to the MP Select Mini & Malyan printers. \\ | ||
+ | \\ | ||
+ | |||
+ | |||
+ | ==== Command Format ===== | ||
+ | |||
+ | < | ||
+ | {CMD: | ||
+ | |||
+ | Start byte: " | ||
+ | |||
+ | Command string: CMD. Please reference to available command list. | ||
+ | |||
+ | Divide byte: ":" | ||
+ | |||
+ | Value string: PARAM | ||
+ | |||
+ | End byte: " | ||
+ | </ | ||
+ | \\ | ||
+ | |||
+ | |||
+ | === Available Commands === | ||
+ | {{tablelayout? | ||
+ | ^ CMD ^ PARAM ^ function | ||
+ | | P | X | Cancel print | | ||
+ | | ::: | H | Homing | ||
+ | | ::: | P | Pause print | | ||
+ | | ::: | R | Resume print | | ||
+ | | ::: | M | Print cache.gc | ||
+ | | C | T0000 | Set T0 temperature | ||
+ | | ::: | P000 | Set hotbed temperature | ||
+ | | e | e | Return printing status | ||
+ | | J | X | Moves the X-Axis | ||
+ | | ::: | Y | Moves the Y-Axis | ||
+ | | ::: | Z | Moves the Z-Axis | ||
+ | | R | M | Return mac address | ||
+ | | S | I | List files on the microSD card | | ||
+ | | V | | Displays firmware versions on LCD | | ||
+ | | W | | Deletes WiFi SSID and password | ||
+ | | | ||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Sample Code for Web UI ===== | ||
+ | |||
+ | |||
+ | ==== Sample Web UI ==== | ||
+ | Moved to it's own page. [[sample_webui|Sample Web UI]] \\ | ||
+ | \\ | ||
+ | |||
+ | |||
+ | ==== Send GCODE M565 to start print file cache.gc | ||
< | < | ||
function start_p(){ | function start_p(){ | ||
Line 17: | Line 81: | ||
} | } | ||
</ | </ | ||
+ | \\ | ||
- | **Send GCODE M566 to rename file cache.gc** | ||
- | < | ||
- | M566 newfilename.gc | ||
- | </ | ||
- | **Get printing status** | + | ==== Get printing status |
< | < | ||
$.get(" | $.get(" | ||
Line 42: | Line 103: | ||
}); | }); | ||
</ | </ | ||
+ | \\ | ||
- | **Send Control command {P:X} to cancel print** | + | |
+ | ==== Send Control command {P:X} to cancel print ==== | ||
< | < | ||
function cancel_p(){ | function cancel_p(){ | ||
Line 53: | Line 116: | ||
} | } | ||
</ | </ | ||
+ | \\ | ||
- | **Set extruder temperature** | + | ==== Set extruder temperature |
< | < | ||
function pad(num, size) { | function pad(num, size) { | ||
Line 69: | Line 133: | ||
}); | }); | ||
</ | </ | ||
+ | \\ | ||
- | **Stop preheat heat bed** | + | ==== Stop preheat heat bed ==== |
< | < | ||
$("# | $("# | ||
Line 81: | Line 146: | ||
}); | }); | ||
</ | </ | ||
+ | \\ | ||
- | **Set printing speed** | + | |
+ | ==== Set printing speed ==== | ||
< | < | ||
1X Speed: {C:S10} | 1X Speed: {C:S10} | ||
Line 88: | Line 155: | ||
5X Max | 5X Max | ||
</ | </ | ||
+ | \\ | ||
+ | |||
- | **Enable fast mode for web uploading** | + | ==== Send gcode though WebSocket interface ==== |
< | < | ||
- | GCode: S value can be 2~6 | + | < |
- | M563 S6 | + | var ws = new WebSocket(' |
+ | ws.onopen = function () { | ||
+ | ws.send(" | ||
+ | } | ||
+ | </ | ||
</ | </ | ||
+ | \\ | ||
+ | |||
+ | |||
+ | ==== REST ==== | ||
+ | Using AJAX and REST a single line of code g-code can be sent without a socket connection. | ||
+ | |||
+ | < | ||
+ | http:// | ||
+ | </ | ||
+ | |||
+ | |||
+ | Send extended command though REST: | ||
+ | |||
+ | < | ||
+ | http:// | ||
+ | </ | ||
+ | \\ | ||
+ | |||
+ | ==== Web Browser Address Bar ==== | ||
+ | While the MP Select Mini V1/V2 is connected to WiFi you may use the format **'' | ||
+ | |||
+ | **Format:** '' | ||
+ | < | ||
+ | http:// | ||
+ | http:// | ||
+ | http:// | ||
+ | </ | ||
+ | |||
+ | When a command is sent and received successfully the browser should display `Ok`, `OK`, or `ok`. Additional g-code commands can be sent one after another using the same format. | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | ===== Network interface ===== | ||
+ | |||
+ | |||
+ | ==== UDP Interface ==== | ||
+ | MM32 will response UDP broadcast or unicast on port 6000. | ||
+ | |||
+ | Command: " | ||
+ | |||
+ | Below is sample C# code for discovery MM32 in local network. | ||
+ | |||
+ | < | ||
+ | NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); | ||
+ | |||
+ | for (int i = 0; i < interfaces.Length; | ||
+ | { | ||
+ | if (interfaces[i].OperationalStatus != OperationalStatus.Up) continue; | ||
+ | IPInterfaceProperties property = interfaces[i].GetIPProperties(); | ||
+ | foreach (UnicastIPAddressInformation ip in property.UnicastAddresses) | ||
+ | { | ||
+ | // | ||
+ | |||
+ | if (ip.Address.AddressFamily == AddressFamily.InterNetworkV6) continue; | ||
+ | if (ip.Address.GetAddressBytes()[0] == 255 || ip.Address.GetAddressBytes()[0] == 0) continue; | ||
+ | |||
+ | UdpClient client = new UdpClient(new IPEndPoint(ip.Address, | ||
+ | IPEndPoint iep = new IPEndPoint(IPAddress.Broadcast, | ||
+ | byte[] buffer = Encoding.UTF8.GetBytes(" | ||
+ | client.Send(buffer, | ||
+ | Thread.Sleep(100); | ||
+ | while (client.Available != 0) | ||
+ | { | ||
+ | byte[] data = client.Receive(ref iep); | ||
+ | // | ||
+ | |||
+ | //if (Encoding.UTF8.GetString(data).Contains(" | ||
+ | | ||
+ | string str = Encoding.UTF8.GetString(data); | ||
+ | |||
+ | var regex = new Regex(@" | ||
+ | MatchCollection mc = regex.Matches(str); | ||
+ | |||
+ | if (mc.Count == 4) | ||
+ | { | ||
+ | notifyIcon1.Text = " | ||
+ | } | ||
+ | | ||
+ | toolStripComboBox1.Items.Add(iep.Address); | ||
+ | toolStripComboBox1.SelectedIndex = 0; | ||
+ | |||
+ | localIP = ip.Address; | ||
+ | } | ||
+ | |||
+ | client.Close(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | |||
+ | ==== TCP Interface ==== | ||
+ | The printer also supports TCP interface instead of COM port to send G-code. Create a TCP socket on port 23 and send G-code as a string to receive a response. | ||
+ | |||
+ | * Send empty line included LF/CR character to flush garbage in buffer. | ||
+ | |||
+ | * Handle RST(reset) signal properly by closing the current connection and open a new socket to recover from disconnect. | ||
+ | |||
+ | The printer by default will accept two TCP connections. If a single connection sends a command, both connected sockets will receive same response message. | ||
+ | |||
+ | Use a program like PuTTY or another Telnet client to connect to the MP Select Mini. | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | |||
+ | ===== Upload Custom Web UI ===== | ||
+ | <wrap lo>< | ||
+ | - Enter '' | ||
+ | - Upload html file using the 3rd " | ||
+ | - Click the " | ||
+ | - Enter '' | ||
+ | - Custom Web UI should appear | ||
+ | |||
+ | |||
+ | ===== Default Web UI ===== | ||
+ | - Enter '' | ||
+ | - Click the " | ||
+ | - Enter '' | ||
+ | - Default Web UI will appear | ||
+ | |||
+ | |||
+ | ==== Sample Web UI ==== | ||
+ | Moved to it's own page. [[sample_webui|Sample Web UI]] \\ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | ==== WebSocket ==== | ||
+ | The printer provides a WebSocket server for integrating control panel using a Web UI. Below is sample Javascript code to send G28 command though the WebSocket: | ||
- | **Send gcode though websocket interface** | ||
< | < | ||
< | < | ||
Line 105: | Line 311: | ||
</ | </ | ||
+ | Using JavaScript along with the WebSocket, you can create a custom Web UI. | ||
+ | |||
+ | |||
+ | ==== WebSocket Test Page ==== | ||
+ | Moved to it's own page. [[websocket_test_page|WebSocket Test Page]] \\ | ||
+ | \\ |