| | 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");
|
| | }
|
| |
|
| | 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();
|
| | }
|
| | }
|
| | } |