泉州網(wǎng)站制作專業(yè)產(chǎn)品怎么做市場推廣
以下詳細(xì)描述了一個(gè)longin記錄設(shè)備支持模塊編寫過程以及用于測試這個(gè)模塊的IOC的操作步驟:
1)創(chuàng)建一個(gè)目錄lidriver用于保存這個(gè)IOC目錄結(jié)構(gòu):
orangepi@orangepi4-lts:~/epics$ mkdir lidriver
orangepi@orangepi4-lts:~/epics$ ls
example lidriver
2) 進(jìn)入上一步創(chuàng)建的目錄,并且使用makeBaseApp.pl腳本創(chuàng)建這個(gè)IOC應(yīng)用程序目錄結(jié)構(gòu)和啟動(dòng)目錄:
orangepi@orangepi4-lts:~/epics/lidriver$ makeBaseApp.pl -t ioc lidriver
orangepi@orangepi4-lts:~/epics/lidriver$ makeBaseApp.pl -i -t ioc lidriver
Using target architecture linux-aarch64 (only one available)
The following applications are available:lidriver
What application should the IOC(s) boot?
The default uses the IOC's name, even if not listed above.
Application name?
orangepi@orangepi4-lts:~/epics/lidriver$ ls
configure iocBoot lidriverApp Makefile
3) 進(jìn)入lidriverApp/src目錄,編寫設(shè)備支持源文件以及對應(yīng)的支持文件,并且編輯對應(yīng)目錄下的Makefile文件:
a) devLiRnd.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>#include "alarm.h"
#include "dbDefs.h"
#include "dbAccess.h"
#include "recGbl.h"
#include "devSup.h"
#include "longinRecord.h"
#include "epicsExport.h"typedef struct devData{int upper_limit;int lower_limit;
}devData;static int lirand(devData * data)
{int ret;int mid = data->upper_limit - data->lower_limit + 1;ret = rand() % mid + data->lower_limit;return ret;
}
/* Create the dset for devLiRnd */
static long init_record(dbCommon *pcommon);
static long read_longin(longinRecord *prec);longindset devLiRnd = {{5, NULL, NULL, init_record, NULL},read_longin
};
epicsExportAddress(dset, devLiRnd);static long init_record(dbCommon *pcommon)
{longinRecord *prec = (longinRecord *)pcommon;devData * data;if (prec->inp.type != CONSTANT){recGblRecordError(S_db_badField, prec, "devLiRnd(init_record)illegal INP INP field");return S_db_badField;}data =(devData *)malloc(sizeof(devData));if (fabs(prec->hihi) < 1e-5){data->upper_limit = 100;}else{data->upper_limit = (int) prec->hihi;}if (fabs(prec->lolo) < 1e-5){data->lower_limit = 0;}else{data->lower_limit = (int)prec->lolo;}srand((unsigned int)time(NULL));prec->dpvt = (void *)data;return 0;
}static long readLocked(struct link *pinp, void *dummy)
{longinRecord *prec = (longinRecord *) pinp->precord;long status = 0;devData * data =(devData *) prec->dpvt;prec->val = lirand(data);if (dbLinkIsConstant(&prec->tsel) &&prec->tse == epicsTimeEventDeviceTime)dbGetTimeStamp(pinp, &prec->time);return status;
}static long read_longin(longinRecord *prec)
{long status = dbLinkDoLocked(&prec->inp, readLocked, NULL);if (status == S_db_noLSET)status = readLocked(&prec->inp, NULL);return status;
}
b) devLiRnd.dbd
device(longin, CONSTANT, devLiRnd, "random")
c) 將以上兩個(gè)文件名添加到相同目錄下的Makefile文件中:
...lidriver_DBD += devLiRnd.dbdlidriver_SRCS += devLiRnd.c...
4)在idriverApp/Db文件下,增加一個(gè)數(shù)據(jù)庫實(shí)例文件longintest.db,并且編輯此路徑下的Makefile文件:
a)longintest.db
record(longin, "$(P):LiRandom1")
{field(DESC, "Random Test")field(DTYP, "random")field(INP, "1")field(HIHI, "50")field(LOLO, "0")field(SCAN, "1 second")
}record(longin, "$(P):LiRandom2")
{field(DESC, "Random Test")field(DTYP, "random")field(INP, "1")field(HIHI, "100")field(LOLO, "51")field(SCAN, "1 second")
}
b) 將上面的文件名添加到Makefile中:
DB += longintest.db
5) 回到這個(gè)IOC的頂層目錄lidriver ,執(zhí)行make進(jìn)行編譯。
6)進(jìn)入啟動(dòng)目錄iocBoot/ioclidriver,編譯啟動(dòng)腳本st.cmd:
#!../../bin/linux-aarch64/lidriver#- You may have to change lidriver to something else
#- everywhere it appears in this file< envPathscd "${TOP}"## Register all support components
dbLoadDatabase "dbd/lidriver.dbd"
lidriver_registerRecordDeviceDriver pdbbase## Load record instances
dbLoadRecords("db/longintest.db","P=Test")cd "${TOP}/iocBoot/${IOC}"
iocInit
7)啟動(dòng)這個(gè)IOC,用dbl查看加載的記錄實(shí)例:
orangepi@orangepi5:/usr/local/EPICS/program/lidriver/iocBoot/ioclidriver$ ../../bin/linux-aarch64/lidriver st.cmd
#!../../bin/linux-aarch64/lidriver
< envPaths
...
############################################################################
iocRun: All initialization complete
## Start any sequence programs
#seq sncxxx,"user=orangepi"
epics> dbl
Test:LiRandom1
Test:LiRandom2
epics>
8) 用通道訪問命令camonitor查看以上兩個(gè)記錄實(shí)例的值:
orangepi@orangepi4-lts:~$ camonitor Test:LiRandom1 Test:LiRandom2
Test:LiRandom1 2023-08-28 11:15:43.229290 32
Test:LiRandom2 2023-08-28 11:15:43.229302 61
Test:LiRandom1 2023-08-28 11:15:44.229311 6
Test:LiRandom2 2023-08-28 11:15:44.229398 57
Test:LiRandom1 2023-08-28 11:15:45.229424 13
Test:LiRandom2 2023-08-28 11:15:45.229458 75
....
實(shí)錄實(shí)例Test:LiRandom1和Test:LiRandom2的值每秒鐘隨機(jī)變化一次,Test:LiRandom1的變化范圍在0~50,而Test:LiRandom2的變化范圍為51-100。