Closed jgphilpott closed 6 months ago
@moof-moof this is a good idea, thanks for the suggestion. I've created a new branch to work on this feature but haven't made any commits yet.
If you want to work on it I recommend using FileReader to upload files. The upload event could be triggered by clicking a button. Once the upload is complete the data could then be passed to the write
function in serial/browser/sender.js
which will send it to the printer (assuming the connection is active).
If you prefer Python you could also take a look at the serial/python/usb.py
file. At the moment it doesn't do anything except send a G28
command and then disconnect but you could build something on top of it if you want. I was just experimenting with how to create serial connections in different ways.
@jgphilpott Thanks for the suggestion to make use of FileReader. I will be busy with other stuff the next few days, but will at least look into how it works after that.
@moof-moof here is an update on this issue. I have got a basic upload feature working, although it still needs some improvement. I have already merged my changes thus far into the main
branch so it should be live already.
Here are the design decisions I have made, let me know if you have any feedback.
Availability
Utility
.gcode
extension.Performance
The big issue that remains is the firmware command queue. I observed that when I send the entire G-code file at once only the first 8 commands actually get executed. After some research I discovered that this is because my Marlin firmware will only queue 8 commands at a time, the rest of the commands get discarded because they arrive before the printer has had time to run the commands it has already received. I believe the queue limit can be increased but doing so has a negative impact on the printers overall performance because it uses up memory so I don't want that to be the solution. I'm not sure if this is also true of your GRBL firmware?
The good news is that i've already partly developed a streaming function that will send the commands one at a time, only sending the next one after the previous one has been executed. The bad news is that my solution may be specific to Marlin firmware. In order for it to work I need to precede the file with a M111 S1
command. This tells the printer to echo back each command that is sent once it has been executed, this way I know when it's safe to send a new command without flooding the queue.
I will let you know once the streaming feature is done. If it doesn't work for you hopefully all you will need to do is edit the one line of code with the M111 S1
command and substitute it with a GRBL equivalent.
In the meantime if you have any input or feedback on the changes i've made thus far it would be greatly appreciated.
Thanks, Jacob
@jgphilpott Will reply tomorrow, or Fridsy at the latest.
Dear @jgphilpott, Since I am currently unable to properly use my cnc machine, due to some mechanical problems, I performed tests using a standalone Arduino Uno microcontroller. My test results with various short Gcode programs seem to indicate that I can indeed load .gcode files and run them automatically. The behaviour and output was just as when the content of the same file was pasted into the input field of my local (Polyslice) "sender.html" page.
For comparison, I also tested the same Gcode files using my usual method, which consists of streaming the commands, line by line utilising a short python script based on a simple script provided by Sonny Jeon (the maintainer of Grbl).
The Grbl firmware by default sends an "OK" asci reply as aknowledgment after every received line. This of course allows the stream to be "throttled" when the microcontroller's memory is full and (temporarily) can't handle more commands. In practise that means that the command stream usually starts with about 20 lines (varying with actual line lengths evidently) in quick succession. After that, new lines/commands are only sent in response to an "OK" from Grbl.
An interesting fact I found was that the Polyslice method was faster to finish than the other (Python based) method. For example, when using the Python script and the attached example Gcode file, the streaming procedure quickly processed 22 lines, then waited for about 150 seconds before "dropfeeding" the remaining lines with an approximate interval of 10 seconds.
But when streaming the same file using Polyslice the waiting time after the initial stage (quickly streaming all the lines Grbl can take and then proceed to wait) only lasted about 90 seconds, while the remaining lines were processed at the same 10 sends rate.
Also, while the python script prints out the "OK" after every line (including the first 9 "header" and 2 "footer" lines of the gcode file (so a total of 28 in this particular case), Polyslice's output window only reports 19 "OK's", evidently corresponding to the G01 and G03 commands. but not the header and footer lines.
Anyway, I am glad to report that your app now works well for me, and I am looking forward to be able use it as soon as I have time to fix what I believe is my machine's faulty stepper motors.
Cheers! test-shapes_03.gcode.pdf
@moof-moof that's great, i'm glad to hear that it's working for you! I guess I will just keep the streaming feature that I developed on a separate branch for my personal use, merging it would likely break what is already working for you.
Thanks so much for your contributions and feedback, don't hesitate to open more issues in the future if you think of anything!
Jacob
@moof-moof just to let you know I actually decided to merge the branch with the streaming feature. My target audience for this project is people doing FDM 3D Printing and most of them use Marlin so I want the main
branch to cater to that audience.
However, for your convenience, I added a simple variable on line 11
called streamEnabled
. If you set this to false
then the app should continue to work for you the way it did before the streaming feature was merged. Sorry for any inconvenience.
@jgphilpott A bespoke variable just for me! I’m most obliged 8^) Thanks again.
Is your feature request related to a problem? Please describe:
No.
Describe the solution you'd like to see:
Add an upload button and/or a drag-and-drop feature to enable complete file uploads.
Describe alternatives you've considered:
None.
Additional Information:
This feature was originally suggested by @moof-moof in this comment.