epics-modules / xxx

APS BCDA synApps module: xxx
http://epics-modules.github.io/xxx
Other
5 stars 6 forks source link

use PREFIX env var here #29

Closed prjemian closed 4 years ago

prjemian commented 4 years ago

fixes #28

prjemian commented 4 years ago

This module expects $IOC to not have a trailing colon :. The $PREFIX must be edited or PVs with :: will be produced.

Here's a way to do this in bash: SO post

This does not work in the IOC shell:

iocxxx> echo $(PREFIX)
bc2:
iocxxx> echo $(PREFIX::-1)
macLib: macro PREFIX::-1 is undefined (expanding string echo $(PREFIX::-1))

so do not merge this PR until a solution is found.

prjemian commented 4 years ago

@keenanlang @anjohnson : How to delete the last character from an EPICS environment variable in the IOC console?

prjemian commented 4 years ago

Going to tech-talk with this question.

prjemian commented 4 years ago

Looking at the EPICS AppDevGuide, I'm not sure this is possible unless using some other tool, such as lua. The IOC's help command shows this for lua: luaSpawn luash

@keenanlang can you construct the lua command to do this( possibly defining a new env var if needed)?

prjemian commented 4 years ago

luash help: https://github.com/epics-modules/lua/blob/master/documentation/using_lua_shell.md

prjemian commented 4 years ago

@keenanlang : in lua, something like PREFIX:sub(?, ?) but how to do that?

keenanlang commented 4 years ago

I wouldn't suggest doing this with lua, but it can be done. In the latest release of the lua module, you can do:

PREFIX = os.getenv("PREFIX")
epicsEnvSet("SOME_NAME", string.sub(PREFIX, 1, #PREFIX - 1)

The only difference for older versions is you'll have to put iocsh.epicsEnvSet

Put that in a file and call it with luash, there is no current equivalent to iocshRun to do one-liners.

I'd instead take Michael's suggestion from tech-talk and define a macro that's just xxx and use that to construct PREFIX. At least for the time being. There has been discussion of this issue already on iocStats to change the databases so that you can get rid of the trailing separator, then there would be no need to have two macros. See:

https://github.com/epics-modules/iocStats/pull/32 https://github.com/epics-modules/iocStats/issues/31

prjemian commented 4 years ago

A change in iocStats's databases is the best way. The others are more fragile. It would be interesting to demonstrate this with lua. Can you construct the steps to run that in the IOC shell? Treat me like the lua novice that I am.

keenanlang commented 4 years ago

To do it with lua, just take those two lines and put them into a file, let's say 'substring.lua'.

If you put that file in the IOC's startup directory, the IOC doesn't need to be told anything else. If you want to put it in a subdirectory, then you'll want to define the environment variable LUA_SCRIPT_PATH. I generally put all the lua stuff in a scripts subdirectory so I have a line in the ioc startup script like so:

epicsEnvSet("LUA_SCRIPT_PATH","./scripts")

Then, later in the startup script, when you want the lua commands to be run, just do:

luash "substring.lua"
prjemian commented 4 years ago

Closing since this work is superceded by #31.