Page 1 of 1

Adding User LED to User Exts Page

Posted: Tue Mar 04, 2014 9:13 pm
by adam
Hello,
I am having trouble getting a LED that I have Added to the User Extense Page. What I am trying to accomplish is for the M10/M11 Call will change the state of the LED.
M10 LED ON M11 LED OFF so that I can Make a Brain to communicate with a PLC that will operate a pneumatic solenoid to open and close a collet chuck .
Steps I have Taken are.

Created a UserLed (2000) added to User Exts Page

Modified the M10.m1s

Dim FrontCloser As Integer
FrontCloser=(2000)

SetUserLED(Frontcloser,1)

Modified the M11.m1s

Dim FrontCloser As Integer
FrontCloser=(2000)

SetUserLED(Frontcloser,0)

Thanks for your valuable help.

Re: Adding User LED to User Exts Page

Posted: Wed Mar 05, 2014 10:20 am
by DaveCVI
Hi,
Two comments:
1) The code you posted works fine, however, you don't need to declare an integer and set it to control the LEDs.
Since the led # is constant it can be declared as a constant. I like to do this as it let's me give the number a useful name (as you did with the name of the integer).

For example:

Code: Select all

Option Explicit

' little M10 script
Const LedNumber = 2000

' turn LED on
SetUserLED(LedNumber,1)
You can even just use the number directly (but I don't like that coding style as a year from now you won't remember what you were using 2000 for... a name is much better over the long term.

Code: Select all

' turn LED on
SetUserLED(2000,1)
2) If you save the scripts as M2000 and M2001, I think that you'll find they work when you do M2000 or M2001 via MDI.
Mach treats low number M-codes specially. I've forgotten the boundary, but all user mcodes are supposed to be above a certain number (100 or 1000?).
When I save the same scripts as M10 and M11, they do not work from MDI - I suspect it is because of the 10, 11 number.
I don't know a trick to edit M10 and M11... A question to the mach Yahoo list may be your best bet to find out how to do this.

Dave