wx.lua wait

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
gorf25
Earned a small fee
Earned a small fee
Posts: 12
Joined: Mon Aug 21, 2017 3:10 pm

wx.lua wait

Postby gorf25 » Tue Nov 14, 2017 1:31 am

Is there a function or a way to make a wxlua script wait not sleep I have a function call that is
running and I want it to keep running. but before it completes I am already into the next function waiting for the next input
or button click, I don't want to continue till the call is done..

Thanks gary

User avatar
doublemax
Moderator
Moderator
Posts: 11481
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wx.lua wait

Postby doublemax » Tue Nov 14, 2017 3:58 pm

What you're describing should not happen in a single-threaded application.

Can you explain it in more detail?
Use the source, Luke!

gorf25
Earned a small fee
Earned a small fee
Posts: 12
Joined: Mon Aug 21, 2017 3:10 pm

Re: wx.lua wait

Postby gorf25 » Tue Nov 14, 2017 5:41 pm

The reason i need to wait is i am sending out code to run a stepper motor the axis and the distance to travel
but i want to wait till the motor reaches it final distance what ever it may be then move on or return from that function
to get my next input..

make more sense ?

Thanks gary

User avatar
doublemax
Moderator
Moderator
Posts: 11481
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wx.lua wait

Postby doublemax » Tue Nov 14, 2017 6:50 pm

So you're sending a command to a motor and the motor starts moving towards its target position, but your program continues immediately?

I don't know much about wxLua, so i'll talk about the C++ version and assume that the same methods apply.

You can't wait in a tight loop, this would freeze the GUI.

How can you check if the motor has stopped moving? Do you receive a signal or can you poll its status?

Assuming you can poll its status, i'd do this:

When you start the motor, set a "busy" flag somewhere to "true". While this flag is true, don't send any other commands.
Start a wxTimer and in its handler check the status of the motor. If it has reached the target position, reset the flag.

If one of the problem is that the user can click on controls while the motor is still moving, you can disable these controls (or the whole) window until then.
Use the source, Luke!

gorf25
Earned a small fee
Earned a small fee
Posts: 12
Joined: Mon Aug 21, 2017 3:10 pm

Re: wx.lua wait

Postby gorf25 » Tue Nov 14, 2017 9:15 pm

you are right the GUI freezes and then i get program stopped so it crashes the problem seems to be any
loop or such does the same thing crashes, the only way i have been able to find out if motor has moved the
proper distance is then to call a command that returns the value of where the motor is if you started a 1.0 and moved
2 inches it would return the value of 3.0 but that call if in i use in a loop and wait till it reaches 3.0 also crashes
the program i figure its freezing the GUI also ...

As long as you just let the event function to continue it works fine except that while motor is still running the next function
is already asking form imput..

User avatar
doublemax
Moderator
Moderator
Posts: 11481
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wx.lua wait

Postby doublemax » Tue Nov 14, 2017 11:39 pm

That the GUI freezes while your code is running a loop, is normal. But crashing isn't. That probably has another cause.

But my suggestion still stands: Use a busy-flag to avoid sending commands when the motor is still moving and use a timer event to check the position of the motor.
Use the source, Luke!

gorf25
Earned a small fee
Earned a small fee
Posts: 12
Joined: Mon Aug 21, 2017 3:10 pm

Re: wx.lua wait

Postby gorf25 » Wed Nov 15, 2017 1:56 am

Thanks i think i found away for it to work a button function event using the coroutine and put a while do loop in the
button press and then in the loop i call the function that gets the motor position and exit when it has been reached

have ran it and so far the code doesn't seem to be messing up the GUI or crashing the program
so that may be the way to go only thing i may have to rewrite most of the code,

Thanks gary


Return to “General Development”

Who is online

Users browsing this forum: No registered users and 2 guests