M10/M11 active

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

M10/M11 active

Postby Robertspark » Tue Jun 20, 2017 10:44 pm

How would I go about software wize monitoring for M10/M11 active status?

would the best way to:
Code: Select all
string LazerPin = AS3.Getfield (514);
string LazerPort = AS3.Getfield (515);


join the string

Code: Select all
stringLazerPortPin = LazerPin + LazerPort;


then use a switch statement to find what the status of the pin and port is?

such as:

Code: Select all
Swith (LazerPortPin)
{
case 11:
bool LazerLED = AS3.GetLED(1);
break;
case 12:
bool LazerLED = AS3.GetLED(2);
break;
case 13:
bool LazerLED = AS3.GetLED(3);
break;
.....
case 517:
bool LazerLED = AS3.GetLED(136);
break
}


Is there a faster way?
(defined LED?)
like LED 220?

You can use LED 51 for M4 and LED 50 for M3, but not clear about M10/M11.

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

Re: M10/M11 active

Postby dezsoe » Wed Jun 21, 2017 6:12 am

You can make your code faster by two tricks. First: find out the output led number only once. Second: store it in a static variable for later use. (About static variables: http://www.forum.cncdrive.com/viewtopic.php?f=15&t=589)

Code: Select all
int LaserPort;

if (LaserLED == -1)
{
  LaserLED = 0;                                                                 // set to 0 to show error
  LaserPort = Convert.ToInt32(AS3.Getfielddouble(915));
  switch (LaserPort)                                                            // add pin number to first LED-1
  {
    case 1:
      LaserLED = Convert.ToInt32(AS3.Getfielddouble(914));
      break;
    case 2:
      LaserLED = Convert.ToInt32(68 + AS3.Getfielddouble(914));
      break;
    case 3:
      LaserLED = Convert.ToInt32(85 + AS3.Getfielddouble(914));
      break;
    case 4:
      LaserLED = Convert.ToInt32(102 + AS3.Getfielddouble(914));
      break;
    case 5:
      LaserLED = Convert.ToInt32(119 + AS3.Getfielddouble(914));
      break;
  }
}

if (LaserLED == 0)
{
  // Handle error: no pin defined, LaserLED remained 0
  MessageBox.Show("No laser pin defined!");
  return;
}

// ... your code ...

AS3.Additemtolistbeginning("Laser LED: " + LaserLED.ToString(), 2);
AS3.Additemtolistbeginning("Laser state: " + exec.GetLED(LaserLED).ToString(), 2);

// ... your code ...

#Events

static int LaserLED = -1;

Be careful when configuring LED port and pin: this macro will calculate LaserLED only once! Static remains in memory until macro code changes or UCCNC restarts. In this code you also find some error handling. :)

Edit: Now I see it's in the plugins thread. The technique is the same in plugins, just modify the AS3 calls as used in plugins. Instead #Events and static you may use a global variable. Sorry, it's morning here... :)
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: M10/M11 active

Postby shad » Wed Jun 21, 2017 11:52 am

It's will be great to have Getpin(int portnumber, int pinnumber) function in the API.
Balazs, what you think?
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm

Re: M10/M11 active

Postby cncdrive » Wed Jun 21, 2017 12:01 pm

Hi Andrew,

The input port pins are all represented with virtual LEDs and so they can be read via the LED codes is why we did not think that there is a need to do the same with a specific function like Getpin.
The GetLED function is not good for this? Why do you want a specific function for this?
cncdrive
Site Admin
 
Posts: 4695
Joined: Tue Aug 12, 2014 11:17 pm

Re: M10/M11 active

Postby shad » Wed Jun 21, 2017 1:09 pm

Just for some reason always thought that there is a delay between changing the state of a pin and displaying it in the screen.
Rob ask, how to make it faster as possible.
If this enough fast - it's great and can be used.
Just Question :)
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm

Re: M10/M11 active

Postby cncdrive » Wed Jun 21, 2017 1:36 pm

OK, I see. No, there is no delay because it is a LED.
How it works is that the LEDs array variable which contains the on/off states of each LED is updated in a 20msec loop.
So, the I/Os are read in that loop and the array values are updated.
When you read a LED with the GetLED function then you get the value from this LED array.

How the LEDs are displayed on the screen is a totally different thing, that runs in a totally different loop,
and that loop checks the states of the LEDs array and renders the LEDs to on or off state.

So, the 2 things work separated and so it does not matter how fast the LEDs visually update, the logical state of the LEDs what you read is updated frequently and independently of the screen LEDs.
cncdrive
Site Admin
 
Posts: 4695
Joined: Tue Aug 12, 2014 11:17 pm

Re: M10/M11 active

Postby shad » Wed Jun 21, 2017 1:40 pm

Now everything is clear to me. No need another way to check it. 20 msec is very fast.
Thank you Balazs! This is very useful information.
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm

Re: M10/M11 active

Postby Robertspark » Wed Jun 21, 2017 2:28 pm

Thanks All, I learnt a lot there, very much appreciated for everyone taking the time to explain it and also provide some code.

(I was having a chat with andrew about M10/M11 and its use via plugin (i.e. monitoring the pin change state), hence where my question came from).

Unless I missed it, it would still be useful to have a dedicated LED to M10/M11 so that it was easier to find / read the LED status update.

M0, LED #229
M1, LED #230

M3, LED #50
M4, LED #51

M6, LED #28
M7, LED #52
M8, LED #53

M10/M11 -??

M60, LED #231

unless that is what LED #220 indicates...
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M10/M11 active

Postby beefy » Wed Jun 21, 2017 7:11 pm

Robertspark wrote:it would still be useful to have a dedicated LED to M10/M11 so that it was easier to find / read the LED status update.

M0, LED #229
M1, LED #230

M3, LED #50
M4, LED #51

M6, LED #28
M7, LED #52
M8, LED #53

M10/M11 -??

M60, LED #231

unless that is what LED #220 indicates...


As a plasma user I agree with Rob. I have wanted this when designing my plasma screenset and couldn't find a dedicated LED.

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am


Return to Plugins

Who is online

Users browsing this forum: No registered users and 5 guests

cron