Machsupport Forum
Mach Discussion => General Mach Discussion => Topic started by: wildu 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
-
Hi,
your post would get more readers if in the Mach4 board...
I would use Mach4 signals....
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)
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
-
Thanks for your reply...
When I have a result I will be commenting
-
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...
-
Hi,
Ive already got an m110 so I called this m120 instead...
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