-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathline_us.dart
54 lines (45 loc) · 1.06 KB
/
line_us.dart
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
import 'dart:convert';
import 'dart:io';
main() async {
var commands = [
'G01 X900 Y300 Z0',
'G01 X900 Y-300 Z0',
'G01 X900 Y-300 Z1000',
'G01 X1200 Y300 Z0',
'G01 X1200 Y-300 Z0',
'G01 X1200 Y-300 Z1000',
'G01 X900 Y0 Z0',
'G01 X1200 Y0 Z0',
'G01 X1200 Y0 Z1000',
'G01 X1500 Y150 Z0',
'G01 X1500 Y-300 Z0',
'G01 X1500 Y-300 Z1000',
'G01 X1500 Y250 Z0',
'G01 X1500 Y300 Z0',
'G01 X1500 Y300 Z1000',
];
await LineUs(commands).draw();
}
class LineUs {
final List<String> commandQueue;
LineUs(this.commandQueue);
Socket _socket;
draw() async {
_socket = await Socket.connect("line-us.local", 1337);
_socket.transform(utf8.decoder).listen((data) {
print(data);
if (commandQueue.isNotEmpty) {
final command = commandQueue.removeAt(0);
_sendCommand(command);
} else {
_socket.destroy();
}
}, onError: (error) {
print(error);
_socket.destroy();
});
}
_sendCommand(String command) async {
_socket.write(command + "\x00\n");
}
}