OkoLib
library for accessing Okolab devices
okolib.h
1 
333 #ifndef _OKOLIB_H_
334 #define _OKOLIB_H_
335 
336 #ifdef _MSC_VER
337  #if _MSC_VER >= 1600
338  #include <stdint.h>
339  #else
340  typedef __int8 int8_t;
341  typedef __int16 int16_t;
342  typedef __int32 int32_t;
343  typedef __int64 int64_t;
344  typedef unsigned __int8 uint8_t;
345  typedef unsigned __int16 uint16_t;
346  typedef unsigned __int32 uint32_t;
347  typedef unsigned __int64 uint64_t;
348  #endif
349 #elif __GNUC__ >= 3
350  #include <stdint.h>
351 #endif
352 
353 
354 
355 
356 #ifdef __cplusplus
357 extern "C" {
358 #endif
359 
360 #ifdef _WIN32
361 
362 #if defined(OKO_NO_DLL) /* Static import */
363 # define OKO_API
364 #elif defined(OKO_BUILDING_DLL) /* DLL export */
365 # define OKO_API __declspec (dllexport)
366 #else /* DLL import */
367 # define OKO_API __declspec (dllimport)
368 #endif /* Not BUILDING_DLL */
369 
370 /* Define calling convention in one place, for convenience. */
371 #define OKO_EXPORT __cdecl
372 
373 /* Microsoft VBA */
374 #ifdef OKO_VBA
375 #undef OKO_EXPORT
376 #define OKO_EXPORT __stdcall
377 #endif
378 
379 #else /* _WIN32 not defined. */
380 
381 /* Define with no value on non-Windows OSes. */
382 #define OKO_API
383 #define OKO_EXPORT
384 
385 #endif
386 
393 typedef enum _oko_res_type
394 {
395  OKO_OK = 0,
397  OKO_ERR_ARG = -2,
408  OKO_ERR_COMM = -13,
415  OKO_ERR_UNDEF = -999,
417 
431 OKO_API oko_res_type OKO_EXPORT
432 #ifdef __LINUX__
433 oko_LibInit(char *db_path);
434 #else
435 oko_LibInit(const char *db_path);
436 #endif
437 
442 OKO_API oko_res_type OKO_EXPORT
444 
450 OKO_API oko_res_type OKO_EXPORT
451 oko_LibGetVersion(char *version);
452 
460 OKO_API oko_res_type OKO_EXPORT
461 oko_LibGetLastError(char *errmsg, unsigned int maxsize);
462 
463 
469 OKO_API oko_res_type OKO_EXPORT
471 
472 
478 OKO_API oko_res_type OKO_EXPORT
480 
481 
482 
483 
493 typedef enum _oko_module_type
494 {
501 
502 
510 OKO_API oko_res_type OKO_EXPORT
511 oko_ModulesDetect(uint32_t max_num, oko_module_type *modules, uint32_t *detected_num);
512 
522 OKO_API oko_res_type OKO_EXPORT
524  uint32_t selected_modules_num, oko_module_type *modules, uint32_t *detected_num);
525 
535 OKO_API oko_res_type OKO_EXPORT
536 oko_ModuleGetDetails(oko_module_type module, char *name, char *dim_unit, bool *can_disable);
537 
544 OKO_API oko_res_type OKO_EXPORT
545 oko_ModuleGetCurrentValue(oko_module_type module, double *current_value);
546 
553 OKO_API oko_res_type OKO_EXPORT
554 oko_ModuleGetSetpointValue(oko_module_type module, double *setpoint_value);
555 
563 OKO_API oko_res_type OKO_EXPORT
564 oko_ModuleGetLimits(oko_module_type module, double *min_value, double *max_value);
565 
572 OKO_API oko_res_type OKO_EXPORT
573 oko_ModuleSetSetpointValue(oko_module_type module, double setpoint_value);
574 
583 OKO_API oko_res_type OKO_EXPORT
584 oko_ModuleGetEnabled(oko_module_type module, bool *enabled);
585 
608 OKO_API oko_res_type OKO_EXPORT
609 oko_ModuleSetEnabled(oko_module_type module, bool enabled);
610 
622 OKO_API oko_res_type OKO_EXPORT
623 oko_LibGetNumberOfPorts(uint32_t *count);
624 
630 OKO_API oko_res_type OKO_EXPORT
631 oko_LibGetPortNames(char **names);
632 
641 OKO_API oko_res_type OKO_EXPORT
642 oko_LibGetPortName(uint32_t portidx, char *portname);
643 
650 OKO_API oko_res_type OKO_EXPORT
651 oko_DeviceOpen(const char *port, uint32_t *deviceh);
652 
660 OKO_API oko_res_type OKO_EXPORT
661 oko_DevicesDetect(uint32_t max_num, uint32_t *devicesh, uint32_t *detected_num);
662 
663 
672 OKO_API oko_res_type OKO_EXPORT
673 oko_DevicesDetectByName(uint32_t max_num, uint32_t *devicesh, char *name_filter, uint32_t *detected_num);
674 
675 
681 OKO_API oko_res_type OKO_EXPORT
682 oko_DeviceDetectSingle(uint32_t *deviceh);
683 
684 
691 OKO_API oko_res_type OKO_EXPORT
692 oko_DeviceDetectSingleByName(uint32_t *deviceh, char *name_filter);
693 
694 
700 OKO_API oko_res_type OKO_EXPORT
701 oko_DeviceClose(uint32_t deviceh);
702 
711 OKO_API oko_res_type OKO_EXPORT
712 oko_DeviceGetLastError(uint32_t deviceh, char *errmsg, unsigned int maxsize);
713 
718 OKO_API oko_res_type OKO_EXPORT
720 
732 OKO_API oko_res_type OKO_EXPORT
733 oko_DeviceGetPortName(uint32_t deviceh, char *port);
734 
735 
742 OKO_API oko_res_type OKO_EXPORT
743 oko_DeviceConnectionStatus(uint32_t deviceh, uint32_t *conn);
744 
745 
752 OKO_API oko_res_type OKO_EXPORT
753 oko_DeviceSetChecksumUsage(uint32_t deviceh, bool use_checksum);
754 
755 
762 OKO_API oko_res_type OKO_EXPORT
763 oko_DeviceGetChecksumUsage(uint32_t deviceh, bool *use_checksum);
764 
772 OKO_API oko_res_type OKO_EXPORT
773 oko_DeviceGetChecksumAvailable(uint32_t deviceh, bool *checksum);
774 
787 OKO_API oko_res_type OKO_EXPORT
788 oko_PropertiesGetNumber(uint32_t deviceh, uint32_t *num);
789 
799 OKO_API oko_res_type OKO_EXPORT
800 oko_PropertyGetName(uint32_t deviceh, uint32_t index, char *name);
801 
805 typedef enum _oko_prop_type
806 {
813 
814 
822 OKO_API oko_res_type OKO_EXPORT
823 oko_PropertyGetType(uint32_t deviceh, const char *name, oko_prop_type *prop_type);
824 
825 
833 OKO_API oko_res_type OKO_EXPORT
834 oko_PropertyGetEnumNumber(uint32_t deviceh, const char *name, unsigned int *num);
835 
836 
837 
851 OKO_API oko_res_type OKO_EXPORT
852 oko_PropertyGetEnumName(uint32_t deviceh, const char *name, uint32_t enum_val, char *enum_name);
853 
854 
855 
863 OKO_API oko_res_type OKO_EXPORT
864 oko_PropertyGetUnit(uint32_t deviceh, const char *name, char *unit);
865 
873 OKO_API oko_res_type OKO_EXPORT
874 oko_PropertyGetDescription(uint32_t deviceh, const char *name, char *desc);
875 
883 OKO_API oko_res_type OKO_EXPORT
884 oko_PropertyGetReadOnly(uint32_t deviceh, const char *name, bool *read_only);
885 
889 typedef enum _oko_write_type
890 {
896 
897 
905 OKO_API oko_res_type OKO_EXPORT
906 oko_PropertyGetWriteOnly(uint32_t deviceh, const char *name, bool *write_only);
907 
915 OKO_API oko_res_type OKO_EXPORT
916 oko_PropertyGetWriteType(uint32_t deviceh, const char *name, oko_write_type *write_type);
917 
918 
928 OKO_API oko_res_type OKO_EXPORT
929 oko_PropertyHasLimits(uint32_t deviceh, const char *name, bool *has_limits);
930 
940 OKO_API oko_res_type OKO_EXPORT
941 oko_PropertyGetLimits(uint32_t deviceh, const char *name, double *min, double *max);
942 
950 OKO_API oko_res_type OKO_EXPORT
951 oko_PropertyIsMain(uint32_t deviceh, const char *name, bool *is_main);
952 
962 OKO_API oko_res_type OKO_EXPORT
963 oko_PropertyIsAdvanced(uint32_t deviceh, const char *name, bool *is_adv);
964 
980 OKO_API oko_res_type OKO_EXPORT
981 oko_PropertyReadString(uint32_t deviceh, const char *name, char *val);
982 
991 OKO_API oko_res_type OKO_EXPORT
992 oko_PropertyReadInt(uint32_t deviceh, const char *name, int32_t *val);
993 
1002 OKO_API oko_res_type OKO_EXPORT
1003 oko_PropertyReadDouble(uint32_t deviceh, const char *name, double *val);
1004 
1011 OKO_API oko_res_type OKO_EXPORT
1012 oko_PropertyUpdate(uint32_t deviceh, const char *name); // refresh, read ?
1013 
1029 OKO_API oko_res_type OKO_EXPORT
1030 oko_PropertyWriteString(uint32_t deviceh, const char *name, const char *val, bool async);
1031 
1041 OKO_API oko_res_type OKO_EXPORT
1042 oko_PropertyWriteInt(uint32_t deviceh, const char *name, int32_t val, char async);
1043 
1053 OKO_API oko_res_type OKO_EXPORT
1054 oko_PropertyWriteDouble(uint32_t deviceh, const char *name, double val, char async);
1055 
1065 OKO_API oko_res_type OKO_EXPORT
1066 oko_PropertyWriteVolatileString(uint32_t deviceh, const char *name, const char *val, bool async);
1067 
1077 OKO_API oko_res_type OKO_EXPORT
1078 oko_PropertyWriteVolatileInt(uint32_t deviceh, const char *name, int32_t val, char async);
1079 
1089 OKO_API oko_res_type OKO_EXPORT
1090 oko_PropertyWriteVolatileDouble(uint32_t deviceh, const char *name, double val, char async);
1091 
1105 OKO_API oko_res_type OKO_EXPORT
1106 oko_PropertyAutoUpdate(uint32_t deviceh, const char *name, uint32_t freq_ms);
1107 
1121 OKO_API oko_res_type OKO_EXPORT
1122 oko_StartPropertyLogging(uint32_t deviceh, const char *filename, uint32_t freq_ms);
1123 
1129 OKO_API oko_res_type OKO_EXPORT
1130 oko_StopPropertyLogging(uint32_t deviceh);
1131 
1138 OKO_API oko_res_type OKO_EXPORT
1139 oko_PropertyLoggingGetFileName(uint32_t deviceh, char *filename);
1140 
1153 OKO_API oko_res_type OKO_EXPORT
1154 oko_StartPlayback(uint32_t deviceh, const char *filename);
1155 
1161 OKO_API oko_res_type OKO_EXPORT
1162 oko_StopPlayback(uint32_t deviceh);
1163 
1170 OKO_API oko_res_type OKO_EXPORT
1171 oko_PlaybakGetFileName(uint32_t deviceh, char *filename);
1172 
1186 OKO_API oko_res_type OKO_EXPORT
1187 oko_CommandExecute(uint32_t deviceh, const char *name);
1188 
1189 
1191 OKO_API oko_res_type OKO_EXPORT
1192 oko_OkolabSetDebugPropertiesUsage(bool debug_properties);
1193 
1194 OKO_API oko_res_type OKO_EXPORT
1195 oko_OkolabGetLastProtocolError(uint32_t deviceh, const char *name, int *err);
1202 #ifdef __cplusplus
1203 }
1204 #endif
1205 
1206 #endif /* _OKOLIB_H_ */
1207 
oko_res_type oko_CommandExecute(uint32_t deviceh, const char *name)
Execute a command.
oko_res_type oko_PropertyLoggingGetFileName(uint32_t deviceh, char *filename)
Get the file path used to log the specified device.
oko_res_type oko_StartPropertyLogging(uint32_t deviceh, const char *filename, uint32_t freq_ms)
Start the property logging feature for the specified device.
oko_res_type oko_StopPropertyLogging(uint32_t deviceh)
Stop the property logging feature for the specified device.
oko_res_type oko_PlaybakGetFileName(uint32_t deviceh, char *filename)
Get the file path used to playback the specified device.
oko_res_type oko_StartPlayback(uint32_t deviceh, const char *filename)
Start the playback feature for the specified device.
oko_res_type oko_StopPlayback(uint32_t deviceh)
Start the playback feature for the specified device.
oko_res_type oko_DeviceGetChecksumUsage(uint32_t deviceh, bool *use_checksum)
Get the checksum usage flag of the current device.
oko_res_type oko_DeviceGetPortName(uint32_t deviceh, char *port)
Get the Port Name of the specified device.
oko_res_type oko_DeviceGetChecksumAvailable(uint32_t deviceh, bool *checksum)
Check if the communication protocol of the specified device supports checksum.
oko_res_type oko_DeviceSetChecksumUsage(uint32_t deviceh, bool use_checksum)
Set the checksum usage flag of the current device.
oko_res_type oko_DeviceConnectionStatus(uint32_t deviceh, uint32_t *conn)
Get the connection status of the current device.
_oko_res_type
Specifies the return values.
Definition: okolib.h:394
enum _oko_res_type oko_res_type
Specifies the return values.
@ OKO_ERR_PORT_NOTVALID
Port not valid.
Definition: okolib.h:404
@ OKO_ERR_DEV_SLAVE
Slave device.
Definition: okolib.h:411
@ OKO_ERR_FAIL
A system error occurred while executing the operation.
Definition: okolib.h:398
@ OKO_ERR_DEV_NOTFOUND
Device not found.
Definition: okolib.h:407
@ OKO_ERR_MODULE_NOTFOUND
Module specified not found.
Definition: okolib.h:410
@ OKO_ERR_MEMORY
Memory allocation failed.
Definition: okolib.h:413
@ OKO_ERR_PROP_NOTFOUND
Property not found.
Definition: okolib.h:406
@ OKO_ERR_CLOSED
The specified device is not opened.
Definition: okolib.h:400
@ OKO_ERR_NOTSUPP
The requested operation is not supported by this system or device.
Definition: okolib.h:399
@ OKO_ERR_COMM
Communication error.
Definition: okolib.h:408
@ OKO_ERR_ENUM_NOTFOUND
Enum of the Property not found.
Definition: okolib.h:409
@ OKO_ERR_TIMEOUT
Timeout error.
Definition: okolib.h:414
@ OKO_ERR_DB_OPEN
Database error on open.
Definition: okolib.h:405
@ OKO_ERR_ARG
Invalid arguments were passed to the function.
Definition: okolib.h:397
@ OKO_ERR_UNCONN
The specified device is not connected.
Definition: okolib.h:401
@ OKO_OK
Operation completed successfully.
Definition: okolib.h:395
@ OKO_ERR_UNDEF
Undefined error.
Definition: okolib.h:415
@ OKO_ERR_UNINIT
Library not initialized yet.
Definition: okolib.h:396
@ OKO_ERR_PORT_BUSY
Serial port busy.
Definition: okolib.h:402
@ OKO_ERR_PORT_CFG
Port configuration failed.
Definition: okolib.h:403
@ OKO_ERR_DEV_NOTRUNNING
Device not running.
Definition: okolib.h:412
oko_res_type oko_LibGetLastError(char *errmsg, unsigned int maxsize)
Return a text message that describes the error for the most recent failed call on general library fun...
oko_res_type oko_LibGetSuggestedUSBOnly(bool *use)
Get the usage status of the USB serial ports filter.
oko_res_type oko_LibSetSuggestedUSBOnly(bool use)
Turn on/off the filter on the USB serial ports.
oko_res_type oko_LibGetVersion(char *version)
Print the version of Okolib library on a string passed by reference.
oko_res_type oko_LibShutDown()
Deallocates any resource that were allocated by oko_LibInitialize.
oko_res_type oko_LibInit(const char *db_path)
Initialize the library.
oko_res_type oko_ModuleGetCurrentValue(oko_module_type module, double *current_value)
Returns current value of the specified module.
oko_res_type oko_ModulesDetect(uint32_t max_num, oko_module_type *modules, uint32_t *detected_num)
Detect available modules and open them, returning the type for each module.
oko_res_type oko_ModuleGetDetails(oko_module_type module, char *name, char *dim_unit, bool *can_disable)
Returns all information related to the specified module of this device, which is not changing during ...
oko_res_type oko_ModuleGetLimits(oko_module_type module, double *min_value, double *max_value)
Returns setpoint limits of the specified module of this device.
oko_res_type oko_ModuleGetSetpointValue(oko_module_type module, double *setpoint_value)
Returns setpoint value of the specified module of this device.
oko_res_type oko_ModuleSetSetpointValue(oko_module_type module, double setpoint_value)
Set setpoint of the specified module of this device.
oko_res_type oko_ModulesDetectSelected(const oko_module_type *selected_modules, uint32_t selected_modules_num, oko_module_type *modules, uint32_t *detected_num)
Detect available modules and open them, returning the type for each module.
oko_res_type oko_ModuleSetEnabled(oko_module_type module, bool enabled)
Set enable status of the specified module of this device.
_oko_module_type
Specifies the available modules types.
Definition: okolib.h:494
enum _oko_module_type oko_module_type
Specifies the available modules types.
oko_res_type oko_ModuleGetEnabled(oko_module_type module, bool *enabled)
Returns enable status of the specified module of this device.
@ OKO_MODULE_HMD
Humidity module.
Definition: okolib.h:498
@ OKO_MODULE_MAXNUM
Number of available modules.
Definition: okolib.h:499
@ OKO_MODULE_TEMP
Temperature module.
Definition: okolib.h:495
@ OKO_MODULE_CO2
CO2 module.
Definition: okolib.h:496
@ OKO_MODULE_O2
O2 module.
Definition: okolib.h:497
oko_res_type oko_LibGetPortNames(char **names)
Refresh available ports and return their names.
oko_res_type oko_DevicesDetect(uint32_t max_num, uint32_t *devicesh, uint32_t *detected_num)
Detect available devices and open them, returning an handle for each device.
oko_res_type oko_DevicesCloseAll(void)
Close all the opened devices.
oko_res_type oko_DeviceClose(uint32_t deviceh)
Close the specified device.
oko_res_type oko_LibGetNumberOfPorts(uint32_t *count)
Refresh available ports and return the number of them.
oko_res_type oko_DeviceDetectSingleByName(uint32_t *deviceh, char *name_filter)
Detect the first available device matching the filter name and open it, returning a handle for it.
oko_res_type oko_LibGetPortName(uint32_t portidx, char *portname)
Get the name of the specified port, using the ports refreshed by oko_LibGetNumberOfPorts.
oko_res_type oko_DeviceDetectSingle(uint32_t *deviceh)
Detect the first available device and open it, returning a handle for it.
oko_res_type oko_DevicesDetectByName(uint32_t max_num, uint32_t *devicesh, char *name_filter, uint32_t *detected_num)
Detect the first available device matching the filter name and open it, returning a handle for it.
oko_res_type oko_DeviceOpen(const char *port, uint32_t *deviceh)
Open the specified device, returning a handle for it.
oko_res_type oko_DeviceGetLastError(uint32_t deviceh, char *errmsg, unsigned int maxsize)
Return a text message that describes the error for the most recent failed call on a specified device.
oko_res_type oko_PropertyAutoUpdate(uint32_t deviceh, const char *name, uint32_t freq_ms)
Set the update frequency to read the specified property value from the current device.
oko_res_type oko_PropertyGetName(uint32_t deviceh, uint32_t index, char *name)
Get the name of the specified property, using its index.
_oko_write_type
Specifies the available write types.
Definition: okolib.h:890
oko_res_type oko_PropertyGetWriteOnly(uint32_t deviceh, const char *name, bool *write_only)
Verify if the specified property is write-only.
_oko_prop_type
Specifies the available property types.
Definition: okolib.h:806
oko_res_type oko_PropertyGetDescription(uint32_t deviceh, const char *name, char *desc)
Get the description of the specified property.
enum _oko_prop_type oko_prop_type
Specifies the available property types.
oko_res_type oko_PropertyHasLimits(uint32_t deviceh, const char *name, bool *has_limits)
Verify if the specified property has readable limits.
oko_res_type oko_PropertiesGetNumber(uint32_t deviceh, uint32_t *num)
Get the number of available properties of the current device.
oko_res_type oko_PropertyGetType(uint32_t deviceh, const char *name, oko_prop_type *prop_type)
Get the type of the specified property.
oko_res_type oko_PropertyGetUnit(uint32_t deviceh, const char *name, char *unit)
Get the measure unit of the specified property.
oko_res_type oko_PropertyGetWriteType(uint32_t deviceh, const char *name, oko_write_type *write_type)
Get the write type of the specified property.
oko_res_type oko_PropertyIsAdvanced(uint32_t deviceh, const char *name, bool *is_adv)
Verify if the specified property is an advanced feature of the device.
oko_res_type oko_PropertyGetEnumName(uint32_t deviceh, const char *name, uint32_t enum_val, char *enum_name)
Get the name of a given enum value of the specified property.
oko_res_type oko_PropertyGetLimits(uint32_t deviceh, const char *name, double *min, double *max)
Get the minimum and maximum value that can be set for the specified property.
oko_res_type oko_PropertyGetEnumNumber(uint32_t deviceh, const char *name, unsigned int *num)
Get the number of available enum values of the specified property.
oko_res_type oko_PropertyIsMain(uint32_t deviceh, const char *name, bool *is_main)
Verify if the specified property is a main feature of the device.
enum _oko_write_type oko_write_type
Specifies the available write types.
oko_res_type oko_PropertyGetReadOnly(uint32_t deviceh, const char *name, bool *read_only)
Verify if the specified property is read-only.
@ OKO_WRITE_NONE
No write available (read-only)
Definition: okolib.h:891
@ OKO_WRITE_EEPROM
Only standard write is available.
Definition: okolib.h:892
@ OKO_WRITE_BOTH
Standard and volatile write types are available.
Definition: okolib.h:894
@ OKO_WRITE_VOLATILE
Only volatile write is available.
Definition: okolib.h:893
@ OKO_PROP_INT
Integer (long) property type.
Definition: okolib.h:809
@ OKO_PROP_ENUM
Enum property type.
Definition: okolib.h:811
@ OKO_PROP_DOUBLE
Double property type.
Definition: okolib.h:810
@ OKO_PROP_UNDEF
Undefined property type.
Definition: okolib.h:807
@ OKO_PROP_STRING
String property type.
Definition: okolib.h:808
oko_res_type oko_PropertyReadString(uint32_t deviceh, const char *name, char *val)
Get the current value of a string property.
oko_res_type oko_PropertyUpdate(uint32_t deviceh, const char *name)
Update the specified property value, reading it from the current device.
oko_res_type oko_PropertyReadDouble(uint32_t deviceh, const char *name, double *val)
Get the current value of a double property.
oko_res_type oko_PropertyReadInt(uint32_t deviceh, const char *name, int32_t *val)
Get the current value of a integer property.
oko_res_type oko_PropertyWriteDouble(uint32_t deviceh, const char *name, double val, char async)
Change the current value of the specified double property.
oko_res_type oko_PropertyWriteVolatileDouble(uint32_t deviceh, const char *name, double val, char async)
Change the current value of the specified double property in the volatile memory.
oko_res_type oko_PropertyWriteInt(uint32_t deviceh, const char *name, int32_t val, char async)
Change the current value of the specified integer property.
oko_res_type oko_PropertyWriteVolatileInt(uint32_t deviceh, const char *name, int32_t val, char async)
Change the current value of the specified integer property in the volatile memory.
oko_res_type oko_PropertyWriteVolatileString(uint32_t deviceh, const char *name, const char *val, bool async)
Change the current value of the specified string property in the volatile memory.
oko_res_type oko_PropertyWriteString(uint32_t deviceh, const char *name, const char *val, bool async)
Change the current value of the specified string property.