PDA

View Full Version : Writing Variables to Disk



bstern
09-26-2008, 03:39 PM
Anyone know how to write variables to disk so they can be retrieved with C90.
I think the file is C:\SbParts\Custom\my_variables.sbc but I dont know how to write to it from a shopbot program.
I am writing a routine to Zero to a touch plate outside of the machine bed. I have been able to find the offset to the bed now I just need to write it so I can retrieve it later.

Thanks
Bob

Gary Campbell
09-26-2008, 04:45 PM
Bob...
C#90 calls up the "my variables" file. IF you are trying to make the changes globally, you can open the file and make the changes that you require. The default location is: C:\SbParts\Custom

To move to an alternative location to zero on your plate, this is the section you want:

' if you always want to zero your z-axis in the same place on the table, change these values to
' the coordinates of the point that you want to use
&my_ZzeroStartX = no
&my_ZzeroStartY = no

Just replace the "no" with the X or Y coordinate that you require. This will move the bit to your coordinates EVERY time you run the zzero program. Hope this is what you want. You can also run ShopBot setup to do the same.

If you actually need to write to the file from a running parts file, as far as I know only the "my vars.exe" application does this, but only for the drill to router bit offsets. (as far as I know)

IF you want to keep the zzero file (C2) the same, make a copy of it with a new name, modify as needed, and save it as an unused Custom Cut number.
Gary

bstern
09-26-2008, 04:52 PM
HI Gary,

I am trying to write to the my_variables file.
I am able to move to the position and calculate an offset. Now I want to save that offset variable to the my-variables file using shopbot code. I know how to do this manually. I want to do it with code.

Thanks
Bob

srwtlc
09-26-2008, 05:50 PM
Check out the Programming Handbook on page 17. Never tried it, but here's what it states.

OPEN "path&filename" FOR {INPUT/OUTPUT/APPEND} AS #{number}

ShopBot Files are sequential access text files and use standard BASIC syntax to open a user file for various purposes. If your ShopBot file is going to write to the file you should open it FOR OUTPUT, if you are going to be reading data from it you should open it FOR INPUT, and if you want to add information to an existing file without deleting it’s contents you should open it FOR APPEND. If you open a file FOR OUTPUT and the file doesn’t already exist then the ShopBot will create it, but if the file does exist the data in it will be overwritten. If you need to preserve the data in the file then you may want to either use another name or add your data to the end using the FOR APPEND option.
ShopBot Programming Handbook Page -18-
The file number is the number you are assigning the file you are writing to and is used by the WRITE and PRINT statements to identify which file to work with. Up to 9 open files permitted (number = 1 to 9).
The path&filename can be a variable or specified file name. For path&filename, the path can be relative as in…
OPEN "myfile.sbp" FOR OUTPUT as #1
…which will look for "myfile.sbp" in the current part file folder, or …
OPEN "myfolder\myfile.sbp" FOR OUTPUT as #1
…which will look in your current part file folder for a subfolder named "myfolder" and then look there for “myfile.sbp”. You can also use the full path to the file like…
OPEN "C:\myfolder\myfile.sbp" FOR OUTPUT as #1
It’s important to remember that any file that you’ve opened with the OPEN statement should be closed when you’re finished using the CLOSE statement

bstern
09-26-2008, 06:07 PM
Hi Scott,

I have read page 17 but my problem is basically to change just one line in the file, not create one or replace it.

An example is the drill offset file that replaces the variables :

&my_ZinDrilloffset_T31
and &my_ZmmDrilloffset_T31

Looking at the Drill Offset.sbp file, Ryan sends the change to a temp file called TempVar.txt and then calls an executable with the following line:

Shell "C:\SbParts\Custom\MyVars.exe c:\SbParts\TempVar.txt"

Ryan is away at a camp and no one at SB seems to know how this works.
I have been playing with it for a while and cant figure it out.

Anyone?

knight_toolworks
09-26-2008, 06:29 PM
here is what I do. this zero's the bit takes into account the .121 of the plate and lets you input the thickness. so you don't ahve th change any settings. just use a jog command to move it to the place your plate is.
'zero for tabletop any location
c2
jz .121
zz
INPUT "What is the material thickness?" &thick
JZ,&thick
VA,,,0.0 'Set Z to zero if the material surface is to be zero.
jz 1
jh

bstern
09-26-2008, 07:10 PM
Let me explain what I trying to do.
Fist, I zero to the machine bed.

I have a 2nd zzero plate to the side of the machine.

Stetup:
Need to be run once after resurfacing the table
Step1- run regular C2
Step2- Find the difference between Zero and the plate.
Step3- Write this as a variable in the variables file. (my current problem)

Setting Zero to table after setup is run:
Step1 C3 to zero X,Y to prox
Step2 Move to locations of plate.(To left of table bed)
Step3 move Z (or A) down to find plate. Set Zero based on this + the offset variable I wrote in the setup.

This will allow me to re zero without having to remove material from the machine.

I also plan on drilling a hole in the plate and combine all setup routines to calculate offsets for A and drill. (I can do this without using the bars because I use only 2 fluted bits that are symmetrical.)

So in the end I want to be able to come in, turn on the machine on and hit C5 and the machine will set all zeros.
Then if I need hit C6 and have it calculate both the drill and A offsets.

This is all real simple to do but I need to be able to create and update some variables in the my_variblae file.

ShopBot does this in their offset routines but I cant figure our how?

And Yes I could write the varable in manually but, how fun would that be!

srwtlc
09-26-2008, 08:10 PM
Bob, try this, adapted from the drill offset file.

In your file, where desired, put this (change text to suit)...

&tempvar = "c:\SbParts\TempVar.txt"
OPEN &tempvar FOR OUTPUT AS #1

'Do what you need to do to create your new values like in the drill offset file and then write them to the temp file.
'Watch the syntax. Quotes "" and semi-colons ;

WRITE #1; "&your_value = "; &your_new_value

CLOSE #1

pause .5

bstern
09-27-2008, 12:57 PM
Finally Success!!!

Scott, I had been using that script to no success.

The problem was that the case on the variables must be exact. Now that sounds like it should be obvious. Here is the rub. When you do a list variables they come out in all caps. When you edit the My_varaibles file they are in mixed caps.

My solution, to make things easier in the future, was to rewrite the variables back to the file and guess what? They go back in all caps. It does remove all the comments if you edit it via a text editor.

I think shopbot should look at standardizing their use of caps for variables.

Thanks Steve, Scott and Gary!

bstern
09-27-2008, 01:24 PM
Ive been thinking about the consequences of my solution.

I checked the setup routine and it seems it no longer works. I assume all utilities that write to the My_variables file will no longer work.

I guess I will have to adhere the the spelling in the original file.

Waring! Using the control software to write your variables back to the My_variables file will change the caps and I think render some utilities inoperable.

Its seems best to edit via a text editor or if you are writing your own utilities, edit the file and look at the spelling format in the file. Then use that with the TEMPVAR.txt and MyVars.exe.


(even the TempVar.txt gets written as file name = TEMPVAR.TXT)

Stadardization of Caps would go a long way here!

beacon14
09-28-2008, 10:50 AM
I just use a separate file to save the variables I want control over. They don't have to be in the my_variables file.

Gary Campbell
09-28-2008, 05:48 PM
Bob...
To expand on what David says above, write any variables you wish to a file, and for easy callup, save it as a "CustomX.sbc" in the Custom folder. Then you can call it up when needed.
Gary

bstern
09-29-2008, 12:30 PM
That was my first plan.
But, then I realized I wanted to work with the drill offsets and 2nd Z offsets. They could be moved elsewhere but I though it best to work with them where the were. This way it did not render the original utilities and variables useless.

Bob

If I had just cut and pasted the lines of code I needed, it would have worked out without any issues. I cut some code and modified it and that's when things went wrong.

Everything is going to be easy once I figured out that the Variables are in different spelling format in the file than shown when you display it or when you use the write variables to file command. And that you need to use that with the MyVars.EXE. Also that the variable has to be there in the fist place.

Hey, Its really easy once you know how it works!


Here is a little info on how to use the MyVars.exe.

Note: As far as I can tell this executable file only REPLACES already existing Variables (Thanks Scott) in the My_Variables file.


1.You need to write the variable name exactly as it is written in the My_Variables file (not as used in programs)+ "space = space new variable value", to a file called TEMPVAR.TXT in the SbParts folder.

2 Run MyVars.exe using the line
Shell "C:\SbParts\Custom\MyVars.exe c:\SbParts\TempVar.txt"

MyVars.exe will replace the value of the variable in the MyVariables.sbc file and will delete the TempVar.txt file.

This may help someone like me in the future. But, if you can reach Ryan at shopbot he most probably be of more help.

Thanks to all who helped! I'm off and running but need to put it aside for a week or 2. Ill let you know how it turns out.

Bob

srwtlc
09-29-2008, 01:05 PM
This file "SbW_ShopBotProgrammingStatements.txt" found here "C:\Program Files\ShopBot\Developer Tools\Docs" has a little info that helps with this subject also.

Bob, after reading of the "Case" problems you encounter while working on this, I thought that the last sentence of the file was particularly interesting. ;-)

"VARIABLE CASE
Note that internally, all string variables are converted to upper case when they are entered."

bstern
09-29-2008, 01:10 PM
Scott,
I figured that out the hard way.
I think they should consider writing the variable names in the my_variables file in caps to be consistent.

They would have to rewrite all the utilities that write to that file so it may be tough for them.
Maybe on the next rewrite of control software.

Bob