Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2012, 07:11:01 PM

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
| | |-+  Read value from file and put it to a DRO...
Pages: 1   Go Down
Print
Author Topic: Read value from file and put it to a DRO...  (Read 540 times)
0 Members and 2 Guests are viewing this topic.
giannis121
Active Member

Offline Offline

Posts: 128


View Profile
« on: March 29, 2011, 11:43:41 AM »

How can i read a value from a txt file (on a VB script button)
and then put the value to a DRO?

The txt file contains only the number value.
I have tried to use "file input/output" from the VB-Script-Commands.pdf in Mach Wiki,
with no success.

Any ideas would help.
Kind regards,
Giannis
Logged
ger21
Global Moderator
*
Offline Offline

Posts: 2,619



View Profile WWW
« Reply #1 on: March 29, 2011, 12:23:48 PM »

Try something like this:

FilePath = "C:\DRO.txt" 'Put the full path here

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfile(FilePath)
Set DROfile = f.OpenAsTextStream(1)

DROValue = CDbl(DROfile.readline)

DROfile.Close

SetOEMDRO(*********, DROValue)
Logged

zealous
Active Member

Offline Offline

Posts: 486



View Profile WWW
« Reply #2 on: March 29, 2011, 12:40:26 PM »

Also make sure you are using the correct command.
If you are setting a OEMDRO or UserDRO.
I have tested and the "Input" works fine here is an example using Input as well:
If you have 1 value to set simply change the "DROS = 1" to what you want, for example to set DRO800, "DROS = 800".

Code:
Dim fich As String
Dim FileData As String
 
'////////////FILE LOCATIONS//////////////////////////////////////
fich="C:\Mach3\MyFile.txt"

'//////////CHECK If FILES EXIST/////////////////////////////
If Dir(fich)="" Then
MsgBox "File Isn't There!"
Else

'//////Set DRO's/////////////////////////
DROS = 1
'////////////////Open To Read file//////////////////////////
Open fich For Input As #1
Do While Not EOF(1)

'////////////Read a Line of data////////////////////////
Line Input #1, FileData

'////////////Set User DRO's////////////
If(DROS > 999) Then
SetUserDRO(DROS, FileData)
Else
'////////////Set OEM DROs////////////
SetOEMDRO(DROS, FileData)
End If

DROS = DROS + 1
Loop

Close #1
'////////////File Isnt there////////////
End If
« Last Edit: March 29, 2011, 12:44:02 PM by zealous » Logged

Regards, Jason Blake

www.Fusioncnc.com
giannis121
Active Member

Offline Offline

Posts: 128


View Profile
« Reply #3 on: March 29, 2011, 01:30:51 PM »

Very helpful!!
Thanks!

And by the same way how can i get a DRO and write it to a txt file?

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

Posts: 1,707


Briceville, TN, USA


View Profile WWW
« Reply #4 on: March 30, 2011, 07:34:31 AM »

from an old post,

'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/
giannis121
Active Member

Offline Offline

Posts: 128


View Profile
« Reply #5 on: April 01, 2011, 04:43:53 AM »

Thank you! Thats it!
Logged
Pages: 1   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!