Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synApps luascript record as ophyd Device #532

Closed
prjemian opened this issue Sep 7, 2021 · 8 comments · Fixed by #617
Closed

synApps luascript record as ophyd Device #532

prjemian opened this issue Sep 7, 2021 · 8 comments · Fixed by #617
Milestone

Comments

@prjemian
Copy link
Contributor

prjemian commented Sep 7, 2021

The EPICS lua module has support for the luascript record. Build a Device for the luascript record.

synApps lua

@prjemian prjemian added this to the 1.5.2 milestone Sep 7, 2021
@prjemian
Copy link
Contributor Author

prjemian commented Sep 7, 2021

The INPA --> A field structures look like one of the userCalcs.

@prjemian
Copy link
Contributor Author

prjemian commented Sep 7, 2021

Note the docker xxxx IOC (synApps 6.2) already has 20 of these luascript records (2 sets of 10):

root@zap:/opt/iocxxx# less /opt/synApps/support/lua-R3-0-1/luaApp/Db/luascripts10.db
root@zap:/opt/iocxxx# grep set1 dbl-all.txt 
gp:set1:userScriptEnable
gp:set1:EnableUserScripts
gp:set1:DisableUserScripts
gp:Slit1Vset1
gp:Slit1Hset1
gp:set1:userScript0
gp:set1:userScript1
gp:set1:userScript2
gp:set1:userScript3
gp:set1:userScript4
gp:set1:userScript5
gp:set1:userScript6
gp:set1:userScript7
gp:set1:userScript8
gp:set1:userScript9
root@zap:/opt/iocxxx# grep set2 dbl-all.txt 
gp:set2:userScriptEnable
gp:set2:EnableUserScripts
gp:set2:DisableUserScripts
gp:set2:userScript0
gp:set2:userScript1
gp:set2:userScript2
gp:set2:userScript3
gp:set2:userScript4
gp:set2:userScript5
gp:set2:userScript6
gp:set2:userScript7
gp:set2:userScript8
gp:set2:userScript9
root@zap:/opt/iocxxx# 

@prjemian
Copy link
Contributor Author

prjemian commented Sep 7, 2021

root@zap:/opt/iocxxx# grep lua *
common.iocsh:dbLoadRecords("$(LUA)/luaApp/Db/luascripts10.db", "P=$(PREFIX), R=set1:")
common.iocsh:dbLoadRecords("$(LUA)/luaApp/Db/luascripts10.db", "P=$(PREFIX), R=set2:")
envPaths:epicsEnvSet("LUA","/opt/synApps/support/lua-R3-0-1")
settings.iocsh:# search path for lua scripts

@prjemian prjemian modified the milestones: 1.5.2, 1.5.3 Sep 24, 2021
@prjemian
Copy link
Contributor Author

Not needed immediately, pushing to next milestone.

Needs example lua script to use for testing and example. @keenanlang Can you provide an example?

@prjemian prjemian modified the milestones: 1.5.3, 1.6.0 Oct 13, 2021
@prjemian
Copy link
Contributor Author

prjemian commented Dec 7, 2021

lua support

@prjemian
Copy link
Contributor Author

prjemian commented Dec 7, 2021

Examples:

  • Set VAL to the result of A + B

    field(CODE, "return A + B")

  • Set SVAL to the concatenation of AA and BB

    field(CODE, "return AA .. BB")

  • Run the function ‘example’ from the file test.lua with zero parameters.

    field(CODE, "@test.lua example")

  • Run the function ‘example’ from the file test.lua with two parameters, one a number, the other a string.

    field(CODE, "@test.lua example(1, ‘foo’)")

  • Factorial example - might be a good unit test for file test.lua

  • Tutorial

  • Basic Syntax

@prjemian
Copy link
Contributor Author

prjemian commented Dec 7, 2021

test.lua from above example:

    -- defines a factorial function
    function fact (n)
      if n == 0 then
        return 1
      else
        return n * fact(n-1)
      end
    end

@prjemian
Copy link
Contributor Author

prjemian commented Dec 7, 2021

From the luascript record's documentation:

The CODE expression can also be used to reference a file containing the description of at least a single lua function. If the CODE field starts with the symbol @ followed by the name of said file, the luascript record will search through a list of directories given by the environment variable LUA_SCRIPT_PATH (default: current directory) for the given file. A space character and then the name of a function defined in the file lets the luascript record know what function to call when the record processes. Optionally, a set of parameters can be provided that the function will be called with each processing by including a comma separated list enclosed by parentheses.

prjemian added a commit that referenced this issue Jan 10, 2022
prjemian added a commit that referenced this issue Jan 11, 2022
prjemian added a commit that referenced this issue Jan 11, 2022
prjemian added a commit that referenced this issue Jan 11, 2022
prjemian added a commit that referenced this issue Jan 11, 2022
prjemian added a commit that referenced this issue Jan 11, 2022
prjemian added a commit that referenced this issue Jan 11, 2022
prjemian added a commit that referenced this issue Jan 11, 2022
prjemian added a commit that referenced this issue Jan 11, 2022
prjemian added a commit that referenced this issue Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant