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 2021 <2022> 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 2021 <2022> 2023 2024 |
<== Date ==> | <== Thread ==> |
---|
Subject: | Understanding EPICS DSET-based driver |
From: | Abdalla Ahmad via Tech-talk <tech-talk at aps.anl.gov> |
To: | "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov> |
Date: | Sun, 2 Oct 2022 10:29:16 +0000 |
Hi I am trying to write an EPICS driver by using the device support model explained in the app developer guide. I attached a preliminary code for the ai record which only increments the record’s value by a value passed in the INP field. My
question is, for the read_ai function I had to return 2 in order for the driver to work, otherwise the record’s value will not change. Why is that? In page 192 of the developer guide, return 2 means do not convert, what does it mean in this case? Also, is
implementing a callback to process the record necessary? Or can I lock/unlock the record directly in the read_ai function? Thanks! Abdalla. |
#include <stdio.h> #include <string.h> #include <stdbool.h> #include <stdlib.h> #include <callback.h> #include <aiRecord.h> #include <recSup.h> #include <devSup.h> #include <dbAccess.h> #include <epicsExport.h> static int increment_value; static long init_record(struct aiRecord* record) { if(record->inp.type != INST_IO) { printf("Invalid record type\n"); return -1; } printf("INP: %s\n", record->inp.value.instio.string); char* token = strtok(record->inp.value.instio.string, " "); if(token == NULL) { printf("Invalid INP string"); return -2; } token = strtok(NULL, " "); increment_value = atoi(token); record->dpvt = (void*) &increment_value; return 0; } static long read_ai(struct aiRecord* record) { int* value = (int*) record->dpvt; if(record->pact) { record->val = record->val + *value; record->udf = false; printf("Completed processing. Value %f\n\n", record->val); return 2; } record->pact = true; dbScanLock((struct dbCommon*) record); (record->rset->process)(record); dbScanUnlock((struct dbCommon*) record); return 2; } struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioinit_info; DEVSUPFUN io; DEVSUPFUN misc; } devai = { 6, NULL, NULL, init_record, NULL, read_ai, NULL }; epicsExportAddress(dset, devai);