forked from dsuarezv/Netduino-gcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCodeServer.cs
More file actions
68 lines (48 loc) · 1.54 KB
/
Copy pathGCodeServer.cs
File metadata and controls
68 lines (48 loc) · 1.54 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using System.Net.Sockets;
using NetduinoSocketServer;
using gcodeparser;
namespace StepperBasic
{
public class GCodeServer: LineServer
{
// __ Internals _______________________________________________________
static CncDevice mDevice = new CncDevice();
// __ Port setup ______________________________________________________
static OutputPort LED = new OutputPort(Pins.ONBOARD_LED, true);
// __ Server impl _____________________________________________________
public static void Main()
{
DeviceFactory.RegisterDevice(mDevice);
new GCodeServer().Listen(82);
}
protected override void OnConnect(Socket socket)
{
SendString("Dave's CNC interface 0.70 with G-Code\r\n", socket);
}
protected override bool ProcessLine(string line, Socket socket)
{
string l = line.ToLower().Trim();
if (l == "exit") return false;
LED.Write(false);
try
{
GCodeParser.ParseLine(l);
SendString("+\r\n", socket);
}
catch (Exception ex)
{
SendString("ERROR: " + ex.Message + "\r\n", socket);
}
finally
{
LED.Write(true);
}
return true;
}
}
}