Hello Guest it is May 13, 2021, 02:53:35 AM

Author Topic: Lua Signal Table  (Read 5565 times)

0 Members and 1 Guest are viewing this topic.

Offline dude1

*
  •  1,253 1,253
    • View Profile
Lua Signal Table
« on: May 18, 2015, 02:55:20 AM »
I have run into a problem with signal tables from the scripting manual in it it has the sig table like this

SignalTable = { -------sig table number goes here I think without {
     [mc.ISIG_INPUT0] = function (on_off)
        if (on_off == 1) then
            mc.mcCntlCycleStart(inst)
        end
    end

I keep get a error this

Compilation error on line number: 54
Lua: Syntax error during pre-compilation
[string "C:\Users\Daniel\AppData\Local\Temp\le6115.mcc..."]:54: unexpected symbol near '['



I have searched but cant find anything to help I used this and it work`s

if (sig == mc.ISIG_INPUT1) and (state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlCycleStart(inst)
end

Offline DazTheGas

*
  •  753 753
  • DazTheGas
    • View Profile
Re: Lua Signal Table
« Reply #1 on: May 18, 2015, 05:39:31 AM »
Quote
I have run into a problem with signal tables from the scripting manual in it it has the sig table like this

You got a link to this manual..

DazTheGas
Theres always time for a choccy biccy

Offline dude1

*
  •  1,253 1,253
    • View Profile

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Lua Signal Table
« Reply #3 on: May 18, 2015, 06:04:21 AM »

changed to this seems to work
SignalTable = {001,    --sig table number goes here I think
     [mc.ISIG_INPUT0] = function (on_off)
        if (on_off == 1) then
            mc.mcCntlCycleStart(inst)
        end
    end

then for this bit
if (SignalTable[001] ~= nil) then
SignalTable[001](on_off)
end

it cant find the input

also the editing is a bit out in the manual

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: Lua Signal Table
« Reply #4 on: May 18, 2015, 07:16:10 AM »
in your first post, you are missing the closing "}" for the sig table.

Scott
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Lua Signal Table
« Reply #5 on: May 18, 2015, 03:45:51 PM »
yep found that the call not working now

if (SignalTable[001] ~= nil) then
SignalTable[001](on_off)
end

it cant find the table

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Lua Signal Table
« Reply #6 on: May 18, 2015, 07:02:45 PM »
right it goes like this.

SignalTable = {001,                                  --your sig table number goes here it compiles and runs like this
     [mc.ISIG_INPUT0] = function (on_off)
        if (on_off == 1) then
            mc.mcCntlCycleStart(inst)             --name of button command
        end
    end
}

I think this is now correct if I am wrong someone comment please.

the only problem now when I run the other part of the code it cant find the signal table.

this is the other part

if (SignalTable[sig] ~= nil) then   --I think sig is the number of the table
SignalTable[sig](state)                --I think state is (on_off) or on_off == 1) like I have it below
end

if (SignalTable[001] ~= nil) then
SignalTable[001](on_off)
end
Re: Lua Signal Table
« Reply #7 on: January 02, 2016, 12:28:00 PM »
Could someone who understands Lua explain what is going on here?  This reference (http://www.lua.org/pil/3.6.html) describes Lua table constructors.  Based on that, it looks like this:

SignalTable = {001,
     [mc.ISIG_INPUT0] = function (on_off)
        if (on_off == 1) then
            mc.mcCntlCycleStart(inst)
        end
    end
}

would construct a new table stored in SignalTable with [1] = 001 and [mc.ISIG_INPUT0] = function...

1. Why is the 001 needed?
2. If I want to add additional signals and functions, it seems as though I would need to add them to this SignalTable constructor inside the "{}", but in another post it said that the way to do that was to add additional constructors of the form:

SignalTable = {00n,
     [mc.ISIG_INPUTn] = function (on_off)
        if (on_off == 1) then
            ....
        end
    end
}

Wouldn't this overwrite the previous SignalTable declarations?

Offline DazTheGas

*
  •  753 753
  • DazTheGas
    • View Profile
Re: Lua Signal Table
« Reply #8 on: January 02, 2016, 02:41:33 PM »
If you want to use the table version of this then your best place to add it is within the startup script, it is declared only once there and there are examples already there, this creates a table of signal check and what to do with them, this is then activated from the signal script the same as a function would be in the PLC.

DazTheGas
Theres always time for a choccy biccy
Re: Lua Signal Table
« Reply #9 on: January 02, 2016, 07:05:04 PM »
I followed your example and have F5 working for feed hold using the PLC script, which is delightful - thanks.

I would also like to see how it works using the signal table.  What I have tried doesn't work and I don't see what is wrong.
At the end of the Screen Load script, I have:

SignalTable = {
    [mc.ISIG_INPUT63] = function (on_off)
        if (on_off == 1) then
            local inst = mc.mcGetInstance();
            mc.mcCntlFeedHold(inst);
        end
    end,
}

At the end of the Signal Script, I have:

if (SignalTable[mc.ISIG_INPUT63] ~= nil) then
    SignalTable[mc.ISIG_INPUT63](state);
end