User Tools

Site Tools


developer_guide_for_mm32_platform

!! This page is under construction !!

If you have questions or report bug, please send email to: support at malyansys dot com.

MM32 Platform

Malyan M200/M100/M160/M190/M300/M450 printer use 32-bit MCU powered main board, which name we called MM32 platform. This document will describe detail about MM32 platform, to help 3rd party developer to create app to work with our device.

MM32 platform include below blocks:

1. 32-bit MCU with native high speed USB interface and 72Mhz and up clock frequency to support real-time operation during printing.

2. Wireless network support including webUI, TCP/web-socket link for Gcode interface, UDP discovery/monitor protocol and smartconfig for setting AP's name or password.

3. LCD screen interface and changeable theme.

MM32+ board is planed which reserved more programmability, will available for sale in the future.

Command

G-code

Please reference to extended_gcode_table for more information.

Extended command

Extended command is use to monitor status and control Gcode command flow. This group of command is sent though different channel to gcode and have priority.

Command format

{CMD:PARAM}

Start byte: “{”

Command string: CMD. Please reference to available command list.

Divide byte: “:”

Value string: PARAM

End byte: “}”

Available commands
CMD PARAM comment
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
M Return mac address

Network interface

UDP discovery

MM32 will response UDP broadcast or unicast on port 6000.

Command: “{e:e}” will reply current status; “{e:M}” will echo MAC address.

Below is sample C# code for discovery MM32 in local network.

            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();

            for (int i = 0; i < interfaces.Length; i++)
            {
                if (interfaces[i].OperationalStatus != OperationalStatus.Up) continue;
                IPInterfaceProperties property = interfaces[i].GetIPProperties();
                foreach (UnicastIPAddressInformation ip in property.UnicastAddresses)
                {
                    //textBox1.Text += ip.Address + Environment.NewLine;

                    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, 0));
                    IPEndPoint iep = new IPEndPoint(IPAddress.Broadcast, 6000);
                    byte[] buffer = Encoding.UTF8.GetBytes("{e:e}");
                    client.Send(buffer, buffer.Length, iep);
                    Thread.Sleep(100);
                    while (client.Available != 0)
                    {
                        byte[] data = client.Receive(ref iep);
                        //textBox1.Text += Encoding.UTF8.GetString(data) + Environment.NewLine;

                        //if (Encoding.UTF8.GetString(data).Contains("}")) textBox1.Text += iep.Address;
                        
                        string str = Encoding.UTF8.GetString(data);

                            var regex = new Regex(@"\d+");
                            MatchCollection mc = regex.Matches(str);

                            if (mc.Count == 4)
                            {
                                notifyIcon1.Text = "Extruder:" + mc[0].Value + "°C Target:" + mc[1].Value + "°C\nPlatform:" + mc[2].Value + "°C Target:" + mc[3].Value + "°C";
                            }
                            
                        toolStripComboBox1.Items.Add(iep.Address);
                        toolStripComboBox1.SelectedIndex = 0;

                        localIP = ip.Address;
                    }

                    client.Close();
                }
            }

TCP interface

MM32 support TCP interface instead of com port to send gcode. Create TCP socket to MM32(port 23) and send gcode as string will receive response.

1. Send empty line included LF/CR character to flush garbage in buffer.

2. Handle RST signal properly. Close current connection and open new socket will recover from disconnect.

Note: MM32 default accept two TCP connections. If single connection send command, both connected sockets will receive same respond message.

Sample App 1: Telnet http://malyansys.com/downloads/Mputty.exe

Sample App 2: Modified Repetier-host (To be added)

Web socket

Because most web browser lack of support of TCP socket, MM32 provide web socket for integrating control panel using web UI. Below sample code in Javascript is use to send G28 command though the web socket:

<script>
var ws = new WebSocket('ws://192.168.43.50:81');
ws.onopen = function () {
  ws.send("G28");
}
</script>

Using web socket with javascipt can implement web interface with MM32.

REST method

Using AJAX and REST method can send single line gcode without socket connection:

http://IP_ADDRESS/set?code=G28\nG29

Send extended command though REST:

http://IP_ADDRESS/set?cmd={P:X}

Upload new webUI

To change original web UI, upload html file using browser to the 3rd upload box in address: http://printer_address/up

If zero size file uploaded, original web page will recovered.

Gcode uploading

MM32 platform provide two methods to upload plain text format gcode file. MicroSD card must exist in card slot. All uploaded files will be cached in microSD card, saved as “cache.gc”.

Make sure disable background polling thread/timer, file upload procedure will be interrupt if other command issued.

Recommend use fast mode before uploading using gcode: M563 S6

HTTP post

Upload gcode to url: http://ip_address/upload

Using web browser:

Dropzone.options.mydz = {
    dictDefaultMessage: "Upload GCode here",
	accept: function(file, done) {
		if (file.name.contains(".g")) done();
		else done("Not a valid GCode file.");
		},
	init: function() {
		this.on('error', function(file, response) {
            var errorMessage = response.errorMessage;
            $(file.previewElement).find('.dz-error-message').text(errorMessage);
        });
		this.on("addedfile", function() {
		  if (this.files[1]!=null){
			this.removeFile(this.files[0]);
		  }
		});
	}
};

<div id="dropzone"><form action="/upload" class="dropzone" id="mydz"/></div>

Download from web server

Using gcode M564 will download http file:

M564 http://server/file.gcode

Gcode M565 will download and print http file:

M565 http://server/file.gcode

To be continue

developer_guide_for_mm32_platform.txt · Last modified: 2019/03/20 04:21 (external edit)