What I want to do is write a text with coordinates, send them via DNC software and have arduino wait for the position before it send the next position.
I tried using xon/xoff after a couple hours trial, errors and reading by myself I found an article saying arduino doesn't support xon xoff. So what do you guys think I should do?
second question I'm a cnc machinist, when I program my cnc I use Mastercam, when I make a drawing I use Solidworks. Is there a software to program arduino?
What is DNC software? Post a link to its documentation.
I don't understand your problem. There should be no difficulty programming an Arduino to wait for a message to be received (such as an xon character) before it sends the next message.
If you have some code that is not working please post it.
And please use the code button </> so your code looks like this and is easy to copy to a text editor
The Arduino IDE is the software for programming an Arduino.
I've had a quick look at your DNC link but I don't immediately see how it relates to your need for Arduino code. Please explain and provide an example of the data you are trying to receive on your Arduino.
Your program seems to be trying to read a single byte after sending an XON character.
First, you are expecting the character to arrive within a few microseconds - that won't happen. The XON may not even have been sent at the time you try to read the character.
Second, it seems strange that only one character would be expected.
Have a look at the examples in Serial Input Basics. They will receive the new data in the background. However without knowing what you want to receive I can't give more specific advice about how to integrate that with XON/XOFF
ouatsup:
I will try to modify your serial input basic code for my need later this week.
It should be suitable for what you want.
Is there a Linefeed or CarriageReturn character (or both) after the semi-colon?
You may be able to use the function recvWithEndMarker() and use a semi-colon as the end marker. Then at the point where it sets newData to true you could have it send the XOFF character
Is there no natural break in the flow of incoming data? (i.e. is XOFF the only way to stop it?)
What is the baud rate of the incoming data?
What is the longest time to "use" a parcel of incoming data? (i.e. can you process quicker than it arrives?)
Is there a Linefeed or CarriageReturn character (or both) after the semi-colon?
yes both
#1 Is there no natural break in the flow of incoming data? (i.e. is XOFF the only way to stop it?) #2 What is the baud rate of the incoming data? #3 What is the longest time to "use" a parcel of incoming data? (i.e. can you process quicker than it arrives?)
#1 I can use break after receiving character or delay before each line #2 9600 #3 not all the time (when the move is 270° the next line will come faster than a 1°move)
I tried this code and many other ways to trigger the Xon, nothing worked
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
delay(5000); //give me time to push send on computer
Serial.write("/17"); //this should trigger something on my software}
void loop() {
recvWithEndMarker();
showNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = ';';
char rc;
// if (Serial.available() > 0) {
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("/19");
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
Serial.print("/17");
}
}
OK just to clear this up because I'm a machinist and a arduino nut so everyone understands what the opportunity is trying to do..
DNC is drip feed gcode tof a cnc machine.
He is trying it read an rs-232 output for a indexer and using flow control pause the machine tell he has it do something with the index angle data..
First my view is this is a problem as doing this in most cases means moving a 4th axis A without having true synchronization on a cnc machine scares me. But
It is doable with a custom post in mastercam to move z away before any A movement and a understanding that this is nothing more then a indexer with turn and hold
I can type up code that gone between the rs-232 on the PC and the cnc machine so it can buffer the code and supply a post.