Form - LED object

This is where you talk about Plugins. How they are made and how they work, show examples.

Form - LED object

Postby Robertspark » Fri Jun 16, 2017 2:58 am

Instead of reinventing the wheel...

Suggestion, how would you represent an LED object on a plugin form.

understand the label and button examples within the plugin example, any chance of providing an LED example (object that will change between two states).

thought I'd ask because I'm sure other chip makers (cnc non-programmers) may benefit from this too

Thanks,
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Form - LED object

Postby cncdrive » Fri Jun 16, 2017 4:48 am

Hi Rob,

I think the simples way is to:

1.) Place a PictureBox on your Form and it's location and size to the size you want your LED. This PictureBox will represent your LED.
2.) Place a timer on your Form from the toolbox in Visual Studio.
3.) Set the timer Enabled property to true or set the Enabled property of the timer in your plugin code.
4.) Double click on your Timer in the Form editor, so the Timer_click event will be automatically generated and assigned by Visual Studio.
5.) Add some code to the Timer_click event, something like:

Code: Select all
private void timer1_Tick(object sender, EventArgs e)
{
   bool MyLEDstate = UC.GetLED(54);
   if (MyLEDstate)
   {
      pictureBox1.BackColor = Color.Red;
   }
   else
   {
      pictureBox1.BackColor = Color.Gray;
   }
}


So, you read the LED's state, in this example LED 54. which is the Cycle Start LED and you set the background color of your picturebox based on if the LED is on or off in the UCCNC.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Form - LED object

Postby Robertspark » Fri Jun 16, 2017 5:34 am

thanks very much, just what I was looking for, easy to implment + idiot proof + does the job.

Suggestion would be if you get the time to edit the plugin example and add such a button for anyone wondering in the future, they can just copy the code from within the example.

Thanks again,
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Form - LED object

Postby shad » Fri Jun 16, 2017 5:44 am

+1
Also I am check current state of the picture box before set new color like this:
Code: Select all
if(pictureBox1.BackColor != Color.Red) pictureBox1.BackColor = Color.Red;

And of course you can use any modern LED 16x16 size picture for this. Just change picture depend from LED state.
http://www.clker.com/clipart-red-led-2.html
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 332
Joined: Thu Sep 15, 2016 5:23 pm

Re: Form - LED object

Postby Robertspark » Fri Jun 16, 2017 5:46 am

Thanks Andrew, much appreciated for your input too
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: Form - LED object

Postby dezsoe » Fri Jun 16, 2017 8:57 am

You can also use an LED with text: place a label with your text on the form, turn off autosize, set desired size, set border to single. Then you can change the backcolor property to turn the LED on or off. You can use Drawing.SystemColors.Control for off state and Drawing.Color.anything for on state. Changing the backcolor is also good for buttons to have LED in them.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Form - LED object

Postby ger21 » Fri Jun 16, 2017 11:26 am

You can also use images, and swap them out.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am


Return to Plugins

Who is online

Users browsing this forum: No registered users and 1 guest

cron