-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (36 loc) · 1.06 KB
/
Copy pathmain.py
File metadata and controls
48 lines (36 loc) · 1.06 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
import serial
import time
from pynput.keyboard import Key, Controller, Listener
import keyboard
# Connection to usb port on mac
SerialObject = serial.Serial("/dev/tty.usbmodem7877B8B700181", 9600)
# Default parameters to be changed if required
gcode = open("1002.nc", "r")
# Confirmed connection with usb
print(SerialObject)
# Code referenced from grbl db
SerialObject.write(str.encode("\r\n\r\n"))
key = "w"
xPosition = 0.0
yPostion = 0.0
zPostion = 0.0
time.sleep(2)
SerialObject.flushInput()
for line in gcode:
l = line.strip()
print("sending: " + l),
SerialObject.write(str.encode(l + "\n"))
grbl_out = SerialObject.readline()
print(" : " + grbl_out.strip().decode())
while True:
keyboard.wait("w")
print(("X%d Y%d Z%d\n" % (xPosition, yPostion, zPostion)))
SerialObject.write(
str.encode(("X%d Y%d Z%d F2000 \n" % (xPosition, yPostion, zPostion)))
)
xPosition = xPosition + 0.1
grbl_out = SerialObject.readline()
print(" : " + grbl_out.strip().decode())
# Closing Serial port
gcode.close()
SerialObject.close()