oky I understand,
What if I use something like this arduino sketch that receives a request from mach3 and responds with a 1 or 0:
int pin = 2; //Cycle Start button
int in_buffer[8]; // receiving buffer
int reply_1[] ={0x01, 0x04, 0x02, 0x00, 0x01, 0x78, 0xF0};
int reply_0[] ={0x01, 0x04, 0x02, 0x00, 0x00, 0xB9, 0x30};
void setup()
{
Serial.begin(9600); // Init serial communication
pinMode(pin, INPUT); // Set pin to input
digitalWrite(pin, HIGH); // Turn on pullup resistor
}
void loop()
{
if ( Serial.available() == 8 ) {
// read ModBus command from Mach3
// in this example we only read, don't check anything
for (int i=0; i < 8; i++) {
in_buffer[ i ] = Serial.read();
Serial.println(in_buffer[ i ]);
}
// Read Input PIN and reply with 0 or 1
// Reply is inverted because PIN default state is HIGH and we connect to GND
if ( digitalRead(2) == 0 )
for (int i=0; i < 7; i++) Serial.write(reply_1[ i ]);
else
for (int i=0; i < 7; i++) Serial.write(reply_0[ i] );
}
}
What I actually want to know is when mach3 sends the request to the slave what would it look like? Something like this?
01 04 00 00 00 01
and which of these data bits will be the tool number?
it would actually look something like this then? 01 04 00 00 00 01 31 CA
It would be easy if I can just figure out what this lne of data looks like when mach3 sends it as a request to arduino. I would be able to convert it then.
If I make any sense at all?