A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
C Language.
1 1999/Ph 514: Channel Access Concepts EPICS Channel Access Concepts Bob Dalesio LANL.
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
EPICS Base R and beyond Andrew Johnson Computer Scientist, AES Controls Group.
Programming Languages and Paradigms The C Programming Language.
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Status of VDCT Mark Pleško, Matej Šekoranja, John Maclean EPICS Meeting – Japan, 2004.
Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Chapter 10.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Guide To UNIX Using Linux Third Edition
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
JavaIOC Marty Kraimer EPICS Collaboration Meeting ICALEPCS October
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Comp 248 Introduction to Programming Chapter 6 Arrays Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
JavaIOC EPICS Meeting SSRF March Presented by: Marty Kraimer.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
1 1999/Ph 514: Record Support EPICS Record Support Marty Kraimer APS.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
EPICS record/device/driver Support many slides copied from
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Field Support Ideas. Tech-talk, 19 July 2007 Good Afternoon, I have now for the th time explained to some desperate EPICS newbie all the hoops one has.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Implementing The Middle Tier These slides.
Strings and Text File I/O (and Exception Handling) Corresponds with Chapters 8 and 17.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
1 1999/Ph 514: Flow of Control EPICS Flow of Control Marty Kraimer APS.
Lecture 13: Arrays, Pointers, Code examples B Burlingame 2 Dec 2015.
How to write a MSGQ Transport (MQT) Overview Nov 29, 2005 Todd Mullanix.
EPICS Development for the ASKAP Design Enhancements Program ASTRONOMY AND SPACE SCIENCE Craig Haskins 18 th October 2015 EPICS User Meeting – Melbourne.
C++ for Java Programmers Chapter 2. Fundamental Daty Types Timothy Budd.
Argonne National Laboratory is managed by The University of Chicago for the U.S. Department of Energy ICALEPCS 2005: EPICS Workshop EPICS V4 : Runtime.
B. Dalesio, N. Arnold, M. Kraimer, E. Norum, A. Johnson EPICS Collaboration Meeting December 8-10, 2004 Roadmap for IOC.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
1 EPICS Flow of Control: EPICS Workshop at IHEP, Beijing, August 2001 EPICS Flow of Control Marty Kraimer APS.
Control System Overview J. Frederick Bartlett Fermilab June 1,1999.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
C Formatted Input/Output
JavaIOC Overview and Update
A bit of C programming Lecture 3 Uli Raich.
Objectives You should be able to describe: Interactive Keyboard Input
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
C Basics.
DATA HANDLING.
Some Basics for Problem Analysis and Solutions
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
EPICS Record/Device/Driver Support Interfaces
Programming Languages and Paradigms
Presentation transcript:

A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department of Energy Marty Kraimer, ASD/Controls 23 November 2004 Getting Started With EPICS Lecture Series Writing Record Support

Pioneering Science and Technology Office of Science U.S. Department of Energy Overview  Record Support  Implements a Record Type  Plugs into database common environment  Implementation steps  Prepare a Database Definition (.dbd) file  Create a C source file which implements semantics  Start with existing support!!!  Documentation  App Dev Guide Chapters 5, 6, and 11  makeBaseApp example - xxxRecord  base/src/rec  BUT FIRST: Ask the question Why?  Reasons against a new record type  Reasons for a new record type

Pioneering Science and Technology Office of Science U.S. Department of Energy Reasons Against a New Record Type  Only one STAT, SEVR, VAL  Example: Power Supply Record, i.e. multiple inputs, outputs. What do stat and sevr mean?  Is a template of standard record types a better choice?  No device support  Standard record types have extensive associated device support  No documentation. You should also provide it.  Can be tricky to implement proper semantics  Some standard tools may also need extensions. Example capFast.

Pioneering Science and Technology Office of Science U.S. Department of Energy Reasons For a New Record Type  Sets of standard record types will not satisfy need  Are you really sure? Think hard!!!  State must be shared across multiple records  Example asynRecord – Can dynamically change hardware addressing ✤ I implemented via device support and standard records. Complicated!! ✤ Mark implemented via new record type. Much easier to understand.  Many record instances: Example mbbiDirect record type.  Because it is fun. NOT A GOOD REASON.  Example Event Generator/ Event Receiver Records  APS/SLS/Diamond/PLS – Special Record Types  SNS has different event system. ✤ Question: Modify EG/ER or write device support for standard records? ✤ Answer: Not clear!!! ✢ Very few EG records ✢ At most one ER per IOC ✢ I think SNS decided to use device support for standard record types

Pioneering Science and Technology Office of Science U.S. Department of Energy Implementation: Create DBD.  Create a Database Definition (dbd) File.  Chapter 6 of Application Developer’s Guide.  Syntax recordtype( ) { include “dbCommon.dbd” field(, ) { } field(, ) { }... }

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD Example  Example recordtype(example) { include “dbCommon.dbd” field(PREC,DBF_DOUBLE) { prompt(“Display Precision”) promptGroup(GUI_DISPLAY) } field(VAL,DBF_DOUBLE) }

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD continued  recordtype( ) Should be alphanumeric starting with letter  include “ ”  Must include dbCommon first.  field(, ) { }  Fieldname should be alphanumeric starting with letter  Length is normally limited to four characters ✤ 3.14 allows arbitrary length ✤ May cause problems with some Channel Access clients  In dbd file this should be upper case. It is converted to lower case when the.h file is generated. Bad decision!!

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD – Field Attributes   asl : access security level ✤ ASL1 - Fields seldom modified - default ✤ ASL0 - Fields meant to be modified  initial : initial value  prompt : string for Database Configuration  promptgroup : Should DCT allow field to be configured?  special: Special handling on put ✤ Several values ✤ SPC_MOD, SPC_DBADDR, SPC SPC_NOMOD

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD – Field Attributes continued  (continued)  pp : process passive record on put?  interest : interest level used by dbpr (Database Print Record)  base : DECIMAL (default) or HEX (Only used by dbDumpRecord)  size : For DBF_STRING  extra : For DBF_NOACCESS  menu : For DBF_MENU.

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD - Fieldtypes  DBF_STRING DBF_CHAR DBF_UCHAR DBF_SHORT DBF_USHORT DBF_LONG DBF_ULONG DBF_FLOAT DBF_DOUBLE DBF_ENUM DBF_MENU DBF_DEVICE DBF_INLINK DBF_OUTLINK DBF_FWDLINK DBF_NOACCESS

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD String Field  DBF_STRING fields  Fixed length null terminated strings  Channel access support max of 40 characters  Arrays of character strings are possible  Example field(VAL,DBF_STRING) { size(40) prompt(“value”) promptgroup(GUI_DISPLAY) }

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD Numeric Fields  DBF_CHAR, …, DBF_DOUBLE  Standard C datatypes  All attributes except size, extra, menu meaningful  Arrays  dbd file must define special(SPC_DBADDR)  Record support must implement cvt_dbaddr, get_array_info, put_array_info  No support by Database Configuration Tools.

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD: Enumerated Field  DBF_ENUM  Record Support provides choices and index  See biRecord, mbbiRecord, etc  Actual field type is unsigned short  Record support MUST implement ✤ get_enum_str ✤ put_enum_str ✤ get_enum_strs

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD Menu Field  DBF_MENU menu( ) { choice(,” “) … } … recordtype( ) { field(,DBF_MENU) { menu( ) }

Pioneering Science and Technology Office of Science U.S. Department of Energy Menu Field Example  Example menu(menuYesNo) { choice(menuYesNo,”NO”) choice(menuYesNo,”YES”) } … field(PINI,DBF_MENU) { … menu(menuYesNo) }

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD Device Field  DBF_DEVICE  Database Common Field - DTYP  Related to device definitions  Has associated INP or OUT field  Device Support must be provided  Example field(DTYP,”Soft Channel”) This requires a device definition like: device(ai,CONSTANT,devAiSoft,”Soft Channel”)

Pioneering Science and Technology Office of Science U.S. Department of Energy DBD link Fields  DBF_INLINK, DBF_OUTLINK  Not INP or OUT ✤ Constant link - Just initialization ✤ PV_LINK becomes DB_LINK or CA_LINK  INP or OUT and Device Support ✤ device definitions determine choices ✤ Associated with choice is bus type ✤ Gory details in link.h. Used by device support.  DBF_FWDLINK  references another record which is processed if it is passive.  FLNK ✤ In dbCommon ✤ record support calls recGblFwdLink  Other DBF_FWDLINKs can be defined ✤ Call dbScanFwdLink NOT recGblFwdLink

Pioneering Science and Technology Office of Science U.S. Department of Energy Implementation: Generate include files  Generate.h and.h include file  dbToMenuH generates.h  Code should use generated files instead of hard coding choices ✤ Many standard records written before dbToMenuH existed.  Example menuYesNo.h typedef enum { menuYesNoNO, menuYesNoYES } menuYesNo;

Pioneering Science and Technology Office of Science U.S. Department of Energy Generate Include Files continued  dbToRecordTypeH generates.h  Code MUST use generated files  Include code to compute field sizes, offsets typedef struct aiRecord { charname[29]; … } #define aiRecordNAME 0 … #ifdef GEN_SIZE_OFFSET int aiRecordSizeOffset(dbRecordType *p) { … }  Only record support and associated device support is allowed to use the include files.

Pioneering Science and Technology Office of Science U.S. Department of Energy Implementation: Record Support Module  Provide Execution Semantics  Defined via RSET - Record Support Entry Table /* Create RSET - Record Support Entry Table #define report NULL #define initialize NULL static long init_record(); static long process(); … struct rset RSET = { RSETNUMBER, report, initialize, init_record, process, … };

Pioneering Science and Technology Office of Science U.S. Department of Energy Record Support Methods - Summary  Report, Initialization, Processing  report  initialize  init_record  process

Pioneering Science and Technology Office of Science U.S. Department of Energy Record Support Methods - Summary  Support for Channel/ Database Access  special  cvt_dbaddr  get_array_info  put_array_info  get_units  get_precision  get_enum_str  put_enum_str  get_enum_strs  get_graphic_double  get_control_double  get_alarm_double

Pioneering Science and Technology Office of Science U.S. Department of Energy Record Support Method: Syntax  RSET – Record Support Entry Table  Except for RSETNUMBER just a structure of function pointers.  Similar to JAVA interface or pure virtual C++ class  BUT defined before standard C was available for EPICS  Does NOT use C function prototypes  Sorry!!!!  Perhaps this will change in EPICS version 4.

Pioneering Science and Technology Office of Science U.S. Department of Energy Methods: Report, Initialization, Processing  report(void *precord)  Nothing calls this. Normally not implemented  initialize(void)  Called once before first call to init_record.Not normally needed  init_record(void *precord,int pass)  Normally implemented  Called twice ✤ pass 0 - Can do anything except access other records. For example storage for arrays should be allocated during pass 0. ✤ pass 1 - Finish initialization and also call associated device support initialization  process  VERY IMPORTANT  Implements record semantics

Pioneering Science and Technology Office of Science U.S. Department of Energy init_record example /* assume val is double *val */ typedef struct xxxdset { long number, … DEVSUPFUN init_record; … DEVSUPFUN read; } xxxdset; static long init_record(void *prec, int pass) { xxxarrayRecord *paf = (xxxarrayRecord *)prec; xxxdest *pdset = (xxxdset *)paf->dset; if(pass==0) { if(paf->nelm nelm = 1; paf->val = (double *)calloc(paf->nelm,sizeof(double)); return(0); } /* Must have dset defined */ if(!pdset !! (pdset->number read ) { epicsPrintf(“%s no or invalid dset\n”,paf->name); return(0); } (*pdset->init_record)(paf); return(0); }

Pioneering Science and Technology Office of Science U.S. Department of Energy process overview  dbAccess:dbProcess calls process if  Decision was made to process the record  Record not active ( PACT FALSE )  Record is enabled ( DISV !=DISA )  process with device support must  set record active ( PACT TRUE )  Perform I/O  Check for record specific alarms  Raise database monitors  Request processing of forward links  Set PACT FALSE and return

Pioneering Science and Technology Office of Science U.S. Department of Energy process overview continued  For asynchronous devices.  Asynchronous start ✤ Initiate I/O. ✤ Determine a method for calling process when operation completes ✤ Return leaving PACT TRUE.  Asynchronous completion ✤ Call process as follows: dbScanLock(precord); *(prset->process)(precord); dbScanUnlock(precord); ✤ process completes record processing ✢ Complete I/O ✢ Check for record specific alarms ✢ Raise database monitors ✢ Request processing of forward links ✢ Set PACT FALSE ✢ return

Pioneering Science and Technology Office of Science U.S. Department of Energy process example static long process(void *prec, int pass) { xxxarrayRecord *paf = (xxxarrayRecord *)prec; xxxdest *pdset = (xxxdset *)paf->dset; unsigned char pact = paf->pact; unsigned short monitor_mask; /* Must have dset defined */ if(!pdset !! (pdset->number read ) { /*set pact true so process will not be called*/ paf->pact = TRUE; return(0); } (*pdset->read)(paf); /*return if beginning of asyn processing */ if(!pact && paf->pact) return(0); paf->pact = TRUE; alarm(paf); /*sample monitor code */ monitor_mask = recGblResetAlarms(paf); monitor_mask |= (DBE_LOG|DBE_VALUE) db_post_events(paf,paf->val,monitor_mask); recGblFwdLink(paf); paf->pact = FALSE return(0); }

Pioneering Science and Technology Office of Science U.S. Department of Energy alarm and monitors  alarms  recGblSetSevr(void *prec,, )  Status and severity values defined in alarm.h  Must prevent alarm storms on numeric values ✤ value fluctuating around alarm limit ✤ See Application Developer’s guide for algorithm  process must call recGblResetAlarms after all alarms have been raised and before calling recGblFwdLink. Also, if possible, before raising monitors.  monitors  db_post_event(void *prec,void *pfield, monitor_mask)  Call for all fields that change as a result of record processing  Support value change hysteresis when possible.  Look at aiRecord for an example

Pioneering Science and Technology Office of Science U.S. Department of Energy Routines with a DBADDR argument  Called by database/channel access  Call dbGetFieldIndex to find out which field. int fieldIndex; fieldIndex = dbGetFieldIndex(pdbaddr); if(fieldIndex == aiRecordVAL)...  DBADDR typedef struct dbAddr{ dbCommon *precord; void *pfield; void *pfldDes; void *asPvt; long no_elements; short field_type; short field_size; short special; short dbr_field_type; }DBADDR;

Pioneering Science and Technology Office of Science U.S. Department of Energy Record Support Routines - Cont.  special(DBADDR *pdbaddr,int after)  Called if special defined in dbd file  Called before and after field is modified.  dbGetFieldIndex(pdbaddr)  pdbaddr->special ✤ The special type as defined in.dbd file. USE SPC_MOD. ✤ Must include file special.h  cvt_dbaddr(DBADDR *pdbaddr)  Called by database library when DB or CA connects to field.  Called if special(SPC_DBADDR) specified  Following fields of DBADDR can be changed no_elements field_type field_size special dbr_type

Pioneering Science and Technology Office of Science U.S. Department of Energy Record Support Routines - Cont.  Array Routines  Called if cvt_dbaddr sets no_elements > 1  get_array_info(DBADDR *pdbaddr, long *no_elements, long *offset) ✤ Called when database access gets an array ✤ Must set no_elements ✤ Can set offset if field is circular buffer  put_array_info( DBADDR *pdbaddr,long nNew) Called after database access has written array

Pioneering Science and Technology Office of Science U.S. Department of Energy Record Support Routines - Cont.  Units/Precision  get_units(DBADDR *pdbaddr, char *punits) CA has MAX_UNITS_SIZE 8  get_precision(DBADDR *pdbaddr, long *precision) Problems with only precision.  Enumerated Values  get_enum_str(DBADDR *pdbaddr,char *p)  put_enum_str(DBADDR *pdbaddr,char *p)  get_enum_strs(DBADDR *pdbaddr,dbr_enumStrs *p) CA has limit of 16 choices, 26 characters in each choice  Graphic/ Control/ Alarm Limits  get_graphic_double(DBADDR *pdbaddr,struct dbr_grDouble *p)  get_control_double(DBADDR *pdbaddr,struct dbr_ctrlDouble *p)  get_alarm_double(DBADDR *pdbaddr,struct dbr_alDouble *p)

Pioneering Science and Technology Office of Science U.S. Department of Energy Global Record Support Routines  All start with recGbl  Intended for record/device support but also called by other code  Reporting Errors Deprecated - Use errlogPrintf instead  Alarm Processing  recGblSetSevr(void *precord, short newstat, short newsevr)  recGblResetAlarms(void *precord);  Limits  recGblGetGraphicDouble, recGblGetControlDouble, etc.  Defaults for fields record support doesn’t know how to handle  Channel Access client often not happy  Graphics, Control, Alarm limits  recGblInitConstantLink For use on link fields with a constant value. Only works on numeric values!!

Pioneering Science and Technology Office of Science U.S. Department of Energy Global Record Support Routines continued  recGblGetTimeStamp record support should call this each time record completes processing.  recGblFwdLink Must be called with pact true and all other processing complete

Pioneering Science and Technology Office of Science U.S. Department of Energy Database Access Routines for Record Support  When in context of process use dbGetLink, dbPutLink  Link information  dbGetPdbAddrFromLink gets address of DBADDR.  dbGetRset gets address of Record Support Entry table  dbIsLinkConnected Is link connected?