Hello Guest it is April 16, 2024, 06:29:44 AM

Author Topic: position memorization  (Read 1669 times)

0 Members and 1 Guest are viewing this topic.

position memorization
« on: July 25, 2022, 02:35:19 AM »
good morning
I found on the net this macro stores x axis in the file
since I am not capable of it, is it possible to modify it for all the axes? possibly for "X and Y". I thank those who can help me!

 This example creates a file called myFile.txt in the Mach3 folder. It then reads the current position of the X-axis and writes it to the file. Lastly it closes the file.

Dim X as Double
  Open "C:\Mach3\myFile.txt" For Output As #1
  X = GetDRO(0)
  Print #1, X
  Close #1

 

And here's code that opens the file created in the previous example and reads a single line from it. It then asks the user if it's OK to move the X-axis to the position stored in the file.

Dim Answer
Dim newPos As Double
  Open "C:\Mach3\myFile.txt" For Input As #2              'Open the file for reading
  Line Input #2, newPos                                                      'Read the first line of the file

  Answer = MsgBox ("Is it OK to move the X axis to: " & newPos & "?", 1)

  If Answer = 1 Then                                                           'You pressed OK
    Code "G0 X"& newPos                                                  'Make the move
  End If

  Close #2                                                                              'Close the file
Re: position memorization
« Reply #1 on: July 25, 2022, 04:30:43 AM »
This is an ideal learning opportunity for you.  Most of the clues you need are there in the macro you already have.
Re: position memorization
« Reply #2 on: July 25, 2022, 04:56:54 AM »
John Haine thanks for the answer, tried and tried again I don't come to the head, I know it could be easy to modify it but I'm not really capable !!!! programming are at 0, even less !! :( :(

Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: position memorization
« Reply #3 on: August 05, 2022, 04:47:55 AM »
Code: [Select]
Dim X,Y as Double
  Open "C:\Mach3\myFile.txt" For Output As #1
  X = GetDRO(0)
  Y = GetDRO(1)
  Print #1, X
  Print #1, Y
  Close #1

Code: [Select]
Dim Answer
Dim newPosX, newPosY As Double
  Open "C:\Mach3\myFile.txt" For Input As #2              'Open the file for reading
  Line Input #2, newPosX                                                      'Read the first line of the file
  Line Input #2, newPosY                                                      'Read the second line of the file

  Answer = MsgBox ("Is it OK to move the X axis to: " & newPos & "?", 1)

  If Answer = 1 Then                                                           'You pressed OK
    Code "G0 X"& newPosX & " Y" & newPosY                                                  'Make the move
  End If

  Close #2               

NOT TESTED
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: position memorization
« Reply #4 on: August 05, 2022, 06:43:10 AM »
Good morning
Thanks for your help.
I tested it and it works perfectly, only problem (if you can 'define what i' !!) in the file, after the point, it stores too many numbers
22.000000003381
32.999999998041
I don't know if it can be changed, but it's irrelevant.
thanks TPS for the help offered !!!!!

Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: position memorization
« Reply #5 on: August 05, 2022, 06:54:24 AM »
we had the same couple of day's ago:

Code: [Select]
Dim X,Y as Double
  Open "C:\Mach3\myFile.txt" For Output As #1
  X = GetDRO(0)
  Y = GetDRO(1)
  Print #1, nFmt(X,4)
  Print #1, nFmt(Y,4)
  Close #1
« Last Edit: August 05, 2022, 06:56:42 AM by TPS »
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: position memorization
« Reply #6 on: August 05, 2022, 07:54:35 AM »
perfect!!!! everything works great !!
sorry if I abuse your patience but programming are at 0 (even something less :()
greetings and thanks :)