Hello Guest it is March 28, 2024, 11:25:44 AM

Author Topic: Macro - Pause until input triggered  (Read 8328 times)

0 Members and 1 Guest are viewing this topic.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Macro - Pause until input triggered
« Reply #20 on: September 28, 2016, 12:02:58 PM »
yay you lot have been busy, glad its working for you now.

DazTheGas

Thanks Daz!

I have not had a use for the mc.mcSignalWait API call yet so hadn't used it beofre but bet I will find a use for it real soon now. :)

Love it when a plan comes together! The devil is in the details. Thankfully the details are covered pretty good in the help file.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Macro - Pause until input triggered
« Reply #21 on: September 28, 2016, 12:56:30 PM »
Quote
This does not do any error checking and the time it waits for the input to go high is indefinite (neither of which are very good ideas) and it does not take your "In automatic Cycle" into account but it should be all that is needed to do what you were looking for originally.

Could you recommend the proper error checking for this? I have been neglecting that too much while focusing on getting the code to work.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Macro - Pause until input triggered
« Reply #22 on: September 28, 2016, 03:09:55 PM »
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).

Code: [Select]
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
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Macro - Pause until input triggered
« Reply #23 on: September 29, 2016, 02:14:12 AM »
Hi Guys,

reading Robs post and I saw:

if (rc == mc.MERROR_NOERROR) then
      wx.wxMessageBox("MERROR_NOERROR")

I have been writing code similar to:

if(rc==0)then
                wx.wxMessageBo("MERROR_NOERROR")
 
ie I've been testing the numeric value of rc against a list provided by DTG but
this suggests that mc.MERROR_NOERROR is a defined quantity. Is this correct?

If so 'gotta luv C'

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Macro - Pause until input triggered
« Reply #24 on: September 29, 2016, 03:14:27 AM »
That is correct, 0 is the same as mc.MERROR_NOERROR just like in the command 1 is the same as mc.WAIT_MODE_HIGH, these have been defined in C but can be accessed by the leading mc.

DazTheGas
New For 2022 - Instagram: dazthegas

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Macro - Pause until input triggered
« Reply #25 on: September 30, 2016, 04:32:40 PM »
I am going to look at adding an error check module and the necessary bits to make it work in the default profiles. I have done it and tested it already and got it all working with some help from DTG. I had a very simple mistake and just kept overlooking it.  :-[  Garbage in is garbage out and I'm not immune from giving it some garbage myself. I think most when they start out coding have those moments when they want to kick their own butt. Happens to us all I think so remember that when your ready to give up.

Anyway, the m100 discussed earlier in this topic would like this after its all done. I like this much better..........

Code: [Select]
function m100()

local inst, hSig, rc
inst = mc.mcGetInstance()

hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1) -- Get handle for output 1
if (rc~= 0) then --Check our errors
mc.mcCntlSetLastError(inst, (mcErrorCheck[rc]))
                --wx.wxMessageBox(mcErrorCheck[rc]) --popup a message box with the error
end

rc = mc.mcSignalSetState(hSig, 1) --turn on output 1
if (rc~= 0) then --Check our errors
mc.mcCntlSetLastError(inst, (mcErrorCheck[rc]))
end

rc = mc.mcSignalWait(inst, mc.ISIG_INPUT21, 1, 5) --Wait 5 seconds for input 21 to become active
if (rc~= 0) then mc.mcCntlSetLastError(inst, (mcErrorCheck[rc])) end --In line check our errors works too

end

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

« Last Edit: September 30, 2016, 04:38:25 PM by Chaoticone »
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Macro - Pause until input triggered
« Reply #26 on: October 01, 2016, 10:13:23 AM »
Yes that looks nice and clean.