Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Serial TTY Communication via Shell Script?

Status
Not open for further replies.

unicornswag

Newbie level 2
Joined
Feb 19, 2014
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
37
So, after building a small Arduino-base (GRBL) CNC mill, I was a bit disappointed by the lack of a good Linux CLI interface to stream G-code files to my controller firmware. Then I found this python script on GitHub:

https://github.com/grbl/grbl/blob/master/script/simple_stream.py

I'm not all that familiar with python, but basically this script just looks for a file called grbl.gcode and streams it, line by line, to your device. To make this script easier to use, I wrote a few shell scripts as a wrapper to stream files and jog the machine more interactively. This setup works great. However, I would now like to rewrite that python script into a bash script, making it more universal so it could be run on any *nix system with depending on python or the py-serial module. I wrote a shell script that uses echo to send each line of my G-code file, one after another to my machine at /dev/ttyACM0. This script does essentially the same thing as the simple_stream python script and works quite well to jog the machine and stream small gcode files (under about 20 lines or so). However, streaming large files, it begins streaming fine, but then I run into problems:

1. As soon as I tell the script to begin streaming, about 10 lines of gcode are sent to the Arduino almost immediately. After a few seconds of delay, my machine goes into motion.

2. After that initial 10 or so lines, the gcode begins steaming MUCH slower, with maybe a 5 or 6 second delay between lines. The script begins streaming gcode lines slower than my machine completes them.

3. After around line 20 or 30, my machine catches up to the gcode being streamed. At this point, the firmware must wait the 5 or 6 seconds between lines before executing the code.

So my question is, what is the cause of this issue and what can be done to resolve it? I'm assuming that there is some sort of buffer in the firmware that is being filled and overflows. However, I don't know what commands could be issued from a shell script that would clear the buffer for the next code in line. As I understand it, the simple_stream python script waits for a response from GRBL before streaming the next line. Again, I don't know if or how this functionality could be added to a shell script or whether it would solve my issue. Any suggestions would be awesome!
 

Eight

Member level 1
Joined
Mar 8, 2013
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,736
Why on earth write a shell script when you can use python? All operating systems with python installed will be able to run your script (not counting some os-dependent stuff i.e. serial port names).

The python script is a simple one. It opens up a serial link with 9600 baud rate (this could *probably* be increased with some modding), and initializes the device by sending two CR/LF codes and waits 2 seconds. Finally it clears the receive buffer and begins sending the contents of the file line by line, having a blocking read operation pending after each send for the target device to respond with a "CTS" like reply. This tells the script that the device is ready to receive another line. You could probably erase those print commands, if you don't want all the debug output.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top