In the Arduino sketch you can do an if statement in the main loop. You can read the value of a register from Mach3 modbus or the state of a pin which can be connected to an output pin from Mach.
In the tool change macro you can either turn an output on and off to signal the arduino to start the tool change sequence. Or change the value of a user DRO which can be read in brains and then to modbus. Then you can do a while statement in the tool change macro which waits for the input from Arduino to finish the tool change macro.
So I'm trying to figure out how to do this,
in the m6start macro should i use sendserial() ?
Please help with what the if statement needs to contain?
In the sketch:
if (txenpin > 1) { // pin 0 & pin 1 are reserved for RX/TX
Txenpin = txenpin; /* set global variable */
pinMode(Txenpin, OUTPUT);
digitalWrite(Txenpin, LOW);
}
Do I have change these pins to use 18 and 19?
unsigned int Txenpin = 0; /* Enable transmission pin, used on RS485 networks */
Then here is the code I use to capture the serial input. How do I modify this to capture what modbus sends or will it work as is?
void ReceiveData() {
while (Serial.available()) {
BlinkPattern();
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0) {
//Serial.println(readString); //so you can see the captured string
//int n;
char carray[6]; //converting string to number
readString.toCharArray(carray, sizeof(carray));
Input = atoi(carray);
readString="";
}
}