开源改变世界!!

USB handshaking interface #3

推推 grbl 2年前 (2023-01-21) 350次浏览

 Closed

USB handshaking interface#3

Highlander01 opened this issue on Jun 20, 2010 · 12 comments

Comments

USB handshaking interface #3

I am doing a different python interface then your ruby interface. Should I be doing some handshaking with code on the Arduino. How many lines can I send at a time? Should I wait for code on the Arduino to write back “ok” before I send a next line. I am going to play with it some but if you can give me a head start that would be great. Should code on arduino store up a bunch of gcode lines before starting execution.

(My python interface is a little further along. I made it so that it can draw G02 arc gcode in python/opengl. Not the heart of the system but nice shiny surface stuff.)

USB handshaking interface #3
Member

Nice. I’d really like a graphical interface for Grbl! In stream.rb I can guarantee that the buffer will not overflow, but it is never a problem in reality. I send a number of lines at once (e.g. 10) and then continue to send new lines every time I see an ‘ok’. It works, but in principle it is terrible. I wish I could find a way to use hardware handshaking.

USB handshaking interface #3
Author

I did not tinker to much this weekend…. I will try the 10 and then do one line per ok some time in the future. I previously let python send non stop to Grbl and I think I may have been overloading it somewhere maybe. Not completely sure. The gcode file Vectric Cut 2D generates for me is not generating G02/G03 arc gcode and generates lots of little G01 lines. I need to figure if I can get it to do G02 and G03.

I have not pushed/tested/made additions to the comm limits of Grbl yet but I was thinking a little bit about the usb software/hardware handshaking…getting carried away it would be cool if the Arduino had a dual core processors with shared memory of some sort. Get one processor to handle comms and the other to do the stepping. Other thoughts, if there was a use some I/O could be done thru a printer port.

If you are interested in a copy of the python I am hacking together let me know. I am more then willing to share. It is not completely fine tuned yet but it keeps getting better.

USB handshaking interface #3
Member

In cut 2d there is two separate output profiles for G-code with or without arcs, but personally I use the one without.

The atmega 168/328 has very limited RAM so I have been very frugal with the serial input buffer. Without some sort of handshaking the buffer will be overrun in seconds.

The real solution is to buffer to an SD-card and I plan to do this at some point. Edward has been doing something along these lines using two arduinos:

http://www.edslifedaily.com/1/post/2010/06/arduino-based-headless-cnc-machine-now-featuring-hardware-flow-control.html

I would like to follow your development. Why not host your code here at github?

USB handshaking interface #3
Author

I started a github repository. Looks like I need to download some additional software before I can put code in repository.

Do I need to put any sort of GNU open free sort of clauses in with the code? I am new at this.

USB handshaking interface #3
Member
simen commented on Jul 4, 2010

No you don’t need to explicitly state the licence – but with a free github account you are not allowed to make private repositories which means anyone will be able to download your code.

You need to install git in order to use github.

USB handshaking interface #3
Author

Sounds good, I installed git and put a screen shot of the interface in a repository under my account. I plan to put code there soon also with gnu license.

USB handshaking interface #3
Author

Update:

  • I implemented a handshake betweeen my PC/Python program and Arduino to make sure comms get across.USB speed. I send Gcode line from PC/Python and Arduino sends back count of chars it rcvd. If it matches I then tell Arduino to run the line. If not I cancel what Arduino rcvd and resend line.
  • Ref June 20 comment with lots of little G01 lines. In order to cut a little wooden gear I was going with G01 and 0.1mm line moves to approx arcs. The usb processing seems to be slow and the stepping is fast/buffer is not staying full which results on stepping waiting for USB to get more lines across. lots a dwell time as a result between G01 lines.
  • Have others seen the same. Any one willing to try running my gcode file with 0.1mm lines to see if it goes better for them.
USB handshaking interface #3
Author

Here is Arduino handshake code I mention in previous comment.

PC Python program sends gcode line to arduino with “?” at end of line. If arduino can send back proper count of chars to PC Python program things are good. PC/Python then sends “*” telling Arduino to “gc_execute” run the line. If bad count is sent back PC/Python sends back “#” character to cancel line and start over.

void sp_process()
{
char c;
while((c = serialRead2()) != -1)
{
if((c == ‘*’)) { // Line is complete. Then execute!
line[char_counter] = 0;
gc_execute_line(line);
char_counter = 0;
prompt();
} else if (c == ‘?’) {
printPgmString(PSTR(“?”)); printInteger(char_counter); printPgmString(PSTR(“\r\n”));
} else if (c == ‘#’) {
char_counter = 0;
printPgmString(PSTR(“#”)); printInteger(char_counter);
} else if (c <= ‘ ‘) { // Throw away whitepace and control characters
} else if (c >= ‘a’ && c <= ‘z’) { // Upcase lowercase
line[char_counter++] = c-‘a’+’A’;

} else {
  line[char_counter++] = c;

}

}
}

USB handshaking interface #3

Hi Simen,
This would be a great addition to have. How do you stand on implementing a system like this? I am writing an AIR app as a graphical interface, but it is impossible to receive the data from GRBL in a reliable way. The air-socket connection receives the data in packages, and it is impossible to determine when a data output from grbl is finished.
Ending each grbl output with a restricted character, e.g. *, would already be sufficient.

USB handshaking interface #3
Member

I don’t understand exactly what the problem is, so please educate me!

Grbl ends each line with a CRLF, why isn’t that sufficient?

A long long time ago I wrote I simple testing interface for grbl in Air. It can be found here:

https://github.com/simen/hrdr

I can’t remember having trouble with handshaking. But I am sympathetic to the cause, I just have to make sure this is a real problem.

USB handshaking interface #3

ok, I got it (sort of) figured out. I am not too experienced with sockets so the real problem is probably on my end :)
There were several issues:

  1. The socket connection chops the data into packages resulting in broken lines and confusion;
  2. Somehow the 10 character was somewhere transformed to 0 resulting is strange behaviour. This happens in the AIR app or in SerProxy, because when i look at the ascii output in Cornflake it is a 10.
  3. I was looking for a 13 10 combination before sending a line to the logscreen, but then I found out that there is also a 10 13 combination.

so, right now I am schecking for 10 13 or 13 10 and then sending the resulting string to the display and all is well!

I don’t know if there is a standard method for this, it seems quite a workaround..

This issue was closed.
喜欢 (0)