Hello Guest it is March 29, 2024, 04:35:25 AM

Author Topic: Read value from file and put it to a DRO...  (Read 5303 times)

0 Members and 1 Guest are viewing this topic.

Read value from file and put it to a DRO...
« on: March 29, 2011, 12:43:41 PM »
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

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Read value from file and put it to a DRO...
« Reply #1 on: March 29, 2011, 01: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)
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline zealous

*
  •  489 489
  • HI!
    • View Profile
    • Artsoft Solutions
Re: Read value from file and put it to a DRO...
« Reply #2 on: March 29, 2011, 01: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: [Select]
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, 01:44:02 PM by zealous »
Re: Read value from file and put it to a DRO...
« Reply #3 on: March 29, 2011, 02: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

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Read value from file and put it to a DRO...
« Reply #4 on: March 30, 2011, 08: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
fun times
Re: Read value from file and put it to a DRO...
« Reply #5 on: April 01, 2011, 05:43:53 AM »
Thank you! Thats it!