开源改变世界

坚持通过 Python 唤醒 GRBL #1316

推推 grbl 2年前 (2023-01-23) 168次浏览

打开
selotipkusut 打开了这个问题 2017 年 11 月 9 日 · 3条评论
打开

坚持通过 Python 唤醒 GRBL#1316

selotipkusut 打开了这个问题 2017 年 11 月 9 日 · 3条评论

注释

坚持通过 Python 唤醒 GRBL #1316
塞洛蒂库苏特 评论了 2017 年 11 月 9 日  

您好,我正在为以前的学生制作的 GRBL 机器开发一个简单的 Python 3 GUI。

我正在努力使用修改后的 simple_stream.py 来初始化 GRBL,其中打开了 2 个串行端口。ttyACM0 用于配置电机步进模式,ttyUSB0 用于与 GRBL 通信。

ttyACM0 没有问题,但我没有收到 GRBL 的反馈。没有启动消息,例如Grbl v0.9j press $ for help等。
同时,使用 Arduino IDE 的串行监视器与两个端口通信没有问题,G 代码已正确发送。

##
import serial
import time

# Open grbl serial port
s = serial.Serial('/dev/ttyUSB0',115200)
step=serial.Serial('/dev/ttyACM0',9600)

# Open g-code file
f = open('test.gcode','r')

# Wake up grbl
s.write("\r\n\r\n".encode())
time.sleep(2)   # Wait for grbl to initialize
s.flushInput()  # Flush startup text in serial input

step.write("f".encode()) #set motor to full step
print((step.readline()).decode())

# Stream g-code to grbl
for line in f:
    l = line.strip() # Strip all EOL characters for consistency
    print('Sending: ' + l)
    s.write((l + '\n').encode()) # Send g-code block to grbl
    grbl_out = s.readline() # Wait for grbl response with carriage return
    print(' : ' + (grbl_out.strip()).decode())

# Wait here until grbl is finished to close serial port and file.
input("Enter to exit and disable grbl.")
f.close() #close file

step.write("s".encode()) #Exit step mode
print((step.readline()).decode())
坚持通过 Python 唤醒 GRBL #1316
成员

Grbl 只有一个串行接口,为什么你认为你需要两个设备?

坚持通过 Python 唤醒 GRBL #1316

我想我不明白你所说的“唤醒”grbl 是什么意思。只要 Arduino 通电,Grbl 就会运行,因此无需唤醒。如果您正在寻找启动脚本,那么您需要发送软重置命令 Ctrl-X。

坚持通过 Python 唤醒 GRBL #1316

Hola,veo que utiliza algo 类似于“用于 grbl 的简单 g 代码流脚本”,presenté el mismo problema y de antemano,encontré los cambios para python3 …(参考:#1316(评论)

import serial
import time

# Open grbl serial port
s = serial.Serial('COM7',115200)

# Open g-code file
f = open('corte.gcode','r')

# Wake up grbl
s.write("\r\n\r\n".encode())
time.sleep(2)   # Wait for grbl to initialize 
s.flushInput()  # Flush startup text in serial input

# Stream g-code to grbl
for line in f:
    l = line.strip() # Strip all EOL characters for consistency
    print( 'Sending: ' + l)
    s.write((l + '\n').encode()) # Send g-code block to grbl
    grbl_out = s.readline() # Wait for grbl response with carriage return
    print( ' : ' + (grbl_out.strip()).decode())

# Wait here until grbl is finished to close serial port and file.
input("  Press <Enter> to exit and disable grbl.") 

# Close file and serial port
f.close()
s.close()

Seguido, al correrlo aparecerá lo siguiente en el terminal:

PS D:\GCODE_BUSCAR\grbl_python> & C:/Python37/python.exe d:/GCODE_BUSCAR/grbl_python/simple_stream.py

发送:G90:错误:报警锁定

发送:M5:错误:报警锁定

发送:X4.8Y22.5:错误:报警锁

Esto a su vez, nos indica que GRBL necesita ser desbloqueado o en GRBL…. “$X”。
Para lo cual podría ser que en el archivo .gcode o depende la extención, cuente en su encabezado $X

PS D:\GCODE_BUSCAR\grbl_python> & C:/Python37/python.exe d:/GCODE_BUSCAR/grbl_python/simple_stream.py

发送:$X:[注意:已解锁]

发送:G90:好的

发送:M5:好的

Espero que haya sido de ayuda。

喜欢 (0)