Hello Guest it is April 26, 2024, 03:38:00 AM

Author Topic: difference between mc.mcSignalWait and mc.mcSignalHandleWait ??  (Read 697 times)

0 Members and 1 Guest are viewing this topic.

difference between mc.mcSignalWait and mc.mcSignalHandleWait ??
« on: October 31, 2020, 03:07:58 PM »
Hi
I want create macro for wait signal input for do next step.
But I don't know how to use about

mcSignalWait
and
mcSignalHandleWait

Asis
Re: difference between mc.mcSignalWait and mc.mcSignalHandleWait ??
« Reply #1 on: November 03, 2020, 01:06:51 AM »
Hi,
the difference between the two is:

Code: [Select]
LUA Syntax:
rc = mc.mcSignalWait(
number mInst,
number sigId,
number waitMode,
number timeoutSecs);

Description:
Wait on a signal to change state.

Parameters: Parameter Description
mInst The controller instance.
sigId A valid signal ID. (NOT a signal handle)
waitMode An integer specifying whether to wait on the signal to go high (WAIT_MODE_HIGH) or low (WAIT_MODE_LOW).
timeoutSecs A double specifying a timeout period.

and:
Code: [Select]
LUA Syntax:
rc = mc.mcSignalHandleWait(
number hSig,
number waitMode,
number timeoutSecs);

Description:
Wait on a signal to change state.

Parameters: Parameter Description
hSig The handle for the signal.
waitMode An integer specifying whether to wait on the signal to go high (WAIT_MODE_HIGH) or low (WAIT_MODE_LOW).
timeoutSecs A double specifying a timeout period.

So one API uses a Signal_ID where the other uses a Signal_Handle.

All signals in Mach have a numeric signal number or identifier, for instance input signal ISIG_15 has a numeric identifier 16 and the probe signal ISIG_PROBE1
has a numeric identifier of 183 for example. These are Signal_ID's . You can find some useful signal identifiers, other useful ENUMS and various other
lists like machine states, error identifiers etc  here:

https://www.machsupport.com/forum/index.php?topic=40051.0

If you find the Signal_Handle with mc.mcSignalGetHandle(....) a number will be returned corresponding to the handle, an hexadecimal integer of commonly
5 or 6 digits. The 'handle' means...sort of....the current memory location that the variable of interest is in.

Lua is a dynamic memory language and a variable may not have one constant and unchanging memory address but rather its
memory location will be formed, used and then 'garbage collected' as the program segment goes out of scope, whereas a Signal_ID is
constant.

The use of either is fine, all you have to remember is that you get a current signal handle from within the current scope in order to address
a signal variable. While it sounds like using a Signal_ID is better it is programmatically less efficient because Lua has to stop, look up the Signal_ID
table, which could well be in another page of memory,  get the signal current handle, then execute the Signal_Wait routine. Additionally a Signal_ID
is numeric and therefore prone to human confusion, a Signal_ENUM is far less confusing and much easier to read many months after you have
written the code.

I fell into a trap in the early days. I was trying to use mc.mcSignalHandle Wait(inst, mc.ISIG_SPINDLE_AT_SPEED).

The numeric identifier for ISIG_SPINDLE_AT_SPEED is 181. What I did not know was at that time the SignalHandleWait() API was limited to a
signal identifiers of 64 or less and the API failed. It took a lot of shagging around before I discovered the reason. I believe that limitation has since
been rectified but it serves to point out that you are inviting trouble if you do not test EACH AND EVERY possible return code for this API otherwise
you are inviting Mach to hang up, and you'll have to use Task_Manager to stop it, very, VERY tedious after a while.

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