Hello Guest it is April 18, 2024, 02:14:09 PM

Author Topic: mpg  (Read 1726 times)

0 Members and 1 Guest are viewing this topic.

Offline mark4

*
  •  167 167
    • View Profile
mpg
« on: June 22, 2016, 09:26:29 PM »
hi
i am writing an mpg in signal script under SigLib. it has rotary switches x y z a and 1 .1 .01 .001 four positions as this is a stepper machine and this is the resolution i can get the mpg to work in smooth stepper diagnostics screen but have yet to convince mach to see it may not be programmed properly yet. also i am programming rotary switches the question is which is proper or better this

[mc.ISIG_INPUT0] = function (state)
      if (state == 1) then
         have to figure out what to put here
      end
end,

or this

[mc.ISIG_INPUT0] = function (on_off)
      if (on_off == 1) then
         have to figure out what to put here
      end
end,

there is allot of information some conflicting some confusing. is signal script being used or is it mostly or all screen load script
thank you
mark
Re: mpg
« Reply #1 on: June 23, 2016, 11:16:18 AM »
Either form is OK.  The first form (with the variable named "state") is consistent with the sample code in the original wx4 screen set, so some may argue for consistency's sake use that.  The important thing is that the naming of the function variable makes sense (primarily to you, secondarily to others).

As to the signal script vs load script - it is using BOTH.  The signal script (in the wx4 screen set) simply calls the scripts in the SigLib array that is defined in the screen load script.  The idea (I believe) is to put most of the customized code in the screen load script instead of having some there and some in the signal script.

Also keep in mind that the SigLib scripts get called only on a *change* in the signal, either from 0 to 1, or from 1 to 0.  You can test both for a signal going high/active *and* going low/inactive by including an "else" clause, like this:
Code: [Select]
[mc.ISIG_INPUT0] = function (state)
      if (state == 1) then
         have to figure out what to put here
      else
         -- This "else" clause executes when the signal transitions to the "off/low/inactive" state
      end
end,