EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  <20012002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  <20012002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re:
From: Eric Norum <[email protected]>
Cc: Mythili Srinivasan <[email protected]>, [email protected]
Date: Mon, 25 Jun 2001 10:46:23 -0600
Andrew Johnson wrote:
> 
> Mythili Srinivasan wrote:
> >
> > I have written myHookInit, myHookFuncioon as mentioned in the application
> > developer guide.
> >   For vxworks based EPICS if the commands in st.cmd are as follows,
> >
> >   ld<bin/myHook.o
> >   myHookInit
> >
> >   then, what is the equivalent for stcmd.host on linux ?
> 
> The ld command is replaced by linking myHook.o into your executable, add
> myHook.c to the example_SRCS_DEFAULT variable in your
> exampleApp/src/Makefile.  Then you just have to get it called early
> enough, the simplest way to do this is probably to put a call to
> myHookInit() into your main() routine in exampleMain.c before it executes
> iocsh().  To call myHookInit() from the startup script you'd need to get
> it registered with the registration facility, and I'm not sure what the
> simplest way is to do this right now as I haven't worked in this area yet.
> 

Probably the simplest way to register your command with the iocsh so
that you can call it from your startup script is to use a C++ static
constructor.  This is the technique used by the IOC core routines to
register the default set of IOC shell commands and by the state notation
compiler to register the additional commands provided when SNL programs
are present.  The technique is also used by the GPIB/LAN adapter driver
to register its driver initialization command.

Here's the code from the GPIB/LAN adapter (caveat -- I'm about as far as
one can get from being a C++ expert, but the code does seem to work):

===============================================================================
extern "C" {

/*
 * Register commands associated with the HP E2050 Ethernet/GPIB adapter
 */
#include <iocsh.h>

extern int drvHpGpibConfig(
	short link,
	char *hostName,
	int recoverWithIFC,
	int defTimeout,
	char *vxiName);

static const iocshArg drvHpGpibConfigArg0 = { "link",iocshArgInt};
static const iocshArg drvHpGpibConfigArg1 = { "host
name",iocshArgString};
static const iocshArg drvHpGpibConfigArg2 = { "recover with
IFC?",iocshArgInt};
static const iocshArg drvHpGpibConfigArg3 = { "default timeout
(msec)",iocshArgInt};
static const iocshArg drvHpGpibConfigArg4 = { "vxi
name",iocshArgString};
static const iocshArg *drvHpGpibConfigArgs[5] = {&drvHpGpibConfigArg0,
	&drvHpGpibConfigArg1, &drvHpGpibConfigArg2, &drvHpGpibConfigArg3,
	&drvHpGpibConfigArg4};
static const iocshFuncDef drvHpGpibConfigFuncDef =
{"drvHpGpibConfig",5,drvHpGpibConfigArgs};
static void drvHpGpibConfigCallFunc(const iocshArgBuf *args)
{
	short link = args[0].ival;
	char *hostName = args[1].sval;
	int recoverWithIFC = args[2].ival;
	int defTimeout = args[3].ival;
	char *vxiName = args[4].sval;

	drvHpGpibConfig (link, hostName, recoverWithIFC, defTimeout, vxiName);
}

/*
 * This routine is called before multitasking has started, so there's
 * no race condition in the test/set of firstTime.
 * This is made global so that it can be referenced from
drvHpE2050AGpib.c 
 * and thus pulled in from the library.
 */
void epicsShareAPI
drvHpGpibConfigRegisterCommands (void)
{
	static int firstTime = 1;
	if (firstTime) {
		firstTime = 0;
		iocshRegister(&drvHpGpibConfigFuncDef,drvHpGpibConfigCallFunc);
	}
};

} /* extern "C" */

class hpE2050Init {
public:
	hpE2050Init () { drvHpGpibConfigRegisterCommands(); }
};
static hpE2050Init hpE2050Init;
================================================================================

-- 
Eric Norum                                 [email protected]
Department of Electrical Engineering       Phone: (306) 966-5394
University of Saskatchewan                 FAX:   (306) 966-5407
Saskatoon, Canada.


References:
[no subject] Mythili Srinivasan
Re: Andrew Johnson

Navigate by Date:
Prev: Re: Andrew Johnson
Next: Minor problem with file names for genSub record CapFast symbols Redman, Russell O.
Index: 1994  1995  1996  1997  1998  1999  2000  <20012002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Andrew Johnson
Next: Re: Mythili Srinivasan
Index: 1994  1995  1996  1997  1998  1999  2000  <20012002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 10 Aug 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·