Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Ya-Nvr-No on May 17, 2014, 12:05:25 PM

Title: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 12:05:25 PM
Been mucking around looking in to reading and writing to variables and trying to figure out the variable#'s
Reality, I was trying to find a way to set the persistent dro's so when I restart it has the same dro coords as when it shut down.
not sure where it picked these from but can not seem to reset them, as the data is held in the xml file not the machine.ini

There has to be a way to write them to memory on shutdown or maybe write them to a file and then read the file and fill the variables with the stored locations.

-- inst 0 is the hobby version 0 is the only one, the pro versions will have more capabilities and Mach4 can then run multiplies instances.
-- this was placed under a button click to read and set, step thru and experiment.
inst= 0

--how to read variables
local valx = mc.mcCntlGetPoundVar(inst, 5021);
local valy = mc.mcCntlGetPoundVar(inst, 5022);
local valz = mc.mcCntlGetPoundVar(inst, 5023);
local vala = mc.mcCntlGetPoundVar(inst, 5024);

--how to set variables (in this case to zero)
mc.mcCntlSetPoundVar(inst, 5021, 0);
mc.mcCntlSetPoundVar(inst, 5022, 0);
mc.mcCntlSetPoundVar(inst, 5023, 0);
mc.mcCntlSetPoundVar(inst, 5024, 0);


-- this is a listing of a lot of the variables I found. As you can see there is a pattern to some like kinds
not all as most of course are zero's and there are a lot of them. Your numbers will vary for most.
I labeled some I could get a handle on. Others will have to wait for Documentation.
Writing a while loop to read all the variables > 0 and then writing to a text file or even a wizard is in the plans.

2132=900
2134=10

3005 =200
3101 =3.141592
3102 =2.718282
4001=10
4002 =170
4003 =900
4004 =911
4005 =940
4006 =200
4007 =400
4008 =490
4009 =500
4010 =990
4011 =150
4012 =1
4013 =610

--my machine always defaults to these #' on startup
5021=0.254 --machine coordinate x
5022=1.27 --mc y
5023=1.27 --mc z
5024=50.8 --mc a

5025=453.571429 --not sure what this number is

5110= headshift x
5111= hs y
5112= hs z
5113= hs a
5114= hs b
5115= hs c

5201= workshift x
5202= ws y
5203= ws z
5204= ws a
5205= ws b
5206= ws c

5221= g54x
5222= g54y
5223= g54z
5224= g54a
5225= g54b
5226= g54c

5241= g55
5261= g56
5281= g57
5301= g58
5321= g59
--and on and on they go as blocks of 20

7785=tool 1 Length
7786=Length wear
7788=1/2 Diameter
7789=1/2 Dia wear

7795=tool 2
7805=tool 3
7815=tool 4
7825=tool 5
7835=tool 6
7845=tool 7
7855=tool 8
7865=tool 9
7875=tool 10
8375=tool 60
8775=tool 100
8785=tool 101
9775=tool 200
9785=tool 201
9795=tool 202
-- and these go on in blocks of 10

10275=tool 250 Length
10276=length Wear
10278=1/2 Dia
10279=1/2 Dia wear

10315=tool 254 Length
10316=length Wear
10318=1/2 Dia
10319=1/2 Dia wear

15000=2418317446859018500000000000000000000000000000000000000000000000000000000000000
15001=2418347089633870200000000000000000000000000000000000000000000000000000000000000
15002=2418376732408721800000000000000000000000000000000000000000000000000000000000000
--up to variable 15038 with those in variations

below are some screen shots of where to look at your variables
and yes you can have multiple ranges and multiple display groups displayed
Pin it to keep them on the top of screen.

--just a random lot of variables and the values
15043=92
15045=17
15046=90
15047=91
15048=94
15049=20
15050=40
15051=49
15052=50
15053=98
15054=15
15055=54
15056=64
15057=97
15058=69
15059=-1.#QNAN0
15060=-1.#QNAN0
15061=-1.#QNAN0
15063=13
15064=10
15065=900
15067=-1
15068=-1
15069=-1
15102=-1
15104=-1
15105=-1.#QNAN0
15106=-1.#QNAN0
15107=-1.#QNAN0
15108=-1.#QNAN0
15109=-1.#QNAN0
15110=-1.#QNAN0
15111=-1.#QNAN0
16127=5000
16288=3600
16293=5


Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 12:22:23 PM
HIYA Craig, I have a #VAR report generator for MACH3 that does that trick. It sweeps through ALL the Var Numbers and reports ONLY the one that are > OR <  0

IT IS important that you check for values < AND > because some values are negative values.

Save the text file and send it to Notepad for viewing and printing.

I trick I use a lot when trying to find something in the VARs . I input a Value into a DRO that is easy to spot then I create the report and open in Notepad. THen do a search on that string to find the value and I then HAVE the Var number where I found the value.


Thnaks, (;-) TP
Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 12:24:51 PM
ALSO Steve Wrote a #VAR monitor for Mach4 that you can set a range and View the Values .

It works great but does not give the option to save or print. You CAN lock it on top if needed, that works well for testing code as the values are updated in real time.

(;-) TP
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 12:30:34 PM
have not see anything other than what Mach4 provides
TP I too wrote a plugin years ago for that very same purpose.

also I use the iReg0 register (instance) I can read and write to it from other external scripts, such as a Wizzard that can read the Axis DRO's or pass and set feed rates
Title: Re: Variables reading and writing
Post by: ger21 on May 17, 2014, 12:31:41 PM
How do you open these Windows???
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 12:35:09 PM
Menu Diagnostic then Reg File list of all the #variables is at the bottom

TP I do believe I was referring to that same ability you mentioned (Mach4 provides) unless it is a separate program you received.
Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 12:39:32 PM
You just type faster than I do (;-) it is the same thing. One nice thing is it runs in real time AND yo can lock it on top and view the values as they change when running a Gcode Parametric program. SAME as the Var monitor in Mach3.

NOW IF you can figure out HOW to see the #var values in the Gcode window AS it runs THAT would  be a NICE touch (;-)

  FOR EXAMPLE

G01 X#1 Y#2 Z#3    (#1=10.203 #2= 1.0435 #3= -1.128)

OR have it pop up in a small side window off to the side of the Gcode window.

BUT it would need to stay in sync with the Gcode LINE.

(;-) TP
Title: Re: Variables reading and writing
Post by: ger21 on May 17, 2014, 12:41:54 PM
Thanks.
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 12:50:03 PM
maybe you can associate them with the line number when read and then display as used

guess it depends on if the look ahead read line has a line number and was given a variable that can be used.

Would be interesting to view the variables while running gcode variables,  guess I could try that  ::)

TP you sure do come up with all kinds of things others should do  >:D Trouble Maker
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 01:18:53 PM
current machine goto points

variables 5001 current goto point in x
variables 5002 current goto point in y
variables 5003 current goto point in z
variables 5004 current goto point in a
or
variables 5021 current goto point in x
variables 5022 current goto point in y
variables 5023 current goto point in z
variables 5024 current goto point in a
Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 01:30:54 PM
Trust me Craig IF I could do it you would never hear a word out of me on such matters. I would be too busy to chat.

You do know that one does NOT have to do anything I am just describing functions that have proven very usefull over time  ;D

You can ether have a LEXUS or a Model T for a controller which would you like to have.  >:D

Yo HAVE taught me a great deal through examples , and I can take those and make things AS LONG as I have enough examples to work with.

NOW do you know how to install socket moduals into LUA. I need access to the Socket.smtp in order to send alert Emails from Mach4. Native LUA has no such function as far as I can find.

GEES even the lowly CB language can do that  :o
Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 01:35:07 PM
Brian Should  be able to provide a LIST of ALL the #vars in mach4 AND their description/function. He had to create them so there should be a list.

Just a thought, (;-) TP
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 02:03:11 PM
That's above my pay grade (Sockets that what I use to break bolts off)
Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 02:47:09 PM
OK I do not think we can use Socket moduals here as Brian would have to include them in his Distributable file.

I think, (;-) TP
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 02:55:21 PM
ran your little example with variables
Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 04:59:27 PM
No dought the Var monitor works well I am very pleased to have it. Very hard to test complex parametric code without it.

AND paramateric Gcode in MACH4 WORKS VERY WELL as well.

(;-) TP
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 05:21:20 PM
so far there are some things that do have some merit, but this learning curve is trial and error most of the time.
Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 06:35:47 PM
YES it is without DOCUMENTATION. Like wondering in the Desert looking for the OASIS

Here is a NEW Thread Milling Wizard.

Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 07:21:34 PM
Or perhaps a new Circular Pocket Wizard. The new G12/13 routines made that one easy .

AND YES I did steal that image(;-)

I do wish the Lua Editor was a bit more friendly. All the crashing makes it HARD to get anything done when it is time to test your code
Title: Re: Variables reading and writing
Post by: ger21 on May 17, 2014, 08:27:55 PM
All the whining about Lua and two weeks later he's spitting out wizards. Must not be that hard. ;)
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 08:37:36 PM
Looks like you've done good Terry, do they spit out the correct code?
I too like the bolt hole pattern wizard to use as a template.
Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 08:43:11 PM
NOPE still can't do it without example code. I am just cutting and pasting here from Brians original example. THAT is not programming that is fishing with rocks, sooner or later you WILL hit a fish in the head and have supper.

I do have a question on wizards. I need to be able to LOAD the program on close of the Wizard. The Wizard uses this code to gather the FileName to save.

I cannot figure out WHAT VARIBLE it saves the NAME as. I need that NAME to be able to open the file in Mach4 before the wizard closes.

I use MsgBoxes to try and test all the variables I could think of and it always reports NIL. It would appear that it uses the local Variable "file" but I get NIL when I display that string right after that function.

  -- End of Gcode Write fILE to DIR    
                 local file = wx.wxFileDialog(panel, "Select Gcode File Name","",""," Tap files (*.tap)|*.tap",
                        --wx.wxFD_SAVE,wx.wxDefaultPosition,wx.wxDefaultSize, "File Dialog" );
                         wx.wxFD_SAVE + wx.wxFD_OVERWRITE_PROMPT,wx.wxDefaultPosition,wx.wxDefaultSize, "File Dialog" );
             --wx.wxMessageBox(tostring(file))
    

        if (file:ShowModal() == wx.wxID_OK) then
            local path = file:GetPath()

            --wx.wxMessageBox(tostring(path))

            io.output(io.open(path,"w"))
            io.write(gcode)
            io.close()
        end
        SaveSettings()
    end)



IT DOES write the correct file name on the save BUT what IS the file name  ????????



HIYA CRAIG, I have the code that runs the functions I just need to convert it to LUAISM  Right noww it just posts the Safety Blocks AND the file end Blocks.

I ran out of ROCKS , (;-) TP
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 17, 2014, 10:29:39 PM
With a lot of struggling, a little direction & help, I now have a Wizard that shows the axis DRO's in real time (set to 100ms scan) and that can be pinned to the screen's top. This uses iRegs0 to Write and Read the small floating popup. From this template, I can now create several other useful screen popups and also add to this as my Screen MPG

Took a whole lot of rocks, Terry  :P
Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 10:42:57 PM
With a lot of struggling, a little direction & help, I now have a Wizard that shows the axis DRO's in real time (set to 100ms scan) and that can be pinned to the screen's top. This uses iRegs0 to Write and Read the small floating popup. From this template, I can now create several other useful screen popups and also add to this as my Screen MPG

Took a whole lot of rocks, Terry  :P

HIYA Craig that is my problem NOT near enough rocks to be fishing in LUA

LOOKS GOOD

(;-) TP
Title: Re: Variables reading and writing
Post by: Bodini on May 17, 2014, 10:51:42 PM
HIYA Craig, I have a #VAR report generator for MACH3 that does that trick. It sweeps through ALL the Var Numbers and reports ONLY the one that are > OR <  0

IT IS important that you check for values < AND > because some values are negative values.

Save the text file and send it to Notepad for viewing and printing.

I trick I use a lot when trying to find something in the VARs . I input a Value into a DRO that is easy to spot then I create the report and open in Notepad. THen do a search on that string to find the value and I then HAVE the Var number where I found the value.


Thnaks, (;-) TP

If I read you correctly, I made something like that last night for Mach 4.  Like you said, its good to seek out a certain number you are looking for with a search in notepad (i like notepad++, btw).  This script has similar concepts used in that tool table writing script.  I have it set to stop at 14000 because it sometimes doesnt work after that for reasons that are beyond my knowledge (as most things in this codey stuff are)  :D

-Nick

Code: [Select]
file = io.open("registry introspect.txt","w") -- open a new current file
file:write("Mach 4 Register Variables\n\n")
inst = mc.mcGetInstance()
regstart = 1  --start registry #
regend = 14000 --end registry #
regstep = 1  --step increment
rowno = regstart

for L1 = regstart,regend,regstep do  --creates the registry number to check
    v1 = mc.mcCntlGetPoundVar(inst, L1)  --gets the var from the registry number

    if v1 < -1000000 then
        --filters out big negative numbers
    elseif v1 > 1000000 then
        --filters out big positive numbers
    elseif v1 == 0 then
        --filters out zero values
    else
        l1output = string.format ("%5d = %10.4f \n",rowno,v1)  --formats registry var number for writing
        file:write(l1output)  --writes to file
 
end
    rowno = rowno + 1 --iterate the row number
end
file:write ("\n")  
file:write(os.date("Created: %x  %X"))
file:close()
[\code]

Title: Re: Variables reading and writing
Post by: BR549 on May 17, 2014, 11:22:38 PM
HI ALL, trying to get the probe file open to work but no luck so far. the error message says the format is 
 
mcCntlProbeFileOpen(number, string, string, number");

The probing NOTES says this should work, but notta so far

mcCntlProbeFileOpen(inst, "myProbeFile.csv", "%.4AXIS_X, %.4AXIS_Y, %.4AXIS_Z");

Anyone played with this yet, ????
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 18, 2014, 07:40:20 AM
Nice job Nick, I'll try it out

Thought id post a text file on pound(#) variables  for another reference document

hell I thought that character was renamed "hash tag"  ;)


Terry: I did not have luck getting the information found in the Probe doc to write to a file, thou it did create the file just nothing was passed to it. Have to revisit and throw more rocks, as the more I understand whats up.
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 18, 2014, 08:34:53 AM
found this worked to 15000 for me (at least I did not get any messages, so assume it works)

    if (v1 < -1000000 or v1 > 1000000) then
        --filters out big numbers
    elseif v1 ~= 0 then
        l1output = string.format ("%5d = %0.6f \n",rowno,v1)  --formats registry var number for writing
        file:write(l1output)  --writes to file
    else
    end

Thanks Nick ya did good. nice to have new tools.  ;D
Title: Re: Variables reading and writing
Post by: BR549 on May 18, 2014, 02:58:13 PM
HIYA Craigs Just a note there is no E #var, the Eword is reserved in mach4. Thanks for the list. I will add it to my Mach4 manual.

What code did you use to open and write the probe file ? An example would be nice in lua of me running LOW on rocks(;-).

Just a thought, (;-)TP
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 18, 2014, 03:45:34 PM
the list I got from Steve Murphree

the script was posted, not much to it. so ya don't need big rocks or many of them to paste the script in a button click.
You do have to set up the iRegs0 with the variable names, don't forget to restart Mach4 to initiate them.

http://www.machsupport.com/forum/index.php/topic,27256.msg192478.html#msg192478
Title: Re: Variables reading and writing
Post by: Bodini on May 18, 2014, 04:23:18 PM
found this worked to 15000 for me (at least I did not get any messages, so assume it works)

    if (v1 < -1000000 or v1 > 1000000) then
        --filters out big numbers
    elseif v1 ~= 0 then
        l1output = string.format ("%5d = %0.6f \n",rowno,v1)  --formats registry var number for writing
        file:write(l1output)  --writes to file
    else
    end

Thanks Nick ya did good. nice to have new tools.  ;D

Nice one, Craig.  I had a feeling it could be improved on, but once it worked for me i said 'screw it' and quit for the night. ;-)
Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 18, 2014, 06:19:08 PM
Added a Feed Rate Over Ride DRO and took the view variables idea to the next step and put all values not equal to zero in a combobox

The update button is attempt to update the combo box, haven't quite got the handle on getting that to work as of yet.  :P
Title: Re: Variables reading and writing
Post by: BR549 on May 19, 2014, 11:39:57 PM
HIYA Craig, In your Var list  is shows

#define CURRENT_X      5021
#define CURRENT_Y      5022
#define CURRENT_Z      5023
#define CURRENT_A      5024
#define CURRENT_B      5025
#define CURRENT_C      5026

These appear to be machine coords, would you know what the work coords numbers are ? 

Also you can add to the upper list #500 -#600 are global persistant vars's

(;-) TP

Title: Re: Variables reading and writing
Post by: Ya-Nvr-No on May 20, 2014, 07:02:15 AM
Lets hope they get to all Fanuc variables someday, I used to love 3001 for getting run times, when I had to meet a cycle time.
there is a slew of great variables which would be nice to see implemented.
Found variables one of the best ways to keep people from editing your program.
What they don't see they can not change.
I could change positions mcodes, feedrates, tools, spindle speeds just as an example while a program was running by just changing the variable before the next time it called it.
Great for production runs when you can't stop edit and then restart.
Perfect for when your doing an evaluation on new tooling with a salesman
create a variable using 3001 to update your cycle timer then during the run tweak some variables and see how the changes effect overall times.
If nothing else Mach4/Macro B should make better programmers out of the people that write programs.
As a desktop simulator, saves on testing at the machine.
Just that feature alone should sell Mach4 to industry, prove to yourself and your boss your program works before you get that machine time.

This link is a great resource for learning Macro B programming
http://www.machinetoolhelp.com/Applications/macro/macro_variables.html
Title: Re: Variables reading and writing
Post by: BR549 on May 21, 2014, 11:46:38 AM
YEP those #var are darn handy.

But The 2 series we have to use  BOTH are in MACHINE Coordinates  and are for the most part useless

#define CURRENT_X      5021

#define Last_Output_X     5001

Hopefully Soon we will get it all updated /Fixed ,etc

(;-) TP