| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005 |
- //***************************************************************************************
- //
- //! \file advio.h
- //! IO deiver for ECU series prodeuct.
- //!
- //! \version V1.0
- //! \date 2024
- //
- //***************************************************************************************
- #ifndef _ADVIO_H_
- #define _ADVIO_H_
- #include <stdio.h>
- #include <stdint.h>
- #include <stdbool.h>
- #include <dlfcn.h>
- #undef LOG_DOMAIN
- #undef LOG_TAG
- #define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域
- #define LOG_TAG "MY_TAG"
- #include "hilog/log.h"
- #ifndef WIN_TYPE_DEF
- #define WIN_TYPE_DEF
- typedef char WCHAR;
- typedef void *HMODULE;
- typedef void *HANDLE;
- typedef bool BOOL;
- typedef char BYTE;
- typedef HANDLE HINSTANCE;
- #endif
- #define DLL_FILE_NAME "libadvio.so"
- #define AI_CALI_TYPE_ZERO 0X55
- #define AI_CALI_TYPE_SPAN 0Xaa
- #define AI_CALI_TYPE_MIX 0X5a
- #define CAL_FLASH 0x01
- #define _USER_FACTORY 0X02
- #define CAL_FACTORY_USER 0x03
- /** range value of 0~20mA. */
- #define RANGE_CODE_I_0_P20 0x0182
- /** range value of 4~20mA. */
- #define RANGE_CODE_I_4_P20 0x0180
- /** range value of -2.5V~2.5V. */
- #define RANGE_CODE_V_N2P5_P2P5 0x0141
- /** range value of -10V~10V. */
- #define RANGE_CODE_V_N10_P10 0x0143
- /** range value of 0V~10V. */
- #define RANGE_CODE_V_0_P10 0x0149
- enum DO_INIT_VALUE_TYPE { DO_INIT_DOVALUE_TYPE = 0, DO_INIT_RESERVED };
- #pragma pack(1)
- /** module information data struct */
- typedef struct tagSPISearchDeviceAck {
- /** firmware working mode. 0: download mode 1 : application mode */
- uint8_t uModuleMode;
- /** module name */
- uint8_t ucModuleName[10];
- /** firmware version */
- uint32_t ulModuleVersion;
- /** channel number of AI */
- uint8_t ucAINum;
- /** channel number of AO */
- uint8_t ucAONum;
- /** channel number of DI */
- uint8_t ucDINum;
- /** channel number of DO */
- uint8_t ucDONum;
- /** reserved */
- uint32_t ulresv;
- } SPISearchDev, *PSPISearchDev;
- typedef struct _CMD_LOCATION {
- int head;
- int tail;
- } CMD_LOCATION, *PCMD_LOCATION;
- #pragma pack()
- typedef enum tagErrorCode {
- /// <summary>
- /// The operation is completed successfully.
- /// </summary>
- Success = 0,
- ///************************************************************************
- /// warning
- ///************************************************************************
- /// <summary>
- /// The interrupt resource is not available.
- /// </summary>
- WarningIntrNotAvailable = 0xA0000000,
- /// <summary>
- /// The parameter is out of the range.
- /// </summary>
- WarningParamOutOfRange = 0xA0000001,
- /// <summary>
- /// The property value is out of range.
- /// </summary>
- WarningPropValueOutOfRange = 0xA0000002,
- /// <summary>
- /// The property value is not supported.
- /// </summary>
- WarningPropValueNotSpted = 0xA0000003,
- /// <summary>
- /// The property value conflicts with the current state.
- /// </summary>
- WarningPropValueConflict = 0xA0000004,
- ///***********************************************************************
- /// error
- ///***********************************************************************
- /// <summary>
- /// The handle is NULL or its type doesn't match the required operation.
- /// </summary>
- ErrorHandleNotValid = 0xE0000000,
- /// <summary>
- /// The parameter value is out of range.
- /// </summary>
- ErrorParamOutOfRange = 0xE0000001,
- /// <summary>
- /// The parameter value is not supported.
- /// </summary>
- ErrorParamNotSpted = 0xE0000002,
- /// <summary>
- /// The parameter value format is not the expected.
- /// </summary>
- ErrorParamFmtUnexpted = 0xE0000003,
- /// <summary>
- /// Not enough memory is available to complete the operation.
- /// </summary>
- ErrorMemoryNotEnough = 0xE0000004,
- /// <summary>
- /// The data buffer is null.
- /// </summary>
- ErrorBufferIsNull = 0xE0000005,
- /// <summary>
- /// The data buffer is too small for the operation.
- /// </summary>
- ErrorBufferTooSmall = 0xE0000006,
- /// <summary>
- /// The data length exceeded the limitation.
- /// </summary>
- ErrorDataLenExceedLimit = 0xE0000007,
- /// <summary>
- /// The required function is not supported.
- /// </summary>
- ErrorFuncNotSpted = 0xE0000008,
- /// <summary>
- /// The required event is not supported.
- /// </summary>
- ErrorEventNotSpted = 0xE0000009,
- /// <summary>
- /// The required property is not supported.
- /// </summary>
- ErrorPropNotSpted = 0xE000000A,
- /// <summary>
- /// The required property is read-only.
- /// </summary>
- ErrorPropReadOnly = 0xE000000B,
- /// <summary>
- /// The specified property value conflicts with the current state.
- /// </summary>
- ErrorPropValueConflict = 0xE000000C,
- /// <summary>
- /// The specified property value is out of range.
- /// </summary>
- ErrorPropValueOutOfRange = 0xE000000D,
- /// <summary>
- /// The specified property value is not supported.
- /// </summary>
- ErrorPropValueNotSpted = 0xE000000E,
- /// <summary>
- /// The handle hasn't own the privilege of the operation the user wanted.
- /// </summary>
- ErrorPrivilegeNotHeld = 0xE000000F,
- /// <summary>
- /// The required privilege is not available because someone else had own it.
- /// </summary>
- ErrorPrivilegeNotAvailable = 0xE0000010,
- /// <summary>
- /// The driver of specified device was not found.
- /// </summary>
- ErrorDriverNotFound = 0xE0000011,
- /// <summary>
- /// The driver version of the specified device mismatched.
- /// </summary>
- ErrorDriverVerMismatch = 0xE0000012,
- /// <summary>
- /// The loaded driver count exceeded the limitation.
- /// </summary>
- ErrorDriverCountExceedLimit = 0xE0000013,
- /// <summary>
- /// The device is not opened.
- /// </summary>
- ErrorDeviceNotOpened = 0xE0000014,
- /// <summary>
- /// The required device does not exist.
- /// </summary>
- ErrorDeviceNotExist = 0xE0000015,
- /// <summary>
- /// The required device is unrecognized by driver.
- /// </summary>
- ErrorDeviceUnrecognized = 0xE0000016,
- /// <summary>
- /// The configuration data of the specified device is lost or unavailable.
- /// </summary>
- ErrorConfigDataLost = 0xE0000017,
- /// <summary>
- /// The function is not initialized and can't be started.
- /// </summary>
- ErrorFuncNotInited = 0xE0000018,
- /// <summary>
- /// The function is busy.
- /// </summary>
- ErrorFuncBusy = 0xE0000019,
- /// <summary>
- /// The interrupt resource is not available.
- /// </summary>
- ErrorIntrNotAvailable = 0xE000001A,
- /// <summary>
- /// The DMA channel is not available.
- /// </summary>
- ErrorDmaNotAvailable = 0xE000001B,
- /// <summary>
- /// Time out when reading/writing the device.
- /// </summary>
- ErrorDeviceIoTimeOut = 0xE000001C,
- /// <summary>
- /// The given signature does not match with the device current one.
- /// </summary>
- ErrorSignatureNotMatch = 0xE000001D,
- /// <summary>
- /// The given configure does not match with the device current one.
- /// </summary>
- ErrorConfigNotRight = 0xE0000020,
- /// <summary>
- /// Undefined error
- /// </summary>
- ErrorUndefined = 0xE000FFFF,
- } ErrorCode;
- typedef ErrorCode (*PFNIODEVINIT)(void);
- typedef ErrorCode (*PFNIODEVCLOSE)(void);
- typedef ErrorCode (*PFNGETSPIDEVHANDLE)(int *);
- typedef ErrorCode (*PFNSPIPROTOIO)(int, uint8_t *, uint8_t, uint8_t *, uint8_t *, uint8_t);
- typedef ErrorCode (*PFNGETDEVINFO)(PSPISearchDev);
- typedef ErrorCode (*PFNGETADDEVINFO)(char *, char *);
- typedef unsigned char (*PFNCONSTRUCTSPIPACKAGE)(unsigned char, unsigned char, unsigned char, unsigned char *,
- unsigned char, unsigned char *);
- typedef ErrorCode (*PFNGETAIRANGECODE)(unsigned char, unsigned char, unsigned char *);
- typedef ErrorCode (*PFNSETAIRANGECODE)(unsigned char, unsigned char, unsigned char *);
- typedef ErrorCode (*PFNAIREAD)(unsigned char, unsigned char, unsigned char *);
- typedef ErrorCode (*PFNAICAILIBRATE)(unsigned char, unsigned char);
- typedef ErrorCode (*PFNAICALIBRATEFLASH)(unsigned char);
- typedef ErrorCode (*PFNSETAIINTERGRATION)(uint8_t);
- typedef ErrorCode (*PFNGETAIINTERGRATION)(uint8_t *);
- typedef ErrorCode (*PFNDOREAD)(unsigned int *);
- typedef ErrorCode (*PFNDOWRITEONECHANNEL)(unsigned int, unsigned int);
- typedef ErrorCode (*PFNDOWRITEALL)(unsigned int);
- typedef ErrorCode (*PFNDIREAD)(unsigned int *);
- typedef ErrorCode (*PFNGETDRVVERSION)(uint32_t *);
- // typedef ErrorCode (* PFNDOINITVALUEGET)(unsigned int, unsigned int*);
- // typedef ErrorCode (* PFNDOINITVALUESET)(unsigned int, unsigned int);
- typedef ErrorCode (*PFNACCESSDOINITVALUE)(uint32_t, uint32_t, uint32_t, void *, uint32_t);
- typedef struct _BAdvIOLib {
- HMODULE instHandle;
- PFNIODEVINIT pfnIODevInit;
- PFNIODEVCLOSE pfnIODevClose;
- PFNGETSPIDEVHANDLE pfnGetSPIDevHandle;
- PFNSPIPROTOIO pfnSPIProtoIO;
- PFNGETDEVINFO pfnGetDevInfo;
- PFNGETADDEVINFO pfnGetADDevInfo;
- PFNCONSTRUCTSPIPACKAGE pfnConstructSPIPackage;
- PFNGETAIRANGECODE pfnGetAIRangeCode;
- PFNSETAIRANGECODE pfnSetAIRangeCode;
- PFNAIREAD pfnAIRead;
- PFNAICAILIBRATE pfnAICalibrate;
- PFNAICALIBRATEFLASH pfnAICalibrateFlash;
- PFNSETAIINTERGRATION pfnSetAIIntergration;
- PFNGETAIINTERGRATION pfnGetAIIntergration;
- PFNDOREAD pfnDORead;
- PFNDOWRITEONECHANNEL pfnDOWriteOneChannel;
- PFNDOWRITEALL pfnDOWriteAll;
- PFNDIREAD pfnDIRead;
- PFNGETDRVVERSION pfnGetDrvVersion;
- // PFNDOINITVALUEGET pfnDoInitValueGet;
- // PFNDOINITVALUESET pfnDoInitValueSet;
- PFNACCESSDOINITVALUE pfnAccessDoinitValue;
- } BAdvIOLib, *PBAdvIOLib;
- static inline BAdvIOLib *GetBDaqLib(void) {
- static BAdvIOLib badvioLib;
- return &badvioLib;
- }
- static inline BOOL InitializeAdvIOLibray(BAdvIOLib *badviolib) {
- if (badviolib->instHandle == NULL) {
- if ((badviolib->instHandle = dlopen(DLL_FILE_NAME, RTLD_LAZY)) != NULL) {
- badviolib->pfnIODevInit = (PFNIODEVINIT)dlsym(badviolib->instHandle, "IODevInit");
- badviolib->pfnIODevClose = (PFNIODEVCLOSE)dlsym(badviolib->instHandle, "IODevClose");
- badviolib->pfnGetSPIDevHandle = (PFNGETSPIDEVHANDLE)dlsym(badviolib->instHandle, "GetSPIDevHandle");
- badviolib->pfnSPIProtoIO = (PFNSPIPROTOIO)dlsym(badviolib->instHandle, "SPIProtoIO");
- badviolib->pfnGetDevInfo = (PFNGETDEVINFO)dlsym(badviolib->instHandle, "GetDevInfo");
- badviolib->pfnGetADDevInfo = (PFNGETADDEVINFO)dlsym(badviolib->instHandle, "GetADDevInfo");
- badviolib->pfnConstructSPIPackage =
- (PFNCONSTRUCTSPIPACKAGE)dlsym(badviolib->instHandle, "ConstructSPIPackage");
- badviolib->pfnGetAIRangeCode = (PFNGETAIRANGECODE)dlsym(badviolib->instHandle, "GetAIRangeCode");
- badviolib->pfnSetAIRangeCode = (PFNSETAIRANGECODE)dlsym(badviolib->instHandle, "SetAIRangeCode");
- badviolib->pfnAIRead = (PFNAIREAD)dlsym(badviolib->instHandle, "AIRead");
- badviolib->pfnAICalibrate = (PFNAICAILIBRATE)dlsym(badviolib->instHandle, "AICalibrate");
- badviolib->pfnAICalibrateFlash = (PFNAICALIBRATEFLASH)dlsym(badviolib->instHandle, "AICalibrateFlash");
- badviolib->pfnSetAIIntergration = (PFNSETAIINTERGRATION)dlsym(badviolib->instHandle, "SetAIIntergration");
- badviolib->pfnGetAIIntergration = (PFNGETAIINTERGRATION)dlsym(badviolib->instHandle, "GetAIIntergration");
- // badviolib->pfnFormatSPICMDPackage = (PFNFORMATSPICMDPACKAGE)dlsym(badviolib->instHandle,
- // "FormatSPICMDPackage");
- badviolib->pfnDORead = (PFNDOREAD)dlsym(badviolib->instHandle, "DORead");
- badviolib->pfnDOWriteOneChannel = (PFNDOWRITEONECHANNEL)dlsym(badviolib->instHandle, "DOWriteOneChannel");
- badviolib->pfnDOWriteAll = (PFNDOWRITEALL)dlsym(badviolib->instHandle, "DOWriteAll");
- badviolib->pfnDIRead = (PFNDIREAD)dlsym(badviolib->instHandle, "DIRead");
- badviolib->pfnGetDrvVersion = (PFNGETDRVVERSION)dlsym(badviolib->instHandle, "GetDrvVersion");
- // badviolib->pfnDoInitValueGet = (PFNDOINITVALUEGET)dlsym(badviolib->instHandle, "DOInitValueGet");
- // badviolib->pfnDoInitValueSet = (PFNDOINITVALUESET)dlsym(badviolib->instHandle, "DOInitValueSet");
- badviolib->pfnAccessDoinitValue = (PFNACCESSDOINITVALUE)dlsym(badviolib->instHandle, "AccessDoInitValue");
- }
- }
- return badviolib->instHandle != NULL;
- }
- /*!*************************************************************************
- * \brief
- * Initialize the AdvIO device.
- *
- * \details
- * This function must be called before any other AdvIO functions.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevInit(void) {
- if (InitializeAdvIOLibray(GetBDaqLib())) {
- if (GetBDaqLib()->pfnIODevInit) {
- return GetBDaqLib()->pfnIODevInit();
- } else {
-
- return ErrorHandleNotValid;
- }
- }
-
- return ErrorUndefined;
- }
- /*!*************************************************************************
- * \brief
- * De-initialize the Advio device
- *
- * \details
- *
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevClose(void) {
- if (GetBDaqLib()->pfnIODevClose) {
- return GetBDaqLib()->pfnIODevClose();
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Get SPI Interface Handle.
- *
- * \details
- *
- * \param[out] phdl
- * Handle of the SPI Interface.
- *
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioGetSPIDevHandle(int *phdl) {
- if (GetBDaqLib()->pfnGetSPIDevHandle) {
- return GetBDaqLib()->pfnGetSPIDevHandle(phdl);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * perform a SPI data exchange.
- *
- * \details
- *
- * \param[in] dev_hdl
- * Handle of the SPI Interface.
- *
- * \param[in] pinbuf
- * input data buffer.
- *
- * \param[in] inlen
- * number of input data.
- *
- * \param[out] poutbuf
- * output data buffer.
- *
- * \param[out] poutlen
- * number of output data.
- *
- * \param[in] printflag
- * flag display date or not.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioSPIProtoIO(int dev_hdl, uint8_t *pinbuf, uint8_t inlen, uint8_t *poutbuf, uint8_t *poutlen,
- uint8_t printflag) {
- if (GetBDaqLib()->pfnSPIProtoIO) {
- return GetBDaqLib()->pfnSPIProtoIO(dev_hdl, pinbuf, inlen, poutbuf, poutlen, printflag);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Get IO module infomation.
- *
- * \details
- *
- *
- * \param[out] pdevinfo
- * pointer of module infomation data struct.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevGetDevInfo(PSPISearchDev pdevinfo) {
- if (GetBDaqLib()->pfnGetDevInfo) {
- return GetBDaqLib()->pfnGetDevInfo(pdevinfo);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Get AD module infomation.
- *
- * \details
- *
- *
- * \param[out] pname
- * ad module name.
- *
- * \param[out] pinfo
- * ad module firmware version.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevGetADDevInfo(char *pname, char *pinfo) {
- if (GetBDaqLib()->pfnGetADDevInfo) {
- return GetBDaqLib()->pfnGetADDevInfo(pname, pinfo);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Contruct a spi protocal data package.
- *
- * \details
- *
- *
- * \param[in] id
- * index of module.
- *
- * \param[in] direction
- * get data or set data.
- *
- * \param[in] command_id
- * spi command index.
- *
- * \param[in] pbufsrc
- * the rest input data buffer.
- *
- * \param[in] buflen
- * input data buffer lenght.
- *
- * \param[out] pbufdst
- * input data buffer.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevConstructSPIPackage(unsigned char id, unsigned char direction, unsigned char command_id,
- unsigned char *pbufsrc, unsigned char buflen,
- unsigned char *pbufdst) {
- if (GetBDaqLib()->pfnConstructSPIPackage) {
- return (ErrorCode)(GetBDaqLib()->pfnConstructSPIPackage(id, direction, command_id, pbufsrc, buflen, pbufdst));
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Get AI range code.
- *
- * \details
- *
- *
- * \param[in] startch
- * The number of the first data channel index you want to get.
- *
- * \param[in] stopch
- * The number of the last data channel index you want to get.
- *
- * \param[out] poutbuf
- * range code data output buffer, two byte per channel.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevGetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) {
- if (GetBDaqLib()->pfnGetAIRangeCode) {
- return GetBDaqLib()->pfnGetAIRangeCode(startch, stopch, poutbuf);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Set AI range code.
- *
- * \details
- *
- *
- * \param[in] startch
- * The number of the first data channel index you want to set.
- *
- * \param[in] stopch
- * The number of the last data channel index you want to set.
- *
- * \param[in] poutbuf
- * range code data input buffer, two byte per channel.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevSetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) {
- if (GetBDaqLib()->pfnSetAIRangeCode) {
- return GetBDaqLib()->pfnSetAIRangeCode(startch, stopch, poutbuf);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * AI calibrate action.
- *
- * \details
- *
- *
- * \param[in] chan
- * The number of the data channel index you want to calibrate.
- *
- * \param[in] calitype
- * calibrate type, zero calibrate or range calibrate.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevAICalibrate(unsigned char chan, unsigned char calitype) {
- if (GetBDaqLib()->pfnAICalibrate) {
- return GetBDaqLib()->pfnAICalibrate(chan, calitype);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * store calibrate data into flash.
- *
- * \details
- *
- *
- * \param[in] act_type
- * action type, to user flash or factory flash.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevAICalibrateFlash(unsigned char act_type) {
- if (GetBDaqLib()->pfnAICalibrateFlash) {
- return GetBDaqLib()->pfnAICalibrateFlash(act_type);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Sinc3 decimation factor setting.
- *
- * \details
- *
- *
- * \param[in] flag
- * Sinc3 decimation factor, 0:60Hz, 1:50Hz.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevSetAIIntergration(uint8_t flag) {
- if (GetBDaqLib()->pfnSetAIIntergration) {
- return GetBDaqLib()->pfnSetAIIntergration(flag);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * get Sinc3 decimation factor.
- *
- * \details
- *
- *
- * \param[out] pflag
- * Sinc3 decimation factor, 0:60Hz, 1:50Hz.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevGetAIIntergration(uint8_t *pflag) {
- if (GetBDaqLib()->pfnGetAIIntergration) {
- return GetBDaqLib()->pfnGetAIIntergration(pflag);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Obtain the results of AI.
- *
- * \details
- *
- *
- * \param[in] startch
- * The number of the first data channel index you want to set.
- *
- * \param[in] stopch
- * The number of the last data channel index you want to set.
- *
- * \param[out] poutbuf
- * AI data output buffer, two byte per channel.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevAIRead(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) {
- if (GetBDaqLib()->pfnAIRead) {
- return GetBDaqLib()->pfnAIRead(startch, stopch, poutbuf);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Obtain the current state of do.
- *
- * \details
- *
- *
- * \param[out] dovalue
- * do state of all channel, one bit corresponds to one do channel.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevDORead(unsigned int *dovalue) {
- if (GetBDaqLib()->pfnDORead) {
- return GetBDaqLib()->pfnDORead(dovalue);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Write the DO value of a channel.
- *
- * \details
- *
- *
- * \param[in] index
- * do channel index.
- *
- * \param[in] value
- * do value be setting.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevDOWriteOneChannel(unsigned int index, unsigned int value) {
- if (GetBDaqLib()->pfnDOWriteOneChannel) {
- return GetBDaqLib()->pfnDOWriteOneChannel(index, value);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Write the DO value of all channel.
- *
- * \details
- *
- *
- * \param[in] value
- * do value be setting, one bit corresponds to one do channel.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevDOWriteAll(unsigned int value) {
- if (GetBDaqLib()->pfnDOWriteAll) {
- return GetBDaqLib()->pfnDOWriteAll(value);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Obtain the current state of di.
- *
- * \details
- *
- *
- * \param[out] divalue
- * di state of all channel, one bit corresponds to one di channel.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevDIRead(unsigned int *divalue) {
- if (GetBDaqLib()->pfnDIRead) {
- return GetBDaqLib()->pfnDIRead(divalue);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- // /*!*************************************************************************
- // * \brief
- // * Obtain the do init value.
- // *
- // * \details
- // *
- // *
- // * \param[in] index
- // * do channel index.
- // *
- // * \param[out] pvalue
- // * do init value.
- // *
- // * \return
- // * result, 0 if successful.
- // *
- // ***************************************************************************/
- // static inline ErrorCode AdvioDevDoInitValueGet(unsigned int index, unsigned int* pvalue)
- // {
- // return GetBDaqLib()->pfnDoInitValueGet(index, pvalue);
- // }
- // /*!*************************************************************************
- // * \brief
- // * Obtain the do init value.
- // *
- // * \details
- // *
- // *
- // * \param[in] index
- // * do channel index.
- // *
- // * \param[in] value
- // * do init value.
- // *
- // * \return
- // * result, 0 if successful.
- // *
- // ***************************************************************************/
- // static inline ErrorCode AdvioDevDoInitValueSet(unsigned int index, unsigned int value)
- // {
- // return GetBDaqLib()->pfnDoInitValueSet(index, value);
- // }
- /*!*************************************************************************
- * \brief
- * Obtain the io driver version.
- *
- * \details
- *
- *
- * \param[out] ver
- * io driver version.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevGetDrvVersion(uint32_t *ver) {
- if (GetBDaqLib()->pfnGetDrvVersion) {
- return GetBDaqLib()->pfnGetDrvVersion(ver);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Set DO initial value .
- *
- * \details
- *
- *
- * \param[in] chStart
- * do channel index.
- *
- * \param[in] chCount
- * do channel count.
- *
- *\param[in] type
- * init value type.
- *
- *\param[in] valueRange
- * init value be setting, 32bit array.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevSetDoInitValue(uint32_t chStart, uint32_t chCount, uint32_t type, void *valueRange) {
- if (GetBDaqLib()->pfnAccessDoinitValue) {
- return GetBDaqLib()->pfnAccessDoinitValue(chStart, chCount, type, valueRange, 1);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- /*!*************************************************************************
- * \brief
- * Get DO initial value .
- *
- * \details
- *
- *
- * \param[in] chStart
- * do channel index.
- *
- * \param[in] chCount
- * do channel count.
- *
- *\param[in] type
- * init value type.
- *
- *\param[out] valueRange
- * to be fill with init value, 32bit array.
- *
- * \return
- * result, 0 if successful.
- *
- ***************************************************************************/
- static inline ErrorCode AdvioDevGetDoInitValue(uint32_t chStart, uint32_t chCount, uint32_t type, void *valueRange) {
- if (GetBDaqLib()->pfnAccessDoinitValue) {
- return GetBDaqLib()->pfnAccessDoinitValue(chStart, chCount, type, valueRange, 0);
- } else {
-
- return ErrorHandleNotValid;
- }
- }
- #endif
- //***************************************************************************************
- //
- //! \example example/airead/main.c
- //! Show how to get ai sample value.
- //! \example example/airange_get/main.c
- //! Show how to get ai range code.
- //! \example example/airange_set/main.c
- //! Show how to set ai range code.
- //! \example example/diread/main.c
- //! Show how to get di value.
- //! \example example/doread/main.c
- //! Show how to get do value.
- //! \example example/dowrite_multi/main.c
- //! Show how to set do to multi channel in one time.
- //! \example example/dowrite_single/main.c
- //! Show how to set do to a single channel.
- //! \example example/mdlsearch/main.c
- //! Show how to get io device information.
- //
- //***************************************************************************************
|