Hello Guest it is August 20, 2019, 08:54:42 AM

Author Topic: Read external input  (Read 883 times)

0 Members and 1 Guest are viewing this topic.

Read external input
« on: August 04, 2017, 11:04:30 PM »
Hello everyone, I'm new working with Mach 4 and I have the following problem:

I made a M Code (M110) to read an external input and depending on its state show a text. The problem is that running the M110 from the MDI does not read the input and I do not know if I have to activate something or I have to do it another way.

Thanks for the help...

Test code:

function m110()

   local inst = mc.mcGetInstance()
   hReg = mc.mcIoGetHandle(inst, mc.ISIG_INPUT1)
   
   if hReg == 1 then
        wx.wxMessageBox("External input activated!")
    else
        wx.wxMessageBox("External input disabled!")
    end
end

if (mc.mcInEditor() == 1) then
 m110()
end





Re: Read external input
« Reply #1 on: August 05, 2017, 04:26:55 PM »
Hi,
your post would get more readers if in the Mach4 board...

I would use Mach4 signals....
Quote
hReg = mc.mcIoGetHandle(inst, mc.ISIG_INPUT1)
gets the handle of an IO whereas mc.ISIG_INPUT1 is a Mach4 signal...
hReg=mc.mcSignalGetHandle(inst,mc.ISIG_INPUT1)

Quote
if hReg == 1 then
tests the handle not the state of the signal. It is a good idea to test the handle to make sure its valid, if you try
to read the state of the signal at the handle address and the handle is invalid Mach will crash. If you do test it, it is assumed valid if NOT zero...
if hReg =! 0 then

Assuming the handle is good now read the state of the signal....
SignalState,rc=mc.mcSignalGetSate(hReg)

Remember that a 'handle' is a numerical address of an IO or Signal or Register in Mach. While IO, Signals and Registers may have useful names, numbers
or paths they must be reduced to a numerical address, a handle, before you can access them.

Craig
My wife left with my best friend...
     and I miss him!
Re: Read external input
« Reply #2 on: August 05, 2017, 08:12:12 PM »
Thanks for your reply...

When I have a result I will be commenting
Re: Read external input
« Reply #3 on: August 14, 2017, 11:12:41 PM »
Hello joeaverage
I did the tests as you recommended but I did not work

All the examples that I saw in internet speak of the "Signal Script" but not an M code.

Does anyone know if it is possible to consult the state of an external input from an M code?

I try to create a M code (example M110) and call it from the G code terminal or from MDI terminal, is it possible?

Thanks for the help...
Re: Read external input
« Reply #4 on: August 15, 2017, 03:28:05 AM »
Hi,
Ive already got an m110 so I called this m120 instead...
Code: [Select]
function m120();
local inst=mc.mcGetInstance();
local SigHandle=mc.mcSignalGetHandle(inst,mc.ISIG_INPUT1);
if SigHandle==0 then wx.wxMessageBox('Bad Handle') end;
SigState,rc=mc.mcSignalGetState(SigHandle);
if SigState==0 then
    wx.wxMessageBox('SigState is false');
else
    wx.wxMessageBox('SigState is true')
end
end

if mc.mcInEditor()==1 then
    m120()
end

and it seems to work.

Craig
My wife left with my best friend...
     and I miss him!