Get strange issue with toggle button.

If you have a question about the software please ask it here.

Get strange issue with toggle button.

Postby kig23 » Tue May 15, 2018 11:13 am

I need to make some controls befor i start the spindel. So i change the M3toggle button for 114 to 20006. This way the button poins to my macro. The macro works fine, but i get a strange issue with the button (the button led changes, but the button remains in down state). Here is a simple code:

Code: Select all
if(AS3.Getbuttonstate(20006))
{
   AS3.Switchbutton(false, 20006);
   MessageBox.Show("False");
}
else
{
   AS3.Switchbutton(true, 20006);
   MessageBox.Show ("True");
   
}


Am i missing something?
kig23
 
Posts: 161
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

Re: Get strange issue with toggle button.

Postby ger21 » Tue May 15, 2018 12:21 pm

Try this:
Code: Select all
bool buttonstate = AS3.Getbuttonstate(20006);

if (buttonstate)
{
   AS3.Switchbutton(false, 20006);
   MessageBox.Show("False");
}
else
{
   AS3.Switchbutton(true, 20006);
   MessageBox.Show ("True");
   
}
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: Get strange issue with toggle button.

Postby dezsoe » Tue May 15, 2018 1:20 pm

I tried your original macro and the button works fine. Did you change the bitmap of the button?
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Get strange issue with toggle button.

Postby kig23 » Tue May 15, 2018 1:22 pm

Thanks Gerry. I've tried this befor, but the same issue. Thanks Dezsoe. No, i didn't change the bitmap of the original button, only redirect the button from 114 to 20006. Dezsoe, the button works and the led of the button too. The issue i'm geting is that the button remains in down sate. When the macro finishes if you click on g-code viewer the button goes to up state.
kig23
 
Posts: 161
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

Re: Get strange issue with toggle button.

Postby dezsoe » Tue May 15, 2018 1:42 pm

Hm. I tried again and no issues. I understood what you wrote for the first time, but could not make my PC to do the same. Which UCCNC version did you try?
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Get strange issue with toggle button.

Postby kig23 » Tue May 15, 2018 2:03 pm

Thanks Dezsoe. I've tried on vrsion 1.2047. I'm gonna try on other computer. I'll let you know.
kig23
 
Posts: 161
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

Re: Get strange issue with toggle button.

Postby cncdrive » Tue May 15, 2018 2:10 pm

I think that the problem is that the Messagebox is shown before the software could send the buttons up and it can't send the buttons up when the messagebox is active, because it blocks the Windows message pump.
Try to place a small value Thread.Sleep between the AS3.Switchbutton and MessageBox.Show codes or check if the button was released by the user using the Getbutton function, that shows you if the button is being pressed or not. And wait for the button to be released by the user and show the messagebox only then.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Get strange issue with toggle button.

Postby kig23 » Tue May 15, 2018 2:27 pm

Thanks Balazs. Yes, you're right. With Thread.Sleep works fine. I'll try with Getbutton () too.

Thanks again
kig23
 
Posts: 161
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy


Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 34 guests