-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLineUs.pde
70 lines (59 loc) · 1.34 KB
/
LineUs.pde
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
69
//An example class to show how to use the Line-us API
class LineUs {
Client lineUs;
Boolean connected = false;
String helloMessage;
String address = "192.168.0.4";
LineUs(PApplet papp, String address) {
try {
lineUs = new Client(papp, address, 1337);
if (lineUs.available() > 0) {
connected = true;
helloMessage = readResponse();
}
}
catch (Exception e) {}
}
String getHelloString() {
if(connected) {
return helloMessage;
} else {
return("Not connected");
}
}
//Close the connection to the Line-us
void disconnect() {
lineUs.stop();
connected = false;
}
//Send a G01 (interpolated move), and wait for the response before returning
void g01(int x, int y, int z) {
String cmd = "G01 X";
cmd += str(x);
cmd += " Y";
cmd += str(y);
cmd += " Z";
cmd += str(z);
sendCommand(cmd);
readResponse();
}
//Read from the socket one byte at a time until we get a null
String readResponse() {
String line = "";
int c;
while(true) {
c = lineUs.read();
if(c != 0 && c != -1) {
line += (char) c;
} else if(c == 0) {
break;
}
}
return line;
}
//Send the command to Line-us
void sendCommand(String command) {
command += "\0";
lineUs.write(command);
}
}