Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2012, 07:40:15 AM

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
| | |-+  Help with loop for writing succesive DRO values to .txt
Pages: 1 2 »   Go Down
Print
Author Topic: Help with loop for writing succesive DRO values to .txt  (Read 978 times)
0 Members and 1 Guest are viewing this topic.
cheech
Active Member

Offline Offline

Posts: 7


View Profile
« on: September 05, 2009, 03:33:52 AM »

hello Grin

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, 04:48:32 AM by cheech » Logged
poppabear
S S SYSTEMS, LLC
Global Moderator
*
Offline Offline

Posts: 1,707


Briceville, TN, USA


View Profile WWW
« Reply #1 on: September 05, 2009, 08: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
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/
cheech
Active Member

Offline Offline

Posts: 7


View Profile
« Reply #2 on: September 05, 2009, 07: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,   Embarrassed

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

thanks
F.
Logged
cheech
Active Member

Offline Offline

Posts: 7


View Profile
« 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

 
Logged
BR549
Active Member

Offline Offline

Posts: 2,550


View Profile
« 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 Huh

Just a thought, (;-)TP
Logged
cheech
Active Member

Offline Offline

Posts: 7


View Profile
« 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 Huh

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.

   
Logged
poppabear
S S SYSTEMS, LLC
Global Moderator
*
Offline Offline

Posts: 1,707


Briceville, TN, USA


View Profile WWW
« 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
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/
BR549
Active Member

Offline Offline

Posts: 2,550


View Profile
« 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
Logged
cheech
Active Member

Offline Offline

Posts: 7


View Profile
« 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.
Logged
cheech
Active Member

Offline Offline

Posts: 7


View Profile
« 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

Logged
Pages: 1 2 »   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!