EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

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

Subject: Re: Creating a record and using its instance.
From: "Johnson, Andrew N. via Tech-talk" <tech-talk at aps.anl.gov>
To: "Wang, Andrew" <wang126 at llnl.gov>
Cc: EPICS tech-talk <tech-talk at aps.anl.gov>
Date: Mon, 12 Apr 2021 22:40:10 +0000
Hi Andy,

I applaud your attempt, but unfortunately you may have started with the wrong template to implement your own record type – doing that isn’t something that I’d suggest for beginners unless they start with the code for an existing record type and make incremental changes. If you want to start extending the code inside the IOC database, I would suggest starting by implementing a new device support for an existing record type.

In fact not many EPICS developers or sites have written their own record types. The ability to swap in a different piece of hardware by linking to a different device support module and changing the DTYP field may have dissuaded creating many new record types, since custom types won’t be supported by anyone else’s device support. I’m not suggesting that you can’t or shouldn’t write your own, but it’s unusual.

I would recommend use makeBaseApp.pl to create a copy of the “example” template and look at the xxxRecord which that instantiates for you in the *App/src directory. That provides a working record type with device support and the necessary Makefile settings, which you can then rename and modify as you wish. Unfortunately it doesn’t quite follow all the best practices that have been implemented in the Base records, but it will give you something that works. There is also an example device support for the lsi (long string input) record in devexampleVersion.c which may be worth looking at too.

Good luck!

- Andrew



On Apr 12, 2021, at 1:46 PM, Wang, Andrew via Tech-talk <tech-talk at aps.anl.gov> wrote:
> 
> All,
>  
> This will be a lengthy post, so please bear with me.
>  
> I am currently trying to create my own record called “sample”, then create a record instance of “sample” for use in an IOC. The manual helped immensely, but I am still a bit stuck and would appreciate some insight.
>  
> For creating the record, what I did first was first create a support application by using the command:
>  
> makeBaseApp.pl -t support sample
>  
> Then, I modified the configure/RELEASE file so that the correct path for EPICS is specified. Next, I went to sampleApp/src and created two files: sampleRecord.dbd and sampleRecord.c. Here is what I currently have for them.
>  
> sampleRecord.dbd:
>  
> recordtype(sample) 
> {
>       include "dbCommon.dbd"
>       field(VAL, DBF_DOUBLE)
>       {
>             asl(ASL0)
>             pp(TRUE)
>       }
>       field(OVAL, DBF_DOUBLE)
>       {
>       }
> }
>  
> sampleRecord.c:
>  
> // EPICS IOC header files
> #include "callback.h"
> #include "dbAccess.h"
> #include "dbBase.h"
> #include "dbDefs.h"
> #include "dbFldTypes.h"
> #include "dbScan.h"
> #include "dbStaticLib.h"
> #include "devLib.h"
> #include "devSup.h"
> #include "drvSup.h"
> #include "epicsExport.h"
> #include "initHooks.h"
> #include "link.h"
> #include "recSup.h"
> #include "special.h"
> #include "taskwd.h"
>  
> // Record support header files
> #include "sampleRecord.h"
>  
> // C standard library header files
> #include <stdio.h>
> static long init_record(void*, int);
> static long process(void*);
> rset sampleRSET={ 
>     RSETNUMBER, 
>     NULL, 
>     NULL, 
>     init_record, 
>     process, 
>     NULL, 
>     NULL, 
>     NULL, 
>     NULL, 
>     NULL, 
>     NULL,
>     NULL,
>     NULL, 
>     NULL, 
>     NULL, 
>     NULL, 
>     NULL, 
>     NULL 
> };
> epicsExportAddress(rset, sampleRSET);
>  
> static long init_record(void* precord, int pass)
> {
>       //long status;
>       //int size_desc;
>       sampleRecord *r;
>       
>       r = (sampleRecord *) precord;
>       
>       if (!pass)
>       {
>             //size_desc = sizeof(r->desc) / sizeof(char);
>             //snprintf(r->desc, size_desc, "%s", "Hello");
>             printf("I've been initialized!\n");
>             
>             return 0;
>       }
>       
>       return 0;
> }
>  
> static long process(void* precord)
> {
>       printf("I've been processed!\n");
>       
>       return 0;
> }
>  
> My goal is to use channel access and see those two messages printed when running iocBoot. For instance, when I run caput sample_record_instance.PROC 1, hopefully it will print “I’ve been processed”.
>  
> In my following steps, I modified the Makefile in sampleApp/src to be:
>  
> TOP=../..
>  
> include $(TOP)/configure/CONFIG
> #----------------------------------------
> #  ADD MACRO DEFINITIONS AFTER THIS LINE
> #=============================
>  
> #==================================================
> # build a support library
>  
> LIBRARY_IOC += sample
>  
> # xxxRecord.h will be created from xxxRecord.dbd
> DBDINC += sampleRecord.h
>  
> # install sample.dbd into <top>/dbd
> DBD += sampleRecord.dbd
>  
> # specify all source files to be compiled and added to the library
> sample_SRCS += sampleRecord.c
>  
> sample_LIBS += $(EPICS_BASE_IOC_LIBS)
>  
> #===========================
>  
> include $(TOP)/configure/RULES
> #----------------------------------------
> #  ADD RULES AFTER THIS LINE
>  
> So after making these modifications and additions, I ran make in TOP and no errors were produced.
>  
> Finally, I created an IOC application and iocBoot type called “test_sample”. In the configure/RELEASE file, I included:
>  
> SAMPLE = ${HOME}/myepics/support/sample
>  
> Then, I created a record instance for “sample” in a database file within test_sampleApp/Db:
>  
> record(sample, “sample_record_instance”)
> {
>       field(DESC, “Yay”)
> }
>  
> Finally, I modified the Makefile in test_sampleApp/src to be:
>  
> TOP=../..
>  
> include $(TOP)/configure/CONFIG
> #----------------------------------------
> #  ADD MACRO DEFINITIONS AFTER THIS LINE
> #=============================
>  
> #=============================
> # Build the IOC application
>  
> PROD_IOC = test_sample
>  
> # test_sample.dbd will be created and installed
> DBD += test_sample.dbd
>  
> # test_sample.dbd will be made up from these files:
> test_sample_DBD += base.dbd
>  
> # Include dbd files from all support applications:
> test_sample_DBD += sampleRecord.dbd
>  
> # Add all the support libraries needed by this IOC
> test_sample_LIBS += sample
>  
> # test_sample_registerRecordDeviceDriver.cpp derives from test_sample.dbd
> test_sample_SRCS += test_sample_registerRecordDeviceDriver.cpp
>  
> # Build the main IOC entry point on workstation OSs.
> test_sample_SRCS_DEFAULT += test_sampleMain.cpp
> test_sample_SRCS_vxWorks += -nil-
>  
> # Add support from base/src/vxWorks if needed
> #test_sample_OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary
>  
> # Finally link to the EPICS Base libraries
> test_sample_LIBS += $(EPICS_BASE_IOC_LIBS)
>  
> #===========================
>  
> include $(TOP)/configure/RULES
> #----------------------------------------
> #  ADD RULES AFTER THIS LINE
>  
> However, when I run make in TOP, I receive the following error:
>  
> test_sample_registerRecordDeviceDriver.o: In function `_GLOBAL__sub_I_test_sample_registerRecordDeviceDriver':
> test_sample_registerRecordDeviceDriver.cpp:(.text.startup+0x2b5): undefined reference to `pvar_func_sampleRecordSizeOffset'
>  
> Any thoughts?
>  
> Thank you,
> Andy

-- 
Complexity comes for free, simplicity you have to work for.


Replies:
RE: Creating a record and using its instance. Wang, Andrew via Tech-talk
References:
Creating a record and using its instance. Wang, Andrew via Tech-talk

Navigate by Date:
Prev: Re: Creating a record and using its instance. Hu, Yong via Tech-talk
Next: RE: Creating a record and using its instance. Wang, Andrew via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  <20212022  2023  2024 
Navigate by Thread:
Prev: Re: Creating a record and using its instance. Hu, Yong via Tech-talk
Next: RE: Creating a record and using its instance. Wang, Andrew via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  <20212022  2023  2024 
ANJ, 12 Apr 2021 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·