Hello Guest it is March 28, 2024, 03:11:47 PM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - TheSuperior

Pages: 1 2 3 4 »
1
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 31, 2022, 03:30:39 PM »
I have finally managed to solve it. Thank you Zafar and TPS for all the help it is really appreciated.

2
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 31, 2022, 11:54:15 AM »
I know this, but it seems you do not fully understand.

I need to write code in arduino to understand what is send to it.

This macro basically sends

 30 toolnumber 13

but in Hex format. This is what I'm asking, so I figured it out myself.

ToolCommand = &H1E     'Tells microcontroller the job is tool change
JobDone = &HB6         'Micro sends this value when the job is done
CReturn = &H3E         'Value of carriage return in Hexadecimal

This is in the macro and gets appended to be send as a complete message.

I need to know how this macro is send over RS232 (Not rocket science I assume)

which I did figure out without using Swahili.

&H1E this is the same as 0X1E which is Hex format for a Record Seperator
&H0D this is the same as 0X0D ehich is HEX format for Carriage Return

Now I can not just randomly try to Parse this in arduino as it will not work. but what I can do is use both of these as Start and end markers. That is what they were intended for but I can replace them with my own start and end markers

ex. "<" and ">"

That way I can use only the integer value that is returned between my markers. That is exactly how this macro was written when it was made for the microcontroller.

So when everything is done I can use this: JobDone = &HB6         'Micro sends this value when the job is done
but instead of &HB6 I can use my own HEX value to send back to Mach3 and tell it the tool change has been completed.

Visual Basics and C++ are worlds apart therefore for them to communicate takes a different approach

The easy answer would have been for you to say '30 toolnumber 13' in HEX format but it seemed you did not understand this either.

3
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 31, 2022, 05:41:00 AM »
It will still use modbus to communicate to the microcontroller.

What I mean is what would an actual message of this Startsign (Hex 1E) + toolnumber + CR (Hex 0D) look like

I see that The value of HEX 1E in decimal is 30 and in binary is 00011110

Hex 0D = 0D

So would it be: 30 01 0D for tool number 1
30 02 0D - tool number 2
30 03 0D - tool number 3
30 04 0D - tool number 4
etc

4
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 31, 2022, 04:53:02 AM »
i am still not realy sure wether you what to use Modbus communication or the serial communication of the
sample i posted.

in case of the sample i posted the reveive data will look like this:

Startsign (Hex 1E) + toolnumber + CR (Hex 0D)

or

0x1E  0x?? 0x0D where ?? is the toolnumber

in case of you are using modbus, i have no experience what data would look like.

Could you please give me an example of what this will look like Startsign (Hex 1E) + toolnumber + CR (Hex 0D)

5
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 31, 2022, 04:38:30 AM »
At this point I'm just trying to figure it out.

All I want is this:

Mach3 G-code: M6 T0101

This gets stored into the userDRO that I created, from there a macro should save the value in the userDRO into a variable and send that number to my arduino (The only numbers that will ever matter is 1 to 12. So even if I have to write a If statement for every single number it is fine. I just want to send a number based on the tool selected to my arduino. From there the arduino can what for the number and perform the toolchange according to my program and maybe signal mach3 when it is done or it does not even need to.

So basically:

Mach3 Turn encounters M6 T0101 G-code
Stores Tool number 1 in the userDRO(2001)
Runs the m6Start Macro
Saves the tool number and sends it using the RS232 hardware connected to arduino to the arduino
arduino is already configured to receive it and do what it needs to do.

But obviously this gets done through the modbus protocol in Mach3 and a brain

6
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 31, 2022, 04:02:47 AM »
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?

7
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 30, 2022, 03:43:14 PM »
The code might work if I modify it a little to send only Chr(ToolN) which is only the tool number.

8
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 29, 2022, 11:28:12 AM »
I did check if the code still works properly with the mega and CNC shield with my current setup. I just changed this

regs[1]=analogRead(A8);

to connect the pot on analog 8, it worked fine except for a little bit of interference.

I somehow need to copy all of my code into the modbus sketch, I did try this with no luck as my sketch and toolchanger still worked fine but the pot did not work anymore. No idea why this might be.

I just need to know how to make write the if statement and what it should include. I assume it will be regs[10] ?

9
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 29, 2022, 11:15:36 AM »
Zafar, if you can just help me with this if statement please:

"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"

10
General Mach Discussion / Re: Arduino - Mach 3 - Gcode M6 T0101
« on: March 29, 2022, 11:13:47 AM »
Thank you TPS this is really super useful, but still a bit above my understanding. It only means I have some more research to do. I'm going to test this code and see what I can come up with. thank you

Pages: 1 2 3 4 »