Hello Guest it is March 28, 2024, 09:02:09 PM

Author Topic: Help with loop for writing succesive DRO values to .txt  (Read 7770 times)

0 Members and 1 Guest are viewing this topic.

Help with loop for writing succesive DRO values to .txt
« on: September 05, 2009, 04:33:52 AM »
hello ;D

I'm almost crawling with VB programming.  I'd like to create a code that gets the press of a button and writes the DRO's to a file and keeps appending the values as you keep hitting the button.

I did a bit of a search in the forum and read a bit of the "C. Enable" manual. And so far this is what I've got:

Dim fileData As Integer
Dim fileName As String
Dim place As String

fileData = FreeFile
fileName = InputBox("Part file name:", "please name the file...", "", 350,400)
place = "c:\" + fileName + ".txt"

Open place For Output As #fileData

Xcoord = getoemdro(800)           'gets the X axis DRO value, which is motorized
Ycoord = getoemdro(171)           'gets the value of encoder #2 DRO, Y axis carried by hand for measuring rig
Zcoord = getoemdro(172)           'gets the value of encoder #3 DRO, Z axis carried by hand for measuring rig

Print #fileData, "X= ", Xcoord
Print #fileData, "Y= ", Ycoord
Print #fileData, "Z= ", Zcoord

Close #fileData     


Can I get a little help with how to create a loop for repeating the getoemdro() method every time the "append" button is pressed? Also is it possible/needed to create a second button that closes the file?, In case I want to create a new file/session.

thanks
cheech
« Last Edit: September 05, 2009, 05:48:32 AM by cheech »

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Help with loop for writing succesive DRO values to .txt
« Reply #1 on: September 05, 2009, 09:06:16 AM »
Here is one I posted up a long while back, it saves both DRO and LED states to a file, you can Modify it for your purposes.

'M1001.m1s Save User DROs and LEDs to file and/or this can run in your macro pump.
UserDROs = 1000
UserLEDs = 1000

'Optional, you can have a Brain using a timer
'that for every 5 minutes or so this file will run again, updating the status.
'OR you can have a SAVE user DROs/LEDs button that will activate this, you would need
'to put this code in your MacroPump for the AutoSave and manual Save to work.

'If GetUserLED(2100) Then   'Optional code see above.

Open "UserDROStates.txt" For Output As #1   ' Open to write file.
For x = 1000 To 2255
DROState = GetUserDRO(UserDROs)
Write #1, DROState
UserDROs =(UserDROs + 1)
Next x
Close #1

Open "UserLEDStates.txt" For Output As #2   ' Open to write file.
For y = 1000 To 2255
LEDState = GetUserLED(UserLEDs)
Write #2, LEDState
UserLEDs = (UserLEDs + 1)
Next y
Close #2

'End If 'optional from the if above for auto save functions

'Enjoy Scott
fun times
Re: Help with loop for writing succesive DRO values to .txt
« Reply #2 on: September 05, 2009, 08:43:48 PM »
Thanks Scott for the code! I'm having a bit of a hard time to understand it but as I said, I'm not even scratching the surface with programming. I feel dumb actually. But wont give up,   :-[

I'm trying to get a bit of a help from a friend to do this, I'll post results

thanks
F.
Re: Help with loop for writing succesive DRO values to .txt
« Reply #3 on: December 02, 2011, 05:25:43 AM »
HI, after a looong time, I am back trying to make that code work...


can someone please tell me why this snippet gives a compiler error???

Sub Main
Dim TriggerLED As Integer
TriggerLED = 1005   

TriggerLEDState = GetUserLED(TriggerLED)

If (TriggerLEDState = 1)
SetUserLED(TriggerLED,0)

End If

SetUserLED(Trigger LED,1)
Sleep 1000
SetUserLED(TriggerLED,0)

End Sub 

What i am trying to do is, with the push of a button, check the state of UserLED(1005) and make sure it is off. Set it to on for half second and set it off..

Basically, I want to toggle the state of the UserLED On/off, for a short period of time.... that so I can use it as a trigger for DRO capture, for probing....

thanks all,
cheech

 

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Help with loop for writing succesive DRO values to .txt
« Reply #4 on: December 02, 2011, 11:04:12 AM »
WHy not write the dro values directly to the file from the button press??  Press the button and it appends the values to the file

You do know that mach3 already has a POINT file that will run automatically to record your probed points OR are you doing something different ???

Just a thought, (;-)TP
Re: Help with loop for writing succesive DRO values to .txt
« Reply #5 on: December 02, 2011, 06:34:30 PM »
WHy not write the dro values directly to the file from the button press??  Press the button and it appends the values to the file

You do know that mach3 already has a POINT file that will run automatically to record your probed points OR are you doing something different ???

Just a thought, (;-)TP

TP I got the idea from monitoring the led from a snippet by popabear, if i remember right. I am not sure how to do it with a button toggle only!??? also, it will be good to see the led flashing for 1/2 sec., the plan it to assign the toggle to the probe, later.

i didn't know about the point file, how doesit work? thanks!
c.

   

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Help with loop for writing succesive DRO values to .txt
« Reply #6 on: December 02, 2011, 07:20:13 PM »
see here:

Sub Main
Dim TriggerLED As Integer
TriggerLED = 1005   

TriggerLEDState = GetUserLED(TriggerLED)

If (TriggerLEDState = 1) Then 'you forgot the "then"
SetUserLED(TriggerLED,0)
End If

SetUserLED(TriggerLED,1) 'you had this "Trigger LED" notice space between trigger and LED
Sleep 1000
SetUserLED(TriggerLED,0)

End Sub 

'scott
fun times

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Help with loop for writing succesive DRO values to .txt
« Reply #7 on: December 02, 2011, 07:47:24 PM »
Issue a M40  that will open and allow you to name the point file.

After the M40 is called any time you call a G31 probe routine the trip points are written to the file.

When you are finished issue a M41 and it closes and saves the point file.

(;-) TP
Re: Help with loop for writing succesive DRO values to .txt
« Reply #8 on: December 03, 2011, 04:43:11 AM »
see here:

Sub Main
Dim TriggerLED As Integer
TriggerLED = 1005   

TriggerLEDState = GetUserLED(TriggerLED)

If (TriggerLEDState = 1) Then 'you forgot the "then"
SetUserLED(TriggerLED,0)
End If

SetUserLED(TriggerLED,1) 'you had this "Trigger LED" notice space between trigger and LED
Sleep 1000
SetUserLED(TriggerLED,0)

End Sub 

'scott
thanks scott, bad syntax error. it works!!!!!!!! feels good.
Re: Help with loop for writing succesive DRO values to .txt
« Reply #9 on: December 03, 2011, 05:11:32 AM »
Issue a M40  that will open and allow you to name the point file.

After the M40 is called any time you call a G31 probe routine the trip points are written to the file.

When you are finished issue a M41 and it closes and saves the point file.

(;-) TP

TP, this sounds v. interesting. I need to find out more, mind if i ask questions?

-where do I store the routine? is it a vb file, and can I assign it to a button?
-does mach compensates for the probe tip?

I want to scan 3d surfaces, big objects like surfboards. 100% curves. But I don't need to scan the whole surface ... I only need to scan the the profile, outline and the slices. For the profile and outline I need to sample every 30mm or so, x wise. And for the slices, every 5mm, y wise .

regards, cheech