This should work. I changed the time to 5 seconds but you can adjust as needed.
Note, I have it putting the first checks in a MessageBox, the last 2 checks write them to the status bar or message bar in Mach. All of them write a message even if there is no error (MERROR_NOERROR).
function m100()
local inst, hSig, rc
inst = mc.mcGetInstance()
hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1) -- Get handle for output 1
if (rc == mc.MERROR_NOERROR) then
wx.wxMessageBox("MERROR_NOERROR")
elseif (rc == mc.MERROR_INVALID_INSTANCE) then
wx.wxMessageBox("MERROR_INVALID_INSTANCE")
elseif (rc == mc.MERROR_SIGNAL_NOT_FOUND) then
wx.wxMessageBox("MERROR_SIGNAL_NOT_FOUND")
end
rc = mc.mcSignalSetState(hSig, 1) --turn on output 1
if (rc == mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "MERROR_NOERROR")
elseif (rc == mc.MERROR_INVALID_ARG) then
mc.mcCntlSetLastError(inst, "MERROR_INVALID_ARG")
end
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT21, 1, 5) --Wait 5 seconds for input 21 to become active
if (rc == mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "MERROR_NOERROR")
elseif (rc == mc.MERROR_INVALID_INSTANCE) then
mc.mcCntlSetLastError(inst, "MERROR_INVALID_INSTANCE")
elseif (rc == mc.MERROR_INVALID_ARG) then
mc.mcCntlSetLastError(inst, "MERROR_INVALID_ARG")
elseif (rc == mc.MERROR_NOT_ENABLED) then
mc.mcCntlSetLastError(inst, "MERROR_NOT_ENABLED")
elseif (rc == mc.MERROR_TIMED_OUT) then
mc.mcCntlSetLastError(inst, "MERROR_TIMED_OUT")
end
end
if (mc.mcInEditor() == 1) then
m100()
end