Hello Guest it is March 28, 2024, 07:25:02 PM

Author Topic: Mach3 MacroPump Get Current Time in Milliseconds  (Read 6564 times)

0 Members and 1 Guest are viewing this topic.

Mach3 MacroPump Get Current Time in Milliseconds
« on: January 30, 2016, 11:00:15 PM »
I'm running a Mach3 MacroPump script that gets the current time and positions for the x and y axis, and then appends this info to a text file. I need the time resolution to be in milliseconds, but can't find a way to get anything better than seconds with the Cypress Enable functions. Does anyone know a way to do this? It seems like Visual Basic has millisecond formatting for its time fetching functions, but I can't get any of these functions to work in the MacroPump, and Cypress Enable's Time(Now) function that I am currently using doesn't seem to accept any millisecond formatting parameters. Here is my current code for reference:

  Dim t As String                            
  Dim x As Double
  Dim y As Double
  Open "C:\Mach3\macros\Dual_Axis_Test_Stand\timePositionLog.txt" For Append As #1
    t = Time(Now)
    x = GetDRO(0)
    y = GetDRO(1)
    Print #1, t
    Print #1, x
    Print #1, y
  Close #1

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Mach3 MacroPump Get Current Time in Milliseconds
« Reply #1 on: January 31, 2016, 02:54:20 PM »
I take it you are after an absolute time value not an incremental value ?? You are also going to tie up a lot of CPU time with that routine.

(;-) TP
Re: Mach3 MacroPump Get Current Time in Milliseconds
« Reply #2 on: January 31, 2016, 02:57:04 PM »
Yes, I'm after an absolute time value. That said, getting an absolute start time and then incrementing from there would be fine, as long as the increments were representative of real-time measurements.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Mach3 MacroPump Get Current Time in Milliseconds
« Reply #3 on: January 31, 2016, 03:19:27 PM »
USe time(now) for teh start time and SetTimer(1), GetTimer(1) as teh incremental time in MS. You do realise that teh macropump runs continous and you cannot start and stop it. SO you will be writing to teh file the entire time that mach3 is running UNLESS you program around that.

(;-) TP
Re: Mach3 MacroPump Get Current Time in Milliseconds
« Reply #4 on: January 31, 2016, 05:39:45 PM »
I'm aware that the macropump runs continuously and will be appending the file the whole time - that should be fine :-)  What confuses me is how to set a timer once and not have it reset each time the macropump runs. Is there a way to section off a chunk of the macropump to only run the first time in a session? Also, I haven't found any documentation for GetTimer() and SetTimer(). Are these automatically formatted to milliseconds, or do I need to set them that way? Thanks!

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Mach3 MacroPump Get Current Time in Milliseconds
« Reply #5 on: January 31, 2016, 08:47:13 PM »
YOu need to get the Macro Programing guide.

THese are special timers. Actually all it does is create a reference point on an accurate system timer so it takes up ZERO resourses and you could run 100s of these if you needed to without any extra load on the CPU.

At teh beginning of Period use teh GetTimer(1 to retreive teh time from teh last settimer(1) to teh Value. At teh end of the period  use teh SetTimer(1) to restart teh timer.  OR verse versa if needed. YO have to figure out what teh period is that you are trying to measure.

The refresh rate of teh macropump is 10hzs BUT that does not always mean it will run at that rate it all depends on how busy Mach3 really is running teh System. IF it gets too busy it may stall or slow down teh macropump ????

Mach3 was never design to be a Data Accquisition system it is a Gcode motion controller. 

You cannt stop or start teh Macropump . It starts up teh second teh software goes active and runs until it closes at 10hzs sample rate.  BUT you can program IF conditions based on say a LED state to start and stop a code segment to run or be skipped over.

(;-) TP


Re: Mach3 MacroPump Get Current Time in Milliseconds
« Reply #6 on: January 31, 2016, 11:22:42 PM »
Thanks much for your responses. I'm still a bit confused, though. I have the Mach3 VB programming guide, but don't see anything about SetTimer() & GetTimer or about LED states. It would be very helpful if someone could answer the following 2 questions and provide a brief code example:

1. How do I use SetTimer() so that it continues running throughout the cycling of the macropump, without resetting the timer each time the macropump loops (I need the total elapsed time of given Mach3 session)? Maybe that time already operates this way by default?

2. Ideally, I'd like to have a loop within the macropump that only fires if a Gcode file is running. This way, the macropump would of course always be running while Mach3 is open, but my code would only run while my machine is moving. Can maybe do this by listening for LED states to trigger an IF statement? Or would this be done another way?

Thanks!

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Mach3 MacroPump Get Current Time in Milliseconds
« Reply #7 on: February 01, 2016, 10:03:16 AM »
Mach3_V3_Programers Reference Manual  Pages 33 & 78

(;-) TP
Re: Mach3 MacroPump Get Current Time in Milliseconds
« Reply #8 on: February 01, 2016, 10:13:36 AM »
Thanks for the reference, though page 34 is GetOEMDRO and page 78 is MinX. I do set GetOEMDRO on page 33 and SetTimer on page 115. I found a list of OEM LED #'s - seems like LED 116 might be the "Run" light?

I still don't see SetTimer as being capable of millisecond accuracy. It appears to only resolve to seconds. Has anyone accually used SetTimer & GetTimer to track MILLISECONDS?? Thanks!

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Mach3 MacroPump Get Current Time in Milliseconds
« Reply #9 on: February 01, 2016, 11:38:18 AM »
You have the OTHER version(;-)

(;-) TP