我正在通过pyserial Python 包连接到使用Marlin 1.0.3 开发固件的打印机。
我想将大型 gcode 文件流式传输到打印机中,我猜缓冲区的大小有限。我如何知道缓冲区何时已满,以便我可以等到命令处理完毕后再发送一个新命令?
我试过读取一个大文件,发送所有命令并检查另一个线程中的打印机响应。我没有收到错误或指示缓冲区已满的信息。我也没有在官方文档中找到任何关于此的内容。
我的方法对吗?有什么我想念的吗?
部分代码:
def check_for_responses():
while(True):
response = printer_connection.serial.readline()
print(response)
async def stream_gcode():
await printer_connection.open_connection('COM7')
Thread(target=check_for_responses).start()
asyncio.sleep(2) # wait to initialize
file = open("test.gcode", 'r')
for line in file:
command= printer_connection.format_command(line)
printer_connection.serial.write(command.encode())
asyncio.new_event_loop().run_until_complete(stream_gcode())