Hello Guest it is November 13, 2019, 05:47:19 PM

Author Topic: output on/off from same button  (Read 1210 times)

0 Members and 1 Guest are viewing this topic.

output on/off from same button
« on: April 07, 2018, 02:55:21 PM »
Hello everyone. I ask for help because I've lost the last two days trying to make a button work to turn the OUTPUT on or off, now I've built two simple M functions, which work individually but I can not combine them. can someone give me help or tell me why these two tests do not work that I attach below? I'm not a programming expert but I would like to be able to have this function on my machine. thank you all and sorry for my bad english.

first test

function M101()

    local inst = mc.mcGetInstance()


hReg, rc = mc.mcIoGetHandle(inst, OSIG_OUTPUT0);
BoolPointValue = mc.mcIoGetState(hReg);


    if (OSIG_OUTPUT0 == 0) then  ---- SE è SPENTO
        mc.mcCntlMdiExecute(inst, "M15") ---ACCENDI POMPA
    else
    mc.mcCntlMdiExecute(inst, "M16")   ----SPEGNI POMPA
     
           end
       
end

if (mc.mcInEditor() == 1) then
    M101()

end




second test



function M101()

    local inst = mc.mcGetInstance()



    mc.mcSignalGetHandle (inst, OSIG_OUTPUT0) --- LEGGI STATO OUTPUT 0
 mc.mcSignalGetState (inst, OSIG_OUTPUT0) --- LEGGI STATO OUTPUT 0
    if (OSIG_OUTPUT0 == 0) then  ---- SE è SPENTO
        mc.mcCntlMdiExecute(inst, "M15") ---ACCENDI POMPA
    else
    mc.mcCntlMdiExecute(inst, "M16")   ----SPEGNI POMPA
     
           end
       
end

if (mc.mcInEditor() == 1) then
    M101()

end
Re: output on/off from same button
« Reply #1 on: April 07, 2018, 05:16:10 PM »
Hi,
you have a number of syntax errors:

Quote
hReg, rc = mc.mcIoGetHandle(inst, OSIG_OUTPUT0);

Should be:
hReg,rc=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT0)

because OSIG_OUTPUT0 is a signal not an IO and mc.OSIG_OUTPUT0 correctly identifies the signal within Machs core.

Quote
BoolPointValue = mc.mcIoGetState(hReg);

Should be:
BoolPointValue=mc.mcSignalGetState(hReg)

Quote
if (OSIG_OUTPUT0 == 0) then  ---- SE è SPENTO

Should be:
if(BoolPointValue==0) then

Because OSIG_OUTPUT0 is only a human readable representation of a signal, its true identity during this instance of Mach is hReg and you have enquired
and got its state and copied it to a variable BoolPointValue.

One other point is that Machs Lua interpreter always reduces uppercase function names to lowercase and strips out leading zeros and spaces.
Thus your M101 is seen by Mach as m101.
M0101 would be seen as m101
M 101 would be seen as m101

In most cases Mach will correctly indentify and use the code you intended but it can go wrong sometimes. Do yourself a favour use lowercase without leading zeros or spaces,
you'll have fewer mistakes.

Look in Mach4Hobby/Docs for Mach4CoreAPI.chm and ScriptingManual.pdf, they will help a lot.

Craig
My wife left with my best friend...
     and I miss him!
Re: output on/off from same button
« Reply #2 on: April 11, 2018, 01:17:44 PM »
thank you very much for the reply.
Now i'm Able to set mach4 Output, but fisic button don't work. this output are mapped good to csmio IO modules.
attached two screen of the problem.
have you other advice?
thank you
« Last Edit: April 11, 2018, 01:21:05 PM by danilo93 »
Re: output on/off from same button
« Reply #3 on: April 11, 2018, 01:41:05 PM »
Hi,
that looks to be a problem with the controller, I'm not familiar with CSMIO boards.

On the screen pic of the CSMIO plugin it has modules...to what do they refer? Is it possible the pic is displaying one module whereas the signals you wish to view are in another?

Craig
My wife left with my best friend...
     and I miss him!
Re: output on/off from same button
« Reply #4 on: April 11, 2018, 03:03:20 PM »
Modules are additional 16 input and 8 output boards. We can use up to 16 boards and then have a total of 280 inputs and 144 outputs.

Also I thought of a similar problem but if I program in mach / output:
SpindleOn ---> CS MIO IO (0) ---> Output 4,  M3 activates the output well.
So M3 on that same output works and the other functions M no.

So I was thinking of a MACH problem, in your opinion is my M17 script good?

I thank you very much for your help.

Danilo
Re: output on/off from same button
« Reply #5 on: April 11, 2018, 04:50:52 PM »
Maybe silly questions, but:

1. Do the relevant LEDs on the I/O module light?
2.  have you connected both 0V and 24V for output group 0-3?
3. Have you connected the other side of your load to 0V, as the CSMIO can only source current?

Allan
Re: output on/off from same button
« Reply #6 on: April 11, 2018, 06:50:44 PM »
Hi,
yes there is some confusion between the Enable outputs and user Outputs. Try the same script but with OSIG_OUTPUT20 say.

May I suggest also that you not use M17 as a function name, use M100 or greater as user macros and M99 and under
are Mach Macros prehaps with modification. My concern is that your M17 macro may have unintended consequences
as regular Mach may already have an M17 which you have overwritten.

Allan has considerable experience with CSLabs boards and Mach4. Note CSLabs by their own admission their Mach4 plugin is a work
in progress. Allan has, in another thread, claimed CSLabs treatment of Mach outputs is mature however there are some
questions in my mind about them.

Craig
My wife left with my best friend...
     and I miss him!
Re: output on/off from same button
« Reply #7 on: April 16, 2018, 01:54:16 AM »
Hello guys,
I'll be back to update you. I managed to solve with your advice even if I had to use only the outputs above # 20 in mach 4, otherwise they will not work. I have no idea why.
Now I'll be able to work on ATC, and I'll definitely ask for help again about management of the Spindle's safeties, I will mount an HSD ES950.
thank you

Danilo
Re: output on/off from same button
« Reply #8 on: April 16, 2018, 02:38:11 AM »
Hi,
ask CSLabs, its their device, they are collecting money from customers for a product that does not work as advertised. Until customers like you hassle
them no changes will occur. Remember these board are sold at a premium but perform very much less well than my ESS at a third the price.

Craig
My wife left with my best friend...
     and I miss him!
Re: output on/off from same button
« Reply #9 on: April 24, 2018, 02:48:40 PM »
Hello guys,
I already warned cs lab and they replied that they are working on a release to fix.
I would like to have information on some aspects that I can not really understand:
following the manuals I managed to use the tool change, even if I do not understand how to program logical sequences, for all the security functions:
for example, after an m6 t2 command I would like:
- open protection
 - wait for the open protection signal to be on
- go to position (it works)
- release tool (works)
-Wait signal no tool (I can read but I can not use it)
- move to another position (works)
- hook tool (works)
-Wait signal tool ok (I can read but I can not use it)
- return to z safe (it works)
- close protection
- wait for closed protection signal
-m6 end

individually I can do everything, but I can not make them work in this sequence in the same macro, can you explain to me how is logic?
from the manuals I can not understand and I can not find examples even sifting through the whole forum.


moreover I would like to implement the safety devices also in M3 (if tool = 0 spindle does not have to turn on, if door is not closed spindle it does not have to turn on)

or, if low air pressure blocks everything.

or again:
if input x = 1:
- close doors
- wait for a closed door signal
- start cycle

I know that there are many questions, but I would like to understand only where to intervene, then I want to understand for myself how to develop everything, I would need an input from you experts.

Thank you so much for the help

Danilo