Hello Guest it is March 29, 2024, 04:49:40 AM

Author Topic: External button "Enable"  (Read 1761 times)

0 Members and 1 Guest are viewing this topic.

External button "Enable"
« on: May 24, 2021, 12:49:20 AM »
i add an external button to enable mach4 after pc turn on

[mc.ISIG_INPUT0] = function (state)--external button on
   if( state == 1) then              
                      
      local inst = mc.mcGetInstance()
       mc.mcCntlSetLastError(inst, "but enable ");   
       mc.mcCntlEnable(inst,1)
           local Zbrake = mc.OSIG_OUTPUT9 
       local hsig1 = mc.mcSignalGetHandle(0, Zbrake)  ------servo on
        mc.mcSignalSetState(hsig1, 1)
        mc.mcCntlSetLastError(0, "servo on");
       local zb= mc.OSIG_OUTPUT1
       local zb11 = mc.mcSignalGetHandle(0, zb)  ------z brake
        mc.mcSignalSetState(zb11, 1)   
   end
end ,

i use the attach  even handler (quit simple i think)
but strange behaviour
1. if i try first time by button  mach4 crash
2. if i enable from mach interface first time ,then disable ,then by button work good
     even many times ,disable enable....ets its ok ,but s mention first time must be from mach, why?
thanks
yaakov




Re: External button "Enable"
« Reply #1 on: May 24, 2021, 01:56:17 PM »
we had good days her in forum while steeve real help ,now its look like become as past that this forum have useless?
i think i post about 5-6 post with bugs here on last month not even one got real answer
can some one please try explain me why so simple script cause mach to crash?

Re: External button "Enable"
« Reply #2 on: May 24, 2021, 02:05:48 PM »
If you put some "rc =" before some of those API calls, then debugged the screen script I'm sure it would tell you what is going on :)
Re: External button "Enable"
« Reply #3 on: May 24, 2021, 02:09:53 PM »
no,because mach crash immediately when i press the external button
i try delete all the event  script
remind only:
[mc.ISIG_INPUT0] = function (state)--external buton on
   if( state == 1) then              
                      
      local inst = mc.mcGetInstance()
      
       mc.mcCntlEnable(inst,1)
         
   end
end ,
and also the first external button press ,mach crash
Re: External button "Enable"
« Reply #4 on: May 24, 2021, 09:39:47 PM »
Why no any help from mach team?
I also sent to mach support but same
There advice use pmm
But i need use scripts
You provide script i follow your instructions,mach crash why can't get support???
Re: External button "Enable"
« Reply #5 on: June 05, 2021, 02:34:26 PM »
is steve leave this forum?no real help here ,no real help on mach suport

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: External button "Enable"
« Reply #6 on: June 10, 2021, 05:44:10 PM »
No.  Just that my primary function is programming.  And I have been working hard with my head stuck into some new functionality that we are trying to implement.  I only get here on the forums when I have time.  :(

Something isn't right.  Things don't crash if they are correct.  Unfortunately, it is VERY easy to crash the system with bad LUA calls.  Because LUA is soooo close to C and there isn't much protection code in there.  That is one of the reasons LUA is so fast.  But it does come at a cost when developing.  The crash may be coming from some other LUA code in the PLC script even!  So the trick is locating where the problem is.  I tried your last script mocked up in my system and I didn't have a crash.  So again, the task is finding what is wrong.  :(  Sometimes it isn't so easy. 

Another thing...  Have you considered using the PMC for this?  That is where the PMC shines!!  For external buttons and control panel items, etc...  You don't even have to map a discrete I/O to a signal in the PMC. 

Assuming your enable switch is not momentary, the following PMC file might help you along.  Just modify it for your input/output device.  You will have to "Generate" afterwards and then edit your screen and enable the PMC object.  I use the PMC for as Much as I can!  It makes moving to a new screen set a LOT easier if your I/O tasks are all done in PMC objects. 

Steve
Re: External button "Enable"
« Reply #7 on: June 11, 2021, 12:51:37 AM »
first its real good news you still with us
about PMC ,because PMC not map the input ,can i use both ,PMC and Lua (with map)?
the pmc run immediately when Mach start up?(like plc)
thks a lot yaakov

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: External button "Enable"
« Reply #8 on: June 11, 2021, 03:15:16 AM »
The PMC doesn't require the I/O to Signal mapping.  But it can, in effect, map an I/O to a Signal.  You can make a ladder "rung" that will effectively "map" a discrete device input to a Mach input signal.  Or map a Mach output Signal to a discrete device output.  The PMC is VERY flexible. 

For inputs, yes, the PMC can use a device input and that very same input can be mapped to a Mach signal and used in the LUA PLC or SIGLIB scripts.  Not sure why that would be needed, but it would be possible.  You can also do the same with outputs, as long as the LUA scripts and PMC don't care which one set the output at any give time.  In other words, if you don't care about a "split brain" type of situation. 

Yes, the PMC is running instantly.

Steve
Re: External button "Enable"
« Reply #9 on: June 11, 2021, 07:18:28 AM »
i test now ,if i not map output its not work
i use pokeys
if not map the output see nothing on diagnostic