File size: 850 Bytes
b6a0fc3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
using System.IO.Ports;
using System.Threading.Tasks;
namespace FastPrint.Printer
{
public class MarlinConnector
{
private SerialPort port;
public MarlinConnector(string portName, int baudRate = 115200)
{
port = new SerialPort(portName, baudRate);
}
public async Task ConnectAsync()
{
if (!port.IsOpen)
port.Open();
await SendCommandAsync("M115"); // Get firmware info
}
public async Task SendCommandAsync(string gcode)
{
if (port.IsOpen)
await port.BaseStream.WriteAsync(System.Text.Encoding.ASCII.GetBytes(gcode + "\n"));
}
public void Disconnect()
{
if (port.IsOpen)
port.Close();
}
}
} |