Hello Guest it is March 29, 2024, 08:10:00 AM

Author Topic: Saving DRO values in .txt file?  (Read 7036 times)

0 Members and 2 Guests are viewing this topic.

Saving DRO values in .txt file?
« on: January 30, 2008, 09:25:53 PM »
Is there any code examples for saving DRO values in a .txt file that can opened later for review?  For instance  GetDRO x and y (encoder values) and save to a .txt file when a input is activated. 

Thanks

Offline Bodini

*
  •  216 216
    • View Profile
Re: Saving DRO values in .txt file?
« Reply #1 on: January 31, 2008, 12:46:26 PM »
Ok, i got curious...

i took this: http://www.vbforums.com/archive/index.php/t-342619.html

and added a getoemdro

and got:
Code: [Select]
Dim sFileText As String
Dim iFileNo As Integer
iFileNo = FreeFile
'open the file for writing
Open "C:\Test.txt" For Output As #iFileNo
'please note, if this file already exists it will be overwritten!

xd00d=getoemdro (800)
yd00d=getoemdro (801)
zd00d=getoemdro (802)

'write some example text to the file
Print #iFileNo, "X= ", xd00d
Print #iFileNo, "Y= ", yd00d
Print #iFileNo, "Z= ", zd00d

'close the file (if you dont do this, you wont be able to open it again!)
Close #iFileNo

and then when you view that file as spec'd in the code, it has the dro info at the moment the code was ran (although if the axis was in motion, i dont think it would be accurate, that takes a dll). 

-Nick


Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Saving DRO values in .txt file?
« Reply #2 on: January 31, 2008, 01:19:26 PM »
Interesting perhaps if you did and experiment and ran that in the Macro pump, it would update at least 40 times per second.........
just a thought.

Scott
fun times
Re: Saving DRO values in .txt file?
« Reply #3 on: January 31, 2008, 08:19:00 PM »
Nick,

Thank you very much for the code example!

Also a big Thank you to Scott for helping all the learners here with your time and examples!

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Saving DRO values in .txt file?
« Reply #4 on: February 01, 2008, 06:35:55 PM »
Wow!

Your welcome!

Thanks,

scott
fun times
Re: Saving DRO values in .txt file?
« Reply #5 on: February 01, 2008, 10:01:05 PM »
Few more question on this VB stuff.  I have this code working and dong exactly what I want in VB software:


Dim sFileText As String
Dim iFileNo As Integer
Dim myvar As String
Dim place As String


Private Sub Command1_Click()

iFileNo = FreeFile
myvar = InputBox("Enter place")
place = "c:\" + myvar + ".txt"

Open place For Output As #iFileNo


End Sub

Private Sub Command2_Click()

xd00d = 123
yd00d = 123
Print #iFileNo, "X= ", xd00d
Print #iFileNo, "Y= ", yd00d


End Sub

Private Sub Command3_Click()

Close #iFileNo
End Sub


When you click the first button a window comes up to type in File name.   Then the second button saves "123" in a vertical column as many times as you click it.  The last button Closes the file.

Now I moved this code to Mach the first button and the last button work fine but the button to save the coordinates from GetOEMDro (800) and (801) instead of the the "123" value does not work.
I think it's because the Open command is a private deal.  How do I make the second button work?


What I did was made one button and put this code in it:

Dim sFileText As String
Dim iFileNo As Integer
Dim myvar As String
Dim place As String


iFileNo = FreeFile
myvar = InputBox("Enter place")
place = "c:\" + myvar + ".txt"

Open place For Output As #iFileNo


For the second button this part of the code:

xd00d = getoemdro (800)
yd00d = getoemdro (801)
Print #iFileNo, "X= ", xd00d
Print #iFileNo, "Y= ", yd00d


Last button:

Close #iFileNo

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Saving DRO values in .txt file?
« Reply #6 on: February 05, 2008, 12:10:49 PM »
Hi DennisCNC - If I understand you're explanation correctly, your problem is scope. In the first file your 4 variables are global with respect to your subs (i.e. "visible" to the subs). When you put your code in Mach buttons however the scope of one button does not extend to another. Your 4 variables are "invisible" outside of the first button. (are you getting a "bad file number" error on button 2? Actually I suspect that your 3rd button isn't actually doing anything either but the flaky VB in Mach is not reporting the error - the file is being opened AND closed by the script in button one - (explicitly opened by your "open" code and implicitly closed by going out of VB scope at the end of file).

Incidentally have you taken a look at the plugin download section - Brian has a thing there called jcode - a jog to gcode tool.

Ian
Re: Saving DRO values in .txt file?
« Reply #7 on: February 06, 2008, 05:37:51 PM »
I kind of figured that variables don't go from one button to the next.  I think I need to put this in a macro and have it run a part of the code when a button is pressed,  something like GetUserButton() or GetUserLed()?

I looked at the jog to gcode plugin but you need to jog for it to take the dro value and save it, I need to save the encoder dro's that are on setting tab.