advio.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. //***************************************************************************************
  2. //
  3. //! \file advio.h
  4. //! IO deiver for ECU series prodeuct.
  5. //!
  6. //! \version V1.0
  7. //! \date 2024
  8. //
  9. //***************************************************************************************
  10. #ifndef _ADVIO_H_
  11. #define _ADVIO_H_
  12. #include <stdio.h>
  13. #include <stdint.h>
  14. #include <stdbool.h>
  15. #include <dlfcn.h>
  16. #undef LOG_DOMAIN
  17. #undef LOG_TAG
  18. #define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域
  19. #define LOG_TAG "MY_TAG"
  20. #include "hilog/log.h"
  21. #ifndef WIN_TYPE_DEF
  22. #define WIN_TYPE_DEF
  23. typedef char WCHAR;
  24. typedef void *HMODULE;
  25. typedef void *HANDLE;
  26. typedef bool BOOL;
  27. typedef char BYTE;
  28. typedef HANDLE HINSTANCE;
  29. #endif
  30. #define DLL_FILE_NAME "libadvio.so"
  31. #define AI_CALI_TYPE_ZERO 0X55
  32. #define AI_CALI_TYPE_SPAN 0Xaa
  33. #define AI_CALI_TYPE_MIX 0X5a
  34. #define CAL_FLASH 0x01
  35. #define _USER_FACTORY 0X02
  36. #define CAL_FACTORY_USER 0x03
  37. /** range value of 0~20mA. */
  38. #define RANGE_CODE_I_0_P20 0x0182
  39. /** range value of 4~20mA. */
  40. #define RANGE_CODE_I_4_P20 0x0180
  41. /** range value of -2.5V~2.5V. */
  42. #define RANGE_CODE_V_N2P5_P2P5 0x0141
  43. /** range value of -10V~10V. */
  44. #define RANGE_CODE_V_N10_P10 0x0143
  45. /** range value of 0V~10V. */
  46. #define RANGE_CODE_V_0_P10 0x0149
  47. enum DO_INIT_VALUE_TYPE { DO_INIT_DOVALUE_TYPE = 0, DO_INIT_RESERVED };
  48. #pragma pack(1)
  49. /** module information data struct */
  50. typedef struct tagSPISearchDeviceAck {
  51. /** firmware working mode. 0: download mode 1 : application mode */
  52. uint8_t uModuleMode;
  53. /** module name */
  54. uint8_t ucModuleName[10];
  55. /** firmware version */
  56. uint32_t ulModuleVersion;
  57. /** channel number of AI */
  58. uint8_t ucAINum;
  59. /** channel number of AO */
  60. uint8_t ucAONum;
  61. /** channel number of DI */
  62. uint8_t ucDINum;
  63. /** channel number of DO */
  64. uint8_t ucDONum;
  65. /** reserved */
  66. uint32_t ulresv;
  67. } SPISearchDev, *PSPISearchDev;
  68. typedef struct _CMD_LOCATION {
  69. int head;
  70. int tail;
  71. } CMD_LOCATION, *PCMD_LOCATION;
  72. #pragma pack()
  73. typedef enum tagErrorCode {
  74. /// <summary>
  75. /// The operation is completed successfully.
  76. /// </summary>
  77. Success = 0,
  78. ///************************************************************************
  79. /// warning
  80. ///************************************************************************
  81. /// <summary>
  82. /// The interrupt resource is not available.
  83. /// </summary>
  84. WarningIntrNotAvailable = 0xA0000000,
  85. /// <summary>
  86. /// The parameter is out of the range.
  87. /// </summary>
  88. WarningParamOutOfRange = 0xA0000001,
  89. /// <summary>
  90. /// The property value is out of range.
  91. /// </summary>
  92. WarningPropValueOutOfRange = 0xA0000002,
  93. /// <summary>
  94. /// The property value is not supported.
  95. /// </summary>
  96. WarningPropValueNotSpted = 0xA0000003,
  97. /// <summary>
  98. /// The property value conflicts with the current state.
  99. /// </summary>
  100. WarningPropValueConflict = 0xA0000004,
  101. ///***********************************************************************
  102. /// error
  103. ///***********************************************************************
  104. /// <summary>
  105. /// The handle is NULL or its type doesn't match the required operation.
  106. /// </summary>
  107. ErrorHandleNotValid = 0xE0000000,
  108. /// <summary>
  109. /// The parameter value is out of range.
  110. /// </summary>
  111. ErrorParamOutOfRange = 0xE0000001,
  112. /// <summary>
  113. /// The parameter value is not supported.
  114. /// </summary>
  115. ErrorParamNotSpted = 0xE0000002,
  116. /// <summary>
  117. /// The parameter value format is not the expected.
  118. /// </summary>
  119. ErrorParamFmtUnexpted = 0xE0000003,
  120. /// <summary>
  121. /// Not enough memory is available to complete the operation.
  122. /// </summary>
  123. ErrorMemoryNotEnough = 0xE0000004,
  124. /// <summary>
  125. /// The data buffer is null.
  126. /// </summary>
  127. ErrorBufferIsNull = 0xE0000005,
  128. /// <summary>
  129. /// The data buffer is too small for the operation.
  130. /// </summary>
  131. ErrorBufferTooSmall = 0xE0000006,
  132. /// <summary>
  133. /// The data length exceeded the limitation.
  134. /// </summary>
  135. ErrorDataLenExceedLimit = 0xE0000007,
  136. /// <summary>
  137. /// The required function is not supported.
  138. /// </summary>
  139. ErrorFuncNotSpted = 0xE0000008,
  140. /// <summary>
  141. /// The required event is not supported.
  142. /// </summary>
  143. ErrorEventNotSpted = 0xE0000009,
  144. /// <summary>
  145. /// The required property is not supported.
  146. /// </summary>
  147. ErrorPropNotSpted = 0xE000000A,
  148. /// <summary>
  149. /// The required property is read-only.
  150. /// </summary>
  151. ErrorPropReadOnly = 0xE000000B,
  152. /// <summary>
  153. /// The specified property value conflicts with the current state.
  154. /// </summary>
  155. ErrorPropValueConflict = 0xE000000C,
  156. /// <summary>
  157. /// The specified property value is out of range.
  158. /// </summary>
  159. ErrorPropValueOutOfRange = 0xE000000D,
  160. /// <summary>
  161. /// The specified property value is not supported.
  162. /// </summary>
  163. ErrorPropValueNotSpted = 0xE000000E,
  164. /// <summary>
  165. /// The handle hasn't own the privilege of the operation the user wanted.
  166. /// </summary>
  167. ErrorPrivilegeNotHeld = 0xE000000F,
  168. /// <summary>
  169. /// The required privilege is not available because someone else had own it.
  170. /// </summary>
  171. ErrorPrivilegeNotAvailable = 0xE0000010,
  172. /// <summary>
  173. /// The driver of specified device was not found.
  174. /// </summary>
  175. ErrorDriverNotFound = 0xE0000011,
  176. /// <summary>
  177. /// The driver version of the specified device mismatched.
  178. /// </summary>
  179. ErrorDriverVerMismatch = 0xE0000012,
  180. /// <summary>
  181. /// The loaded driver count exceeded the limitation.
  182. /// </summary>
  183. ErrorDriverCountExceedLimit = 0xE0000013,
  184. /// <summary>
  185. /// The device is not opened.
  186. /// </summary>
  187. ErrorDeviceNotOpened = 0xE0000014,
  188. /// <summary>
  189. /// The required device does not exist.
  190. /// </summary>
  191. ErrorDeviceNotExist = 0xE0000015,
  192. /// <summary>
  193. /// The required device is unrecognized by driver.
  194. /// </summary>
  195. ErrorDeviceUnrecognized = 0xE0000016,
  196. /// <summary>
  197. /// The configuration data of the specified device is lost or unavailable.
  198. /// </summary>
  199. ErrorConfigDataLost = 0xE0000017,
  200. /// <summary>
  201. /// The function is not initialized and can't be started.
  202. /// </summary>
  203. ErrorFuncNotInited = 0xE0000018,
  204. /// <summary>
  205. /// The function is busy.
  206. /// </summary>
  207. ErrorFuncBusy = 0xE0000019,
  208. /// <summary>
  209. /// The interrupt resource is not available.
  210. /// </summary>
  211. ErrorIntrNotAvailable = 0xE000001A,
  212. /// <summary>
  213. /// The DMA channel is not available.
  214. /// </summary>
  215. ErrorDmaNotAvailable = 0xE000001B,
  216. /// <summary>
  217. /// Time out when reading/writing the device.
  218. /// </summary>
  219. ErrorDeviceIoTimeOut = 0xE000001C,
  220. /// <summary>
  221. /// The given signature does not match with the device current one.
  222. /// </summary>
  223. ErrorSignatureNotMatch = 0xE000001D,
  224. /// <summary>
  225. /// The given configure does not match with the device current one.
  226. /// </summary>
  227. ErrorConfigNotRight = 0xE0000020,
  228. /// <summary>
  229. /// Undefined error
  230. /// </summary>
  231. ErrorUndefined = 0xE000FFFF,
  232. } ErrorCode;
  233. typedef ErrorCode (*PFNIODEVINIT)(void);
  234. typedef ErrorCode (*PFNIODEVCLOSE)(void);
  235. typedef ErrorCode (*PFNGETSPIDEVHANDLE)(int *);
  236. typedef ErrorCode (*PFNSPIPROTOIO)(int, uint8_t *, uint8_t, uint8_t *, uint8_t *, uint8_t);
  237. typedef ErrorCode (*PFNGETDEVINFO)(PSPISearchDev);
  238. typedef ErrorCode (*PFNGETADDEVINFO)(char *, char *);
  239. typedef unsigned char (*PFNCONSTRUCTSPIPACKAGE)(unsigned char, unsigned char, unsigned char, unsigned char *,
  240. unsigned char, unsigned char *);
  241. typedef ErrorCode (*PFNGETAIRANGECODE)(unsigned char, unsigned char, unsigned char *);
  242. typedef ErrorCode (*PFNSETAIRANGECODE)(unsigned char, unsigned char, unsigned char *);
  243. typedef ErrorCode (*PFNAIREAD)(unsigned char, unsigned char, unsigned char *);
  244. typedef ErrorCode (*PFNAICAILIBRATE)(unsigned char, unsigned char);
  245. typedef ErrorCode (*PFNAICALIBRATEFLASH)(unsigned char);
  246. typedef ErrorCode (*PFNSETAIINTERGRATION)(uint8_t);
  247. typedef ErrorCode (*PFNGETAIINTERGRATION)(uint8_t *);
  248. typedef ErrorCode (*PFNDOREAD)(unsigned int *);
  249. typedef ErrorCode (*PFNDOWRITEONECHANNEL)(unsigned int, unsigned int);
  250. typedef ErrorCode (*PFNDOWRITEALL)(unsigned int);
  251. typedef ErrorCode (*PFNDIREAD)(unsigned int *);
  252. typedef ErrorCode (*PFNGETDRVVERSION)(uint32_t *);
  253. // typedef ErrorCode (* PFNDOINITVALUEGET)(unsigned int, unsigned int*);
  254. // typedef ErrorCode (* PFNDOINITVALUESET)(unsigned int, unsigned int);
  255. typedef ErrorCode (*PFNACCESSDOINITVALUE)(uint32_t, uint32_t, uint32_t, void *, uint32_t);
  256. typedef struct _BAdvIOLib {
  257. HMODULE instHandle;
  258. PFNIODEVINIT pfnIODevInit;
  259. PFNIODEVCLOSE pfnIODevClose;
  260. PFNGETSPIDEVHANDLE pfnGetSPIDevHandle;
  261. PFNSPIPROTOIO pfnSPIProtoIO;
  262. PFNGETDEVINFO pfnGetDevInfo;
  263. PFNGETADDEVINFO pfnGetADDevInfo;
  264. PFNCONSTRUCTSPIPACKAGE pfnConstructSPIPackage;
  265. PFNGETAIRANGECODE pfnGetAIRangeCode;
  266. PFNSETAIRANGECODE pfnSetAIRangeCode;
  267. PFNAIREAD pfnAIRead;
  268. PFNAICAILIBRATE pfnAICalibrate;
  269. PFNAICALIBRATEFLASH pfnAICalibrateFlash;
  270. PFNSETAIINTERGRATION pfnSetAIIntergration;
  271. PFNGETAIINTERGRATION pfnGetAIIntergration;
  272. PFNDOREAD pfnDORead;
  273. PFNDOWRITEONECHANNEL pfnDOWriteOneChannel;
  274. PFNDOWRITEALL pfnDOWriteAll;
  275. PFNDIREAD pfnDIRead;
  276. PFNGETDRVVERSION pfnGetDrvVersion;
  277. // PFNDOINITVALUEGET pfnDoInitValueGet;
  278. // PFNDOINITVALUESET pfnDoInitValueSet;
  279. PFNACCESSDOINITVALUE pfnAccessDoinitValue;
  280. } BAdvIOLib, *PBAdvIOLib;
  281. static inline BAdvIOLib *GetBDaqLib(void) {
  282. static BAdvIOLib badvioLib;
  283. return &badvioLib;
  284. }
  285. static inline BOOL InitializeAdvIOLibray(BAdvIOLib *badviolib) {
  286. if (badviolib->instHandle == NULL) {
  287. if ((badviolib->instHandle = dlopen(DLL_FILE_NAME, RTLD_LAZY)) != NULL) {
  288. badviolib->pfnIODevInit = (PFNIODEVINIT)dlsym(badviolib->instHandle, "IODevInit");
  289. badviolib->pfnIODevClose = (PFNIODEVCLOSE)dlsym(badviolib->instHandle, "IODevClose");
  290. badviolib->pfnGetSPIDevHandle = (PFNGETSPIDEVHANDLE)dlsym(badviolib->instHandle, "GetSPIDevHandle");
  291. badviolib->pfnSPIProtoIO = (PFNSPIPROTOIO)dlsym(badviolib->instHandle, "SPIProtoIO");
  292. badviolib->pfnGetDevInfo = (PFNGETDEVINFO)dlsym(badviolib->instHandle, "GetDevInfo");
  293. badviolib->pfnGetADDevInfo = (PFNGETADDEVINFO)dlsym(badviolib->instHandle, "GetADDevInfo");
  294. badviolib->pfnConstructSPIPackage =
  295. (PFNCONSTRUCTSPIPACKAGE)dlsym(badviolib->instHandle, "ConstructSPIPackage");
  296. badviolib->pfnGetAIRangeCode = (PFNGETAIRANGECODE)dlsym(badviolib->instHandle, "GetAIRangeCode");
  297. badviolib->pfnSetAIRangeCode = (PFNSETAIRANGECODE)dlsym(badviolib->instHandle, "SetAIRangeCode");
  298. badviolib->pfnAIRead = (PFNAIREAD)dlsym(badviolib->instHandle, "AIRead");
  299. badviolib->pfnAICalibrate = (PFNAICAILIBRATE)dlsym(badviolib->instHandle, "AICalibrate");
  300. badviolib->pfnAICalibrateFlash = (PFNAICALIBRATEFLASH)dlsym(badviolib->instHandle, "AICalibrateFlash");
  301. badviolib->pfnSetAIIntergration = (PFNSETAIINTERGRATION)dlsym(badviolib->instHandle, "SetAIIntergration");
  302. badviolib->pfnGetAIIntergration = (PFNGETAIINTERGRATION)dlsym(badviolib->instHandle, "GetAIIntergration");
  303. // badviolib->pfnFormatSPICMDPackage = (PFNFORMATSPICMDPACKAGE)dlsym(badviolib->instHandle,
  304. // "FormatSPICMDPackage");
  305. badviolib->pfnDORead = (PFNDOREAD)dlsym(badviolib->instHandle, "DORead");
  306. badviolib->pfnDOWriteOneChannel = (PFNDOWRITEONECHANNEL)dlsym(badviolib->instHandle, "DOWriteOneChannel");
  307. badviolib->pfnDOWriteAll = (PFNDOWRITEALL)dlsym(badviolib->instHandle, "DOWriteAll");
  308. badviolib->pfnDIRead = (PFNDIREAD)dlsym(badviolib->instHandle, "DIRead");
  309. badviolib->pfnGetDrvVersion = (PFNGETDRVVERSION)dlsym(badviolib->instHandle, "GetDrvVersion");
  310. // badviolib->pfnDoInitValueGet = (PFNDOINITVALUEGET)dlsym(badviolib->instHandle, "DOInitValueGet");
  311. // badviolib->pfnDoInitValueSet = (PFNDOINITVALUESET)dlsym(badviolib->instHandle, "DOInitValueSet");
  312. badviolib->pfnAccessDoinitValue = (PFNACCESSDOINITVALUE)dlsym(badviolib->instHandle, "AccessDoInitValue");
  313. }
  314. }
  315. return badviolib->instHandle != NULL;
  316. }
  317. /*!*************************************************************************
  318. * \brief
  319. * Initialize the AdvIO device.
  320. *
  321. * \details
  322. * This function must be called before any other AdvIO functions.
  323. *
  324. * \return
  325. * result, 0 if successful.
  326. *
  327. ***************************************************************************/
  328. static inline ErrorCode AdvioDevInit(void) {
  329. if (InitializeAdvIOLibray(GetBDaqLib())) {
  330. if (GetBDaqLib()->pfnIODevInit) {
  331. return GetBDaqLib()->pfnIODevInit();
  332. } else {
  333. return ErrorHandleNotValid;
  334. }
  335. }
  336. return ErrorUndefined;
  337. }
  338. /*!*************************************************************************
  339. * \brief
  340. * De-initialize the Advio device
  341. *
  342. * \details
  343. *
  344. *
  345. * \return
  346. * result, 0 if successful.
  347. *
  348. ***************************************************************************/
  349. static inline ErrorCode AdvioDevClose(void) {
  350. if (GetBDaqLib()->pfnIODevClose) {
  351. return GetBDaqLib()->pfnIODevClose();
  352. } else {
  353. return ErrorHandleNotValid;
  354. }
  355. }
  356. /*!*************************************************************************
  357. * \brief
  358. * Get SPI Interface Handle.
  359. *
  360. * \details
  361. *
  362. * \param[out] phdl
  363. * Handle of the SPI Interface.
  364. *
  365. *
  366. * \return
  367. * result, 0 if successful.
  368. *
  369. ***************************************************************************/
  370. static inline ErrorCode AdvioGetSPIDevHandle(int *phdl) {
  371. if (GetBDaqLib()->pfnGetSPIDevHandle) {
  372. return GetBDaqLib()->pfnGetSPIDevHandle(phdl);
  373. } else {
  374. return ErrorHandleNotValid;
  375. }
  376. }
  377. /*!*************************************************************************
  378. * \brief
  379. * perform a SPI data exchange.
  380. *
  381. * \details
  382. *
  383. * \param[in] dev_hdl
  384. * Handle of the SPI Interface.
  385. *
  386. * \param[in] pinbuf
  387. * input data buffer.
  388. *
  389. * \param[in] inlen
  390. * number of input data.
  391. *
  392. * \param[out] poutbuf
  393. * output data buffer.
  394. *
  395. * \param[out] poutlen
  396. * number of output data.
  397. *
  398. * \param[in] printflag
  399. * flag display date or not.
  400. *
  401. * \return
  402. * result, 0 if successful.
  403. *
  404. ***************************************************************************/
  405. static inline ErrorCode AdvioSPIProtoIO(int dev_hdl, uint8_t *pinbuf, uint8_t inlen, uint8_t *poutbuf, uint8_t *poutlen,
  406. uint8_t printflag) {
  407. if (GetBDaqLib()->pfnSPIProtoIO) {
  408. return GetBDaqLib()->pfnSPIProtoIO(dev_hdl, pinbuf, inlen, poutbuf, poutlen, printflag);
  409. } else {
  410. return ErrorHandleNotValid;
  411. }
  412. }
  413. /*!*************************************************************************
  414. * \brief
  415. * Get IO module infomation.
  416. *
  417. * \details
  418. *
  419. *
  420. * \param[out] pdevinfo
  421. * pointer of module infomation data struct.
  422. *
  423. * \return
  424. * result, 0 if successful.
  425. *
  426. ***************************************************************************/
  427. static inline ErrorCode AdvioDevGetDevInfo(PSPISearchDev pdevinfo) {
  428. if (GetBDaqLib()->pfnGetDevInfo) {
  429. return GetBDaqLib()->pfnGetDevInfo(pdevinfo);
  430. } else {
  431. return ErrorHandleNotValid;
  432. }
  433. }
  434. /*!*************************************************************************
  435. * \brief
  436. * Get AD module infomation.
  437. *
  438. * \details
  439. *
  440. *
  441. * \param[out] pname
  442. * ad module name.
  443. *
  444. * \param[out] pinfo
  445. * ad module firmware version.
  446. *
  447. * \return
  448. * result, 0 if successful.
  449. *
  450. ***************************************************************************/
  451. static inline ErrorCode AdvioDevGetADDevInfo(char *pname, char *pinfo) {
  452. if (GetBDaqLib()->pfnGetADDevInfo) {
  453. return GetBDaqLib()->pfnGetADDevInfo(pname, pinfo);
  454. } else {
  455. return ErrorHandleNotValid;
  456. }
  457. }
  458. /*!*************************************************************************
  459. * \brief
  460. * Contruct a spi protocal data package.
  461. *
  462. * \details
  463. *
  464. *
  465. * \param[in] id
  466. * index of module.
  467. *
  468. * \param[in] direction
  469. * get data or set data.
  470. *
  471. * \param[in] command_id
  472. * spi command index.
  473. *
  474. * \param[in] pbufsrc
  475. * the rest input data buffer.
  476. *
  477. * \param[in] buflen
  478. * input data buffer lenght.
  479. *
  480. * \param[out] pbufdst
  481. * input data buffer.
  482. *
  483. * \return
  484. * result, 0 if successful.
  485. *
  486. ***************************************************************************/
  487. static inline ErrorCode AdvioDevConstructSPIPackage(unsigned char id, unsigned char direction, unsigned char command_id,
  488. unsigned char *pbufsrc, unsigned char buflen,
  489. unsigned char *pbufdst) {
  490. if (GetBDaqLib()->pfnConstructSPIPackage) {
  491. return (ErrorCode)(GetBDaqLib()->pfnConstructSPIPackage(id, direction, command_id, pbufsrc, buflen, pbufdst));
  492. } else {
  493. return ErrorHandleNotValid;
  494. }
  495. }
  496. /*!*************************************************************************
  497. * \brief
  498. * Get AI range code.
  499. *
  500. * \details
  501. *
  502. *
  503. * \param[in] startch
  504. * The number of the first data channel index you want to get.
  505. *
  506. * \param[in] stopch
  507. * The number of the last data channel index you want to get.
  508. *
  509. * \param[out] poutbuf
  510. * range code data output buffer, two byte per channel.
  511. *
  512. * \return
  513. * result, 0 if successful.
  514. *
  515. ***************************************************************************/
  516. static inline ErrorCode AdvioDevGetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) {
  517. if (GetBDaqLib()->pfnGetAIRangeCode) {
  518. return GetBDaqLib()->pfnGetAIRangeCode(startch, stopch, poutbuf);
  519. } else {
  520. return ErrorHandleNotValid;
  521. }
  522. }
  523. /*!*************************************************************************
  524. * \brief
  525. * Set AI range code.
  526. *
  527. * \details
  528. *
  529. *
  530. * \param[in] startch
  531. * The number of the first data channel index you want to set.
  532. *
  533. * \param[in] stopch
  534. * The number of the last data channel index you want to set.
  535. *
  536. * \param[in] poutbuf
  537. * range code data input buffer, two byte per channel.
  538. *
  539. * \return
  540. * result, 0 if successful.
  541. *
  542. ***************************************************************************/
  543. static inline ErrorCode AdvioDevSetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) {
  544. if (GetBDaqLib()->pfnSetAIRangeCode) {
  545. return GetBDaqLib()->pfnSetAIRangeCode(startch, stopch, poutbuf);
  546. } else {
  547. return ErrorHandleNotValid;
  548. }
  549. }
  550. /*!*************************************************************************
  551. * \brief
  552. * AI calibrate action.
  553. *
  554. * \details
  555. *
  556. *
  557. * \param[in] chan
  558. * The number of the data channel index you want to calibrate.
  559. *
  560. * \param[in] calitype
  561. * calibrate type, zero calibrate or range calibrate.
  562. *
  563. * \return
  564. * result, 0 if successful.
  565. *
  566. ***************************************************************************/
  567. static inline ErrorCode AdvioDevAICalibrate(unsigned char chan, unsigned char calitype) {
  568. if (GetBDaqLib()->pfnAICalibrate) {
  569. return GetBDaqLib()->pfnAICalibrate(chan, calitype);
  570. } else {
  571. return ErrorHandleNotValid;
  572. }
  573. }
  574. /*!*************************************************************************
  575. * \brief
  576. * store calibrate data into flash.
  577. *
  578. * \details
  579. *
  580. *
  581. * \param[in] act_type
  582. * action type, to user flash or factory flash.
  583. *
  584. * \return
  585. * result, 0 if successful.
  586. *
  587. ***************************************************************************/
  588. static inline ErrorCode AdvioDevAICalibrateFlash(unsigned char act_type) {
  589. if (GetBDaqLib()->pfnAICalibrateFlash) {
  590. return GetBDaqLib()->pfnAICalibrateFlash(act_type);
  591. } else {
  592. return ErrorHandleNotValid;
  593. }
  594. }
  595. /*!*************************************************************************
  596. * \brief
  597. * Sinc3 decimation factor setting.
  598. *
  599. * \details
  600. *
  601. *
  602. * \param[in] flag
  603. * Sinc3 decimation factor, 0:60Hz, 1:50Hz.
  604. *
  605. * \return
  606. * result, 0 if successful.
  607. *
  608. ***************************************************************************/
  609. static inline ErrorCode AdvioDevSetAIIntergration(uint8_t flag) {
  610. if (GetBDaqLib()->pfnSetAIIntergration) {
  611. return GetBDaqLib()->pfnSetAIIntergration(flag);
  612. } else {
  613. return ErrorHandleNotValid;
  614. }
  615. }
  616. /*!*************************************************************************
  617. * \brief
  618. * get Sinc3 decimation factor.
  619. *
  620. * \details
  621. *
  622. *
  623. * \param[out] pflag
  624. * Sinc3 decimation factor, 0:60Hz, 1:50Hz.
  625. *
  626. * \return
  627. * result, 0 if successful.
  628. *
  629. ***************************************************************************/
  630. static inline ErrorCode AdvioDevGetAIIntergration(uint8_t *pflag) {
  631. if (GetBDaqLib()->pfnGetAIIntergration) {
  632. return GetBDaqLib()->pfnGetAIIntergration(pflag);
  633. } else {
  634. return ErrorHandleNotValid;
  635. }
  636. }
  637. /*!*************************************************************************
  638. * \brief
  639. * Obtain the results of AI.
  640. *
  641. * \details
  642. *
  643. *
  644. * \param[in] startch
  645. * The number of the first data channel index you want to set.
  646. *
  647. * \param[in] stopch
  648. * The number of the last data channel index you want to set.
  649. *
  650. * \param[out] poutbuf
  651. * AI data output buffer, two byte per channel.
  652. *
  653. * \return
  654. * result, 0 if successful.
  655. *
  656. ***************************************************************************/
  657. static inline ErrorCode AdvioDevAIRead(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) {
  658. if (GetBDaqLib()->pfnAIRead) {
  659. return GetBDaqLib()->pfnAIRead(startch, stopch, poutbuf);
  660. } else {
  661. return ErrorHandleNotValid;
  662. }
  663. }
  664. /*!*************************************************************************
  665. * \brief
  666. * Obtain the current state of do.
  667. *
  668. * \details
  669. *
  670. *
  671. * \param[out] dovalue
  672. * do state of all channel, one bit corresponds to one do channel.
  673. *
  674. * \return
  675. * result, 0 if successful.
  676. *
  677. ***************************************************************************/
  678. static inline ErrorCode AdvioDevDORead(unsigned int *dovalue) {
  679. if (GetBDaqLib()->pfnDORead) {
  680. return GetBDaqLib()->pfnDORead(dovalue);
  681. } else {
  682. return ErrorHandleNotValid;
  683. }
  684. }
  685. /*!*************************************************************************
  686. * \brief
  687. * Write the DO value of a channel.
  688. *
  689. * \details
  690. *
  691. *
  692. * \param[in] index
  693. * do channel index.
  694. *
  695. * \param[in] value
  696. * do value be setting.
  697. *
  698. * \return
  699. * result, 0 if successful.
  700. *
  701. ***************************************************************************/
  702. static inline ErrorCode AdvioDevDOWriteOneChannel(unsigned int index, unsigned int value) {
  703. if (GetBDaqLib()->pfnDOWriteOneChannel) {
  704. return GetBDaqLib()->pfnDOWriteOneChannel(index, value);
  705. } else {
  706. return ErrorHandleNotValid;
  707. }
  708. }
  709. /*!*************************************************************************
  710. * \brief
  711. * Write the DO value of all channel.
  712. *
  713. * \details
  714. *
  715. *
  716. * \param[in] value
  717. * do value be setting, one bit corresponds to one do channel.
  718. *
  719. * \return
  720. * result, 0 if successful.
  721. *
  722. ***************************************************************************/
  723. static inline ErrorCode AdvioDevDOWriteAll(unsigned int value) {
  724. if (GetBDaqLib()->pfnDOWriteAll) {
  725. return GetBDaqLib()->pfnDOWriteAll(value);
  726. } else {
  727. return ErrorHandleNotValid;
  728. }
  729. }
  730. /*!*************************************************************************
  731. * \brief
  732. * Obtain the current state of di.
  733. *
  734. * \details
  735. *
  736. *
  737. * \param[out] divalue
  738. * di state of all channel, one bit corresponds to one di channel.
  739. *
  740. * \return
  741. * result, 0 if successful.
  742. *
  743. ***************************************************************************/
  744. static inline ErrorCode AdvioDevDIRead(unsigned int *divalue) {
  745. if (GetBDaqLib()->pfnDIRead) {
  746. return GetBDaqLib()->pfnDIRead(divalue);
  747. } else {
  748. return ErrorHandleNotValid;
  749. }
  750. }
  751. // /*!*************************************************************************
  752. // * \brief
  753. // * Obtain the do init value.
  754. // *
  755. // * \details
  756. // *
  757. // *
  758. // * \param[in] index
  759. // * do channel index.
  760. // *
  761. // * \param[out] pvalue
  762. // * do init value.
  763. // *
  764. // * \return
  765. // * result, 0 if successful.
  766. // *
  767. // ***************************************************************************/
  768. // static inline ErrorCode AdvioDevDoInitValueGet(unsigned int index, unsigned int* pvalue)
  769. // {
  770. // return GetBDaqLib()->pfnDoInitValueGet(index, pvalue);
  771. // }
  772. // /*!*************************************************************************
  773. // * \brief
  774. // * Obtain the do init value.
  775. // *
  776. // * \details
  777. // *
  778. // *
  779. // * \param[in] index
  780. // * do channel index.
  781. // *
  782. // * \param[in] value
  783. // * do init value.
  784. // *
  785. // * \return
  786. // * result, 0 if successful.
  787. // *
  788. // ***************************************************************************/
  789. // static inline ErrorCode AdvioDevDoInitValueSet(unsigned int index, unsigned int value)
  790. // {
  791. // return GetBDaqLib()->pfnDoInitValueSet(index, value);
  792. // }
  793. /*!*************************************************************************
  794. * \brief
  795. * Obtain the io driver version.
  796. *
  797. * \details
  798. *
  799. *
  800. * \param[out] ver
  801. * io driver version.
  802. *
  803. * \return
  804. * result, 0 if successful.
  805. *
  806. ***************************************************************************/
  807. static inline ErrorCode AdvioDevGetDrvVersion(uint32_t *ver) {
  808. if (GetBDaqLib()->pfnGetDrvVersion) {
  809. return GetBDaqLib()->pfnGetDrvVersion(ver);
  810. } else {
  811. return ErrorHandleNotValid;
  812. }
  813. }
  814. /*!*************************************************************************
  815. * \brief
  816. * Set DO initial value .
  817. *
  818. * \details
  819. *
  820. *
  821. * \param[in] chStart
  822. * do channel index.
  823. *
  824. * \param[in] chCount
  825. * do channel count.
  826. *
  827. *\param[in] type
  828. * init value type.
  829. *
  830. *\param[in] valueRange
  831. * init value be setting, 32bit array.
  832. *
  833. * \return
  834. * result, 0 if successful.
  835. *
  836. ***************************************************************************/
  837. static inline ErrorCode AdvioDevSetDoInitValue(uint32_t chStart, uint32_t chCount, uint32_t type, void *valueRange) {
  838. if (GetBDaqLib()->pfnAccessDoinitValue) {
  839. return GetBDaqLib()->pfnAccessDoinitValue(chStart, chCount, type, valueRange, 1);
  840. } else {
  841. return ErrorHandleNotValid;
  842. }
  843. }
  844. /*!*************************************************************************
  845. * \brief
  846. * Get DO initial value .
  847. *
  848. * \details
  849. *
  850. *
  851. * \param[in] chStart
  852. * do channel index.
  853. *
  854. * \param[in] chCount
  855. * do channel count.
  856. *
  857. *\param[in] type
  858. * init value type.
  859. *
  860. *\param[out] valueRange
  861. * to be fill with init value, 32bit array.
  862. *
  863. * \return
  864. * result, 0 if successful.
  865. *
  866. ***************************************************************************/
  867. static inline ErrorCode AdvioDevGetDoInitValue(uint32_t chStart, uint32_t chCount, uint32_t type, void *valueRange) {
  868. if (GetBDaqLib()->pfnAccessDoinitValue) {
  869. return GetBDaqLib()->pfnAccessDoinitValue(chStart, chCount, type, valueRange, 0);
  870. } else {
  871. return ErrorHandleNotValid;
  872. }
  873. }
  874. #endif
  875. //***************************************************************************************
  876. //
  877. //! \example example/airead/main.c
  878. //! Show how to get ai sample value.
  879. //! \example example/airange_get/main.c
  880. //! Show how to get ai range code.
  881. //! \example example/airange_set/main.c
  882. //! Show how to set ai range code.
  883. //! \example example/diread/main.c
  884. //! Show how to get di value.
  885. //! \example example/doread/main.c
  886. //! Show how to get do value.
  887. //! \example example/dowrite_multi/main.c
  888. //! Show how to set do to multi channel in one time.
  889. //! \example example/dowrite_single/main.c
  890. //! Show how to set do to a single channel.
  891. //! \example example/mdlsearch/main.c
  892. //! Show how to get io device information.
  893. //
  894. //***************************************************************************************