Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: KatzYaakov on May 24, 2021, 12:49:20 AM

Title: External button "Enable"
Post by: KatzYaakov 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




Title: Re: External button "Enable"
Post by: KatzYaakov 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?

Title: Re: External button "Enable"
Post by: GOOMBA 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 :)
Title: Re: External button "Enable"
Post by: KatzYaakov 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
Title: Re: External button "Enable"
Post by: KatzYaakov 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???
Title: Re: External button "Enable"
Post by: KatzYaakov on June 05, 2021, 02:34:26 PM
is steve leave this forum?no real help here ,no real help on mach suport
Title: Re: External button "Enable"
Post by: smurph 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
Title: Re: External button "Enable"
Post by: KatzYaakov 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
Title: Re: External button "Enable"
Post by: smurph 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
Title: Re: External button "Enable"
Post by: KatzYaakov 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
Title: Re: External button "Enable"
Post by: smurph on June 11, 2021, 01:34:21 PM
You will not see anything in the Mach diagnostic screen if using the PMC.  There is a test mode in the PMC for diagnostics.  The type of device you use for inputs and outputs doesn't matter.  Pokeys, PLC, MODBUS, etc...  all will work with the PMC.  The test here is if it functionally works and does what you want.  Then having lights lit up in the diagnostic screen of Mach is useless.  However, you could add a rung on your PMC ladder program to raise/lower a Mach signal so that you could see it on the diagnostic screen.  :) 

Steve
Title: Re: External button "Enable"
Post by: joeaverage on June 11, 2021, 10:06:16 PM
Hi,
why do you need to 'see it' on the diagnostics screen?

That would be like a beast having two arseholes, one at each end, Doctor DoLittle called it a PushMePullYou.

Craig
Title: Re: External button "Enable"
Post by: KatzYaakov on June 12, 2021, 07:56:04 PM
i have in my machines about 50 outputs ,so i must have some way to debug when have problem
Title: Re: External button "Enable"
Post by: joeaverage on June 13, 2021, 01:33:56 AM
Hi,
well yes but you've already got a diagnostic indication, the Enable button in Machs screen.
If you look at the event properties of the button it changes color with the button-up or button-down,
which in turn effects a change in OSIG_MACHINE_ENABLED signal. What more diagnostic do you need?

Craig
Title: Re: External button "Enable"
Post by: KatzYaakov on June 14, 2021, 07:33:48 AM
for example last test i had problem with pokeys relay
that didnt work(its almost never happened ,but... can) so i have head ace until i understand its hardware problem