Closed prjemian closed 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.
@keenanlang @anjohnson : How to delete the last character from an EPICS environment variable in the IOC console?
Going to tech-talk with this question.
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)?
@keenanlang : in lua, something like PREFIX:sub(?, ?) but how to do that?
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
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.
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"
Closing since this work is superceded by #31.
fixes #28