Hello Guest it is December 15, 2019, 07:24:41 PM

Author Topic: last line not executing  (Read 411 times)

0 Members and 1 Guest are viewing this topic.

Re: last line not executing
« Reply #10 on: March 04, 2019, 09:45:06 PM »
Hi,
smuprh's comment and suggestion is spot on. We have to set the homing function in progress and then wait until it
completes. That could be done as smurph suggests by testing the machine state, knowing that the function has completed
and returned the machine to idle state before progressing.

I had thought of another way which achieves the same result. The API call I am thinking of is:
Code: [Select]
LUA Syntax:
homing, rc= mc.mcAxisIsHoming(
number mInst,
number axisId)

Description:
Check to see if an axis is in a home operation.

We can use this API to test whether the homing function is complete. But we need a delay in the loop.

Quote
What about some kind of counting loop.

The loop idea ties up the CPU. Additionally I would expect a counting loop to count up to 1000 in a millisecond
or so. I think a better idea is to use a wxTimer function. It is a timer  coded in wxLua but creates a Windows
function/event and so has no impact on Mach, its external to Mach. Have a look at Daz's video on wxTimers:

https://www.machsupport.com/forum/index.php?topic=32573.0

It may appear that it adds significant complexity but I think it would work well and not burden Mach with any
extra code.

This code.....where is it going? I note for example that you have not declared the 'inst' variable? Is it available
within the same scope as this code? If not then have to declare 'inst' otherwise your code will fail.

For the purposes of writing and debugging code I tend to make a function of it so I can use the debug facilities of
the Zero Brane editor.

Craig
My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  250 250
    • View Profile
Re: last line not executing
« Reply #11 on: March 05, 2019, 04:08:01 PM »
smuprh and Craig,

thanks for the information and input.
the application that i am going to be using the software for is not a cnc machine like a mill or router
i will be needing to home the machine multiple times while in operation
i will start working on the things you have both suggested

thanks again,
bill
Re: last line not executing
« Reply #12 on: March 05, 2019, 11:48:30 PM »
Hi,
the reason I ask is because if this code is going to be attached to a button then it would be complied as part of
the GUI chunk. Therefore any wx.Timer code could go in the Screen Load script, which is of course always available
to all other code in the GUI.

If however you wish to run this code as a macro it will be complied and included in the Gcode interpreter chunk. Thus
any wx.Timer code in the screen load script (ie GUI chunk)  would not be available to it.

So I need to know how you intend to use this code in order that I can structure the code to the conditions of ude.

Craig

My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  250 250
    • View Profile
Re: last line not executing
« Reply #13 on: March 06, 2019, 07:50:42 AM »
Craig,
right now it is in a button but it will need to be in a macro
Bill

Offline Bill_O

*
  •  250 250
    • View Profile
Re: last line not executing
« Reply #14 on: March 06, 2019, 09:35:39 AM »
I was looking at mc.AxisIsHoming
This appears to me this might be the best one to try using.
I just need a little help on the code.
Looking at the Mach4 Core API reference this is what i see.
int mInst = 0
BOOL homing = true
mc.mcAxisIsHoming(mInst, X_Axis, homing)
I think this is how it all needs to be but a few questions.
What is the "int" and why is it needed?
Why does the variable "mInst" need to be set to "0"?
What is the "BOOL" and why is it needed?
And the last and biggest how do I put this in a loop to keep looking until it is false.
I tried but I keep getting errors.

Bill
Re: last line not executing
« Reply #15 on: March 06, 2019, 11:31:12 AM »
Hi,

Quote
right now it is in a button but it will need to be in a macro

You need to make up your mind either way.......they are not the same. If its in a button the code ends up in one chunk
but if it's in a macro it ends up in another.

Quote
int mInst = 0

That comes from the usage example and its in C++, disregard it. That's not how its used in Lua.

Quote
What is the "BOOL" and why is it needed?

BOOL means Boolean, so it is a variable type, either True or False, again its applicable to C++, C and C++ are very
strongly typed languages whereas Lua is not. It does not mean you can disregard it but its less important.

Quote
And the last and biggest how do I put this in a loop to keep looking until it is false.
I tried but I keep getting errors.

As I have posted and ordinary counting type loop wont work. You need to use a timer to generate a delay. Further
the timer or delay can place no burden on Mach because you are waiting for Mach to complete an API function, you
can't tell it to 'count to 1000' and expect it to complete its API call at the same time.
Have you looked at Daz's video? Have you coded a wxTimer? Where did you put the code?
Depending on how you wish this code to be used will alter where the code is placed and how its accessed, thus
I need to know if its a button OR a macro before I can help.

I notice in another of your threads you have some code that you are trying to use in two places, one as a button
and one as a macro. I think you should consider them as distinctly different.

Craig
My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  250 250
    • View Profile
Re: last line not executing
« Reply #16 on: March 06, 2019, 12:17:31 PM »
Craig,

I had no idea that the code was often different between a button and a macro.
I was so used to Mach3 being the same it never even crossed my mind.
Almost everything I will need to be doing at this time will be macros (M Code) so that is where I will need to focus.
I will look over your earlier information again and look at the videos.
Thanks again,
Bill