585,883 active members*
4,576 visitors online*
Register for free
Login
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2003
    Posts
    218

    VB Scripting 101

    Hopefully an easy one for more of the seasoned engineers here.

    If I create a new button and led in a screen design program such as screen4, how can I associate the button with the LED so when the button is pressed the led lights accordingly?

    Also how can I choose to make a button latch so I can toggle between an on an off state ?

    I would be greatful for generic code examples rather than how a specific screen design program could be made to do this.


    Thanks in advance,

    Dom
    Dom
    http://www.ukrobotics.com/projects

  2. #2
    Join Date
    Mar 2003
    Posts
    35538
    It depends what the LED is doing. Is it a standard Mach3 LED, or a custom LED for a special purpose?

    For most standard mach3 LED's, there are button "calls" to turn them on. For a "User" LED, you just use code in the button to turn it on or off.

    Also, you can't "latch" a button, but you can have it turn something on so that it stays on.

    Basically, when you create a button, you assign a function to it. You have a few options.

    1. Built in Mach function. There's a drop down list in Screen4 to choose them, and there are quite a few.
    2. Call an OEM code. You just put the code in that does what you want it to do. There are codes for all the built in functions, so both 1 and 2 do the same thing, but 1 is just quicker if the function call is listed.
    3. Run G-code. Just enter the g-code you want the button to do. I think it's limited to a single line of code, but you can also call M codes, so you can run a macro by calling it's code, such as M777.
    4. Run VB script. This is probably the route you want to take, from what I gather from your post.


    All the OEM codes can be found here. Look under #9.
    http://www.machsupport.com/MachCusto...itle=Main_Page

    One thing to understand in Mach3, is that turning on an LED actually activates that function. For example, the OEM LED code for Flood coolant is 13. So, if you want to turn on flood coolant with a button, you can use 2 of the methods I gave above.
    1. Choose Flood from the built in function list.
    4. Use the script SetOEMLED(13,1). SetOEMLED(13,0) would turn it off.

    Method 2 requires an OEM button code, so you wouldn't use 13 there. The button code to toggle flood is 113. NOte that some button codes toggle on and off, while others are strictly on or off.

    If you give me more specifics on what you want to do, I can give you a better answer.
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  3. #3
    Join Date
    Dec 2003
    Posts
    218
    Thanks Gerry,

    I really appreciate the time you take to answer my questions. I have read a lot of instruction manuals and watched a lot of tutorial videos but its having that extra knowlege to fill in the gaps which these things don't tell you that makes all the difference.

    I will use my power drawbar as an example.

    I want to create a new button which when pressed sends a signal to the soild state relay which drives the solonoid for the drawbar. So lets assume for arguments sake that the relay is congfigured as output #1. Also while a signal is going out to that relay i'd like a LED to indicate this on screen.

    I was thinking for a latching version of this switch I could use code like:

    (on btn click)

    If output1 = 0
    x = 0
    ElseIf output1 = 1
    x = 1

    If x>0
    ouput1 = 0
    LED1 = 0

    else

    output1=1
    led1 = 1



    And for a non latching version...

    While btn1 = 1
    output 1 = 1
    else
    output 1 = 0

    or something like that


    Please excuse my very poor pseudocode above, - it's been a while since i've done any programming!

    If this would work would you mind rewriting what i've written in the correct syntax?


    Cheers.
    Dom
    http://www.ukrobotics.com/projects

  4. #4
    Join Date
    Jul 2007
    Posts
    887
    Hi,
    The only on-screen-buttons that "acts" as long as they are being pressed are the jog-buttons. All other buttons, AFAIK, are "edge-triggered", they run the attached code once, every time they are being clicked. There's no way to "see" if it is being "held down".

    For your latching LED example, if the LED is OEMLED1000 then you can do something like this:
    Code:
    If IsOutPutActive(Output1) Then   'Check the state of the output...
      DeActivateSignal(Output1)       '...if it's "on", turn it off...
      SetUserLED(1000,0)              '...and turn off LED
    Else
      ActivateSignal(Output1)          'Otherwise turn the output "on"...
      SetUserLED(1000,1)               '...and turn on the LED
    End If
    For the non latching version perhaps a time delay might be worth a shot, something like:
    Code:
    ActivateSignal(Output2)       'Set output
    SetUserLED(1000,1)            'Turn on LED
    Sleep(1000)                        'Wait one second
    DeActivateSignal(Output2)     'Reset output
    SetUserLED(1000,0)              'Turn off LED
    HTH

  5. #5
    Join Date
    Dec 2003
    Posts
    218
    I'm not sure it would work useing sleep in that way because it is only going to be called once regardless of how long you hold the button down.
    Dom
    http://www.ukrobotics.com/projects

  6. #6
    Join Date
    Feb 2005
    Posts
    487
    Gerry:

    SetOEMLED(13,1) is not something you can do in Mach3, there is no SetOEMLED call. BUT!!!! There is a "GetOEMLED(xxx)" to look at is status.
    The OEM Leds are "Read Only", you cant set them (unfortunatly). They only report the status of the function they represent. DoOEMButton(113) will for instance toggle the state of Flood Coolant, or Code("M8") will turn it on, Code("M9") off.

    Dom:

    If you want in a Button you could also do this You would need to put your button, and a user LED on the screen that you want to represent the status of OUTPUT1, lets call it 1500. I am assuming OUTPUT1 when active captures/grabs the draw bar. Tick the Use VB radio button and put the below code in the box. in Screen3, in Screen4 you have to goto operator->edit button script, and your button will blink. click it, and a VB window will appear.
    put the code below in it, hit ONLY the Save button it will title "Hidden Script".
    hit the ok to close the window. Then YOU MUST goto View->Save Current Layout (click the save current layout). Then Go Back and look at Operator->Edit button script to MAKE SURE it DID save it, sometimes it does NOT!!! if you see your script there your good, if not redo the steps again, and recheck.

    if GetUserLED(1500) then 'if it is on (Output1 is active)
    if GetOEMLED(11) then ' if the spindle is running dont release (safety)
    Message("Spindle Must Be OFF to release Tool!!")
    ' Code("M5") 'Optional spindle stop here
    else
    DeActivateSignal(OUTPUT1) 'Draw bar Release tool output1 off
    SetUserLED(1500,0) 'Turn off your indicator LED
    end if
    else
    ActivateSignal(OUTPUT1) 'Draw bar capture tool output1 on
    SetUserLED(1500,1) 'Led is on to indicate capture
    end if

    'NOTE: if you need the reverse of the above logic just flip everything around.

    'Enjoy scott
    Commercial Mach3: Screens, Wizards, Plugins, Brains,PLCs, Macros, ATC's, machine design/build, retrofit, EMC2, Prototyping. http://sites.google.com/site/volunteerfablab/

  7. #7
    Join Date
    Mar 2003
    Posts
    35538
    Quote Originally Posted by PoppaBear10 View Post
    Gerry:

    SetOEMLED(13,1) is not something you can do in Mach3, there is no SetOEMLED call.
    Someone needs to fix the Wiki. It says there is.
    http://www.machsupport.com/MachCusto...title=OEM_LEDs

    That makes sense, though. So, you can only turn on User LED's?
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  8. #8
    Join Date
    Mar 2003
    Posts
    35538
    Also, instead of a User LED for Output one, can't you just use OEMLED 852?
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  9. #9
    Join Date
    Feb 2005
    Posts
    487
    Gerry,

    Yes the Wiki is Wrong on that count, it was written a very long time ago via John Pentice. But, the good news is, if you want you can "Join" and "Correct" the error!!

    Open Mach3, then goto Operator->VB scripter, when the window opens,
    put in the code: SetOEMLED(13,1) and then do a step through or just hit the "Run" button, it will give you an error saying: Expected =, or something like that........

    You could also use the OEM LED code for Output1 as you wanted in place of ULED 1500.........

    The really cool thing about mach is the POWER it give to users to customize the Crap out of it!!! There are many ways to do many things. You could even use "Brians" if you wanted to do it as well.

    I suspect that the reason that the Wiki hasnt been corrected (btw there are Many other issues there as well), is that editing the Wiki is a pain in the butt, and time consuming.

    NOTE: In the Forum section of the "www.machsupport.com", under the subject area called: "Member Docs". I published two documents for the "Undocumented" VB. One is VB Parameters, the other is an extension to the "Mach Specific Subroutines". These where dirived directly from the C++ header file that Art himself sent to me a few months ago, to FINALLY try and get ALL the VB documentation up to date...........

    scott
    Commercial Mach3: Screens, Wizards, Plugins, Brains,PLCs, Macros, ATC's, machine design/build, retrofit, EMC2, Prototyping. http://sites.google.com/site/volunteerfablab/

  10. #10
    Join Date
    Jul 2007
    Posts
    887
    I'm not sure it would work useing sleep in that way because it is only going to be called once regardless of how long you hold the button down.
    Exactly, that's what I was trying to say in my first post. The only buttons that has a "while-pressed" kind of function are the on screen Jog-buttons and they are a special case. The Sleep was an atempt to find a possible workaround for you...

    Gerry,
    Yep, the Wiki seems to be wrong on this. If you don't want to do it I can double check with Brian and then edit the Wiki.
    There is a SetUserLED call that you can use to set or reset "your" LEDs.

  11. #11
    Join Date
    Feb 2005
    Posts
    487
    H.O.

    If memory serves, anyone can join and edit the wiki. I have added stuff to it, and others have as well. I think once you ask to join to edit. I think it may be John that approves it or not. I cant remember if he has to approve you or not, since it has been many years since I last logged on to add stuff.

    scott
    Commercial Mach3: Screens, Wizards, Plugins, Brains,PLCs, Macros, ATC's, machine design/build, retrofit, EMC2, Prototyping. http://sites.google.com/site/volunteerfablab/

  12. #12
    Join Date
    Jul 2007
    Posts
    887
    Hi Scott,
    I think I had to ask Brian to add me to the "aproved list" before I could edit stuff there. Anyway, I now have login so I can edit the SetOEMLED/SetUserLED stuff but I wanted to doublecheck with Brian first so that whatever I put in there is correct.

  13. #13
    Join Date
    Dec 2003
    Posts
    218
    Thanks for all the help guys.

    Based on the examples you provided i've ended up with this for operating my drawbar:

    If GetOEMLED(11) Then
    Message("Spindle Must Be OFF to Change Tool!!")
    ElseIf GetOEMLED(852) Then
    DeActivateSignal(OUTPUT1)
    Message("Tool Locked")
    Else
    ActivateSignal(OUTPUT1)
    Message("Tool Released")
    End If
    Dom
    http://www.ukrobotics.com/projects

Similar Threads

  1. Scripting reference...
    By kiwichris in forum NCPlot G-Code editor / backplotter
    Replies: 5
    Last Post: 11-15-2007, 10:36 PM
  2. Scripting Question
    By eng8248 in forum BobCad-Cam
    Replies: 6
    Last Post: 03-24-2007, 08:53 PM
  3. Replies: 11
    Last Post: 03-11-2007, 10:35 AM
  4. Bobcad scripting
    By 69owb in forum BobCad-Cam
    Replies: 1
    Last Post: 05-14-2006, 09:20 PM
  5. Scripting
    By Klox in forum BobCad-Cam
    Replies: 29
    Last Post: 10-03-2003, 04:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •