Hello Guest it is April 19, 2024, 06:43:53 PM

Author Topic: My first Macro-- quick Q's on reading external inputs.  (Read 5380 times)

0 Members and 1 Guest are viewing this topic.

Offline nicad

*
  •  40 40
    • View Profile
My first Macro-- quick Q's on reading external inputs.
« on: March 28, 2009, 01:17:43 AM »
I am needing to make a macro to:
A) Read a 3-position switch
B) Set a value to a variable in my G-code based on which position the switch is in.
What I have so far:
I am using a G100 for I/O. I have my switch wired to 3 of the digital inputs. This works so far.
I assume I need to assign each of the 3 inputs to an "OEM Trigger" under Ports/Pins.??

What do I then need to do in my macro to read the condition of each of these 3 inputs?
And the, how do I set a variable to a value accordingly so that my G-code can then use the set value? (it will be for a G1 Y xx call, where "xx" is the value)

Thanks-

Offline nicad

*
  •  40 40
    • View Profile
Re: My first Macro-- quick Q's on reading external inputs.
« Reply #1 on: March 28, 2009, 02:05:46 AM »
OK so after doing some more digging I have found that I can check the state of an OEMTRIG with "IsActive(OEMTRIGx)" where x is the #.
I think this pretty much answers my first part.
I can figure out the logic part in the macro.

But I am still not clear on how to get a value into a variable in my code.
Should I place my Macro at the beginning of the Gcode, and in the Macro, have it do something like:

If IsActive(OEMTRIG3) Then
Code "#501=2.65"
...

Then later in my Gcode, use the variable #501?

Also, when you use the "Code" command in a Macro, does the line(s) that the Macro was called from in the Gcode get replaced with whatever is written with the "Code" command?

vmax549

*
Re: My first Macro-- quick Q's on reading external inputs.
« Reply #2 on: March 28, 2009, 04:04:57 PM »
Yes that is one way to get the value into the VAR.

ANother way would be

If IsActive(OEMTRIG3) then  setvar(501,2.65)     



When a CODE"" is run in a macro it runs as a separte entity outside of the gcode then returns to the Gcode. SO the line does NOT actually replace the line in the program but it still will run.

Hope that helps, ((;-) TP
« Last Edit: March 28, 2009, 04:08:08 PM by vmax549 »

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: My first Macro-- quick Q's on reading external inputs.
« Reply #3 on: March 28, 2009, 04:08:16 PM »
here is an option:

In your G code set the three possible values in your param/vars like this:

#1=xx.xx
#2=yy.yy
#3=zz.zz

OR you could drop 3 User DROs on your Screen, and put a button next to each one. you would then put the value that you want in the DRO and that would store the value you want into the param/var Lets say you used UserDRO 2000, 2001, and 2002 and had a button next to each one, and when you pushed the button next to the 1st DRO it would load that value into Param/var #1 for, the others would do #2, and #3 respectively.

The code you would put for instance in Button 1 would be:

Paramone = GetUserDRO(2000)
SetVar(1, Paramone)

Then in my macropump I would put this: (I would use Param/Var 4 to be my on the fly varible var from external buttons.)

if IsActive(OEMTRIGGER1) then
Param = GetVar(1)
end if

if IsActive(OEMTRIGGER2) then
Param = GetVar(2)
end if

if IsActive(OEMTRIGGER3) then
Param = GetVar(3)
end if

SetVar(4,Param)

'///////////////////////

Then in your G-Code, I would call param #4 that would contain the value that one of the three external buttons would cause to be loaded.

With Hard coding the Params then you would have to edit your g code to change values 1-3, but with the User Dros, and Buttons, you could change thier value just by puttin in a new value and hitting the "update" button next to it.

scott
fun times

Offline nicad

*
  •  40 40
    • View Profile
Re: My first Macro-- quick Q's on reading external inputs.
« Reply #4 on: April 03, 2009, 12:23:56 PM »
I used the "setvar(1,x)" route and it worked great.
I even got brave and used some variables to control subroutine loop counters. :)

Thanks for the help yall!