Welcome, Guest. Please login or register.
Did you miss your activation email?
May 23, 2012, 10:54:03 PM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Calendar Links Login Register
+  Machsupport Forum
|-+  Mach Discussion
| |-+  VB and the development of wizards
| | |-+  My first Macro-- quick Q's on reading external inputs.
Pages: 1   Go Down
Print
Author Topic: My first Macro-- quick Q's on reading external inputs.  (Read 1143 times)
0 Members and 2 Guests are viewing this topic.
nicad
Active Member

Offline Offline

Posts: 30


View Profile
« on: March 28, 2009, 12: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-
Logged
nicad
Active Member

Offline Offline

Posts: 30


View Profile
« Reply #1 on: March 28, 2009, 01: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?
Logged
vmax549
Guest
« Reply #2 on: March 28, 2009, 03: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, 03:08:08 PM by vmax549 » Logged
poppabear
S S SYSTEMS, LLC
Global Moderator
*
Offline Offline

Posts: 1,707


Briceville, TN, USA


View Profile WWW
« Reply #3 on: March 28, 2009, 03: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
Logged

Commercial Mach3: Screens (regular and flash), Wizards, Plug-ins, Brains, PLCs, Macros, ATC's, machine build, retrofit and Prototyping
http://sites.google.com/site/volunteerfablab/
nicad
Active Member

Offline Offline

Posts: 30


View Profile
« Reply #4 on: April 03, 2009, 11:23:56 AM »

I used the "setvar(1,x)" route and it worked great.
I even got brave and used some variables to control subroutine loop counters. Smiley

Thanks for the help yall!
Logged
Pages: 1   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!