OkoLib
library for accessing Okolab devices
okolib.h
1 
336 #ifndef _OKOLIB_H_
337 #define _OKOLIB_H_
338 
339 #ifdef _MSC_VER
340  #if _MSC_VER >= 1600
341  #include <stdint.h>
342  #else
343  typedef __int8 int8_t;
344  typedef __int16 int16_t;
345  typedef __int32 int32_t;
346  typedef __int64 int64_t;
347  typedef unsigned __int8 uint8_t;
348  typedef unsigned __int16 uint16_t;
349  typedef unsigned __int32 uint32_t;
350  typedef unsigned __int64 uint64_t;
351  #endif
352 #elif __GNUC__ >= 3
353  #include <stdint.h>
354 #endif
355 
356 
357 
358 
359 #ifdef __cplusplus
360 extern "C" {
361 #endif
362 
363 #ifdef _WIN32
364 
365 #if defined(OKO_NO_DLL) /* Static import */
366 # define OKO_API
367 #elif defined(OKO_BUILDING_DLL) /* DLL export */
368 # define OKO_API __declspec (dllexport)
369 #else /* DLL import */
370 # define OKO_API __declspec (dllimport)
371 #endif /* Not BUILDING_DLL */
372 
373 /* Define calling convention in one place, for convenience. */
374 #define OKO_EXPORT __cdecl
375 
376 /* Microsoft VBA */
377 #ifdef OKO_VBA
378 #undef OKO_EXPORT
379 #define OKO_EXPORT __stdcall
380 #endif
381 
382 #else /* _WIN32 not defined. */
383 
384 /* Define with no value on non-Windows OSes. */
385 #define OKO_API
386 #define OKO_EXPORT
387 
388 #endif
389 
396 typedef enum _oko_res_type
397 {
398  OKO_OK = 0,
400  OKO_ERR_ARG = -2,
411  OKO_ERR_COMM = -13,
418  OKO_ERR_UNDEF = -999,
420 
434 OKO_API oko_res_type OKO_EXPORT
435 #ifdef __LINUX__
436 oko_LibInit(char *db_path);
437 #else
438 oko_LibInit(const char *db_path);
439 #endif
440 
445 OKO_API oko_res_type OKO_EXPORT
447 
453 OKO_API oko_res_type OKO_EXPORT
454 oko_LibGetVersion(char *version);
455 
463 OKO_API oko_res_type OKO_EXPORT
464 oko_LibGetLastError(char *errmsg, unsigned int maxsize);
465 
466 
472 OKO_API oko_res_type OKO_EXPORT
474 
475 
481 OKO_API oko_res_type OKO_EXPORT
483 
484 
485 
486 
496 typedef enum _oko_module_type
497 {
504 
505 
513 OKO_API oko_res_type OKO_EXPORT
514 oko_ModulesDetect(uint32_t max_num, oko_module_type *modules, uint32_t *detected_num);
515 
525 OKO_API oko_res_type OKO_EXPORT
527  uint32_t selected_modules_num, oko_module_type *modules, uint32_t *detected_num);
528 
538 OKO_API oko_res_type OKO_EXPORT
539 oko_ModuleGetDetails(oko_module_type module, char *name, char *dim_unit, bool *can_disable);
540 
547 OKO_API oko_res_type OKO_EXPORT
548 oko_ModuleGetCurrentValue(oko_module_type module, double *current_value);
549 
556 OKO_API oko_res_type OKO_EXPORT
557 oko_ModuleGetSetpointValue(oko_module_type module, double *setpoint_value);
558 
566 OKO_API oko_res_type OKO_EXPORT
567 oko_ModuleGetLimits(oko_module_type module, double *min_value, double *max_value);
568 
575 OKO_API oko_res_type OKO_EXPORT
576 oko_ModuleSetSetpointValue(oko_module_type module, double setpoint_value);
577 
586 OKO_API oko_res_type OKO_EXPORT
587 oko_ModuleGetEnabled(oko_module_type module, bool *enabled);
588 
611 OKO_API oko_res_type OKO_EXPORT
612 oko_ModuleSetEnabled(oko_module_type module, bool enabled);
613 
625 OKO_API oko_res_type OKO_EXPORT
626 oko_LibGetNumberOfPorts(uint32_t *count);
627 
633 OKO_API oko_res_type OKO_EXPORT
634 oko_LibGetPortNames(char **names);
635 
644 OKO_API oko_res_type OKO_EXPORT
645 oko_LibGetPortName(uint32_t portidx, char *portname);
646 
653 OKO_API oko_res_type OKO_EXPORT
654 oko_DeviceOpen(const char *port, uint32_t *deviceh);
655 
663 OKO_API oko_res_type OKO_EXPORT
664 oko_DevicesDetect(uint32_t max_num, uint32_t *devicesh, uint32_t *detected_num);
665 
666 
675 OKO_API oko_res_type OKO_EXPORT
676 oko_DevicesDetectByName(uint32_t max_num, uint32_t *devicesh, char *name_filter, uint32_t *detected_num);
677 
678 
684 OKO_API oko_res_type OKO_EXPORT
685 oko_DeviceDetectSingle(uint32_t *deviceh);
686 
687 
694 OKO_API oko_res_type OKO_EXPORT
695 oko_DeviceDetectSingleByName(uint32_t *deviceh, char *name_filter);
696 
697 
703 OKO_API oko_res_type OKO_EXPORT
704 oko_DeviceClose(uint32_t deviceh);
705 
714 OKO_API oko_res_type OKO_EXPORT
715 oko_DeviceGetLastError(uint32_t deviceh, char *errmsg, unsigned int maxsize);
716 
721 OKO_API oko_res_type OKO_EXPORT
723 
735 OKO_API oko_res_type OKO_EXPORT
736 oko_DeviceGetPortName(uint32_t deviceh, char *port);
737 
738 
745 OKO_API oko_res_type OKO_EXPORT
746 oko_DeviceConnectionStatus(uint32_t deviceh, uint32_t *conn);
747 
748 
755 OKO_API oko_res_type OKO_EXPORT
756 oko_DeviceSetChecksumUsage(uint32_t deviceh, bool use_checksum);
757 
758 
765 OKO_API oko_res_type OKO_EXPORT
766 oko_DeviceGetChecksumUsage(uint32_t deviceh, bool *use_checksum);
767 
775 OKO_API oko_res_type OKO_EXPORT
776 oko_DeviceGetChecksumAvailable(uint32_t deviceh, bool *checksum);
777 
790 OKO_API oko_res_type OKO_EXPORT
791 oko_PropertiesGetNumber(uint32_t deviceh, uint32_t *num);
792 
802 OKO_API oko_res_type OKO_EXPORT
803 oko_PropertyGetName(uint32_t deviceh, uint32_t index, char *name);
804 
808 typedef enum _oko_prop_type
809 {
816 
817 
825 OKO_API oko_res_type OKO_EXPORT
826 oko_PropertyGetType(uint32_t deviceh, const char *name, oko_prop_type *prop_type);
827 
828 
836 OKO_API oko_res_type OKO_EXPORT
837 oko_PropertyGetEnumNumber(uint32_t deviceh, const char *name, unsigned int *num);
838 
839 
840 
854 OKO_API oko_res_type OKO_EXPORT
855 oko_PropertyGetEnumName(uint32_t deviceh, const char *name, uint32_t enum_val, char *enum_name);
856 
857 
858 
866 OKO_API oko_res_type OKO_EXPORT
867 oko_PropertyGetUnit(uint32_t deviceh, const char *name, char *unit);
868 
876 OKO_API oko_res_type OKO_EXPORT
877 oko_PropertyGetDescription(uint32_t deviceh, const char *name, char *desc);
878 
886 OKO_API oko_res_type OKO_EXPORT
887 oko_PropertyGetReadOnly(uint32_t deviceh, const char *name, bool *read_only);
888 
892 typedef enum _oko_write_type
893 {
899 
900 
908 OKO_API oko_res_type OKO_EXPORT
909 oko_PropertyGetWriteOnly(uint32_t deviceh, const char *name, bool *write_only);
910 
918 OKO_API oko_res_type OKO_EXPORT
919 oko_PropertyGetWriteType(uint32_t deviceh, const char *name, oko_write_type *write_type);
920 
921 
931 OKO_API oko_res_type OKO_EXPORT
932 oko_PropertyHasLimits(uint32_t deviceh, const char *name, bool *has_limits);
933 
943 OKO_API oko_res_type OKO_EXPORT
944 oko_PropertyGetLimits(uint32_t deviceh, const char *name, double *min, double *max);
945 
953 OKO_API oko_res_type OKO_EXPORT
954 oko_PropertyIsMain(uint32_t deviceh, const char *name, bool *is_main);
955 
965 OKO_API oko_res_type OKO_EXPORT
966 oko_PropertyIsAdvanced(uint32_t deviceh, const char *name, bool *is_adv);
967 
983 OKO_API oko_res_type OKO_EXPORT
984 oko_PropertyReadString(uint32_t deviceh, const char *name, char *val);
985 
994 OKO_API oko_res_type OKO_EXPORT
995 oko_PropertyReadInt(uint32_t deviceh, const char *name, int32_t *val);
996 
1005 OKO_API oko_res_type OKO_EXPORT
1006 oko_PropertyReadDouble(uint32_t deviceh, const char *name, double *val);
1007 
1014 OKO_API oko_res_type OKO_EXPORT
1015 oko_PropertyUpdate(uint32_t deviceh, const char *name); // refresh, read ?
1016 
1032 OKO_API oko_res_type OKO_EXPORT
1033 oko_PropertyWriteString(uint32_t deviceh, const char *name, const char *val, bool async);
1034 
1044 OKO_API oko_res_type OKO_EXPORT
1045 oko_PropertyWriteInt(uint32_t deviceh, const char *name, int32_t val, char async);
1046 
1056 OKO_API oko_res_type OKO_EXPORT
1057 oko_PropertyWriteDouble(uint32_t deviceh, const char *name, double val, char async);
1058 
1068 OKO_API oko_res_type OKO_EXPORT
1069 oko_PropertyWriteVolatileString(uint32_t deviceh, const char *name, const char *val, bool async);
1070 
1080 OKO_API oko_res_type OKO_EXPORT
1081 oko_PropertyWriteVolatileInt(uint32_t deviceh, const char *name, int32_t val, char async);
1082 
1092 OKO_API oko_res_type OKO_EXPORT
1093 oko_PropertyWriteVolatileDouble(uint32_t deviceh, const char *name, double val, char async);
1094 
1108 OKO_API oko_res_type OKO_EXPORT
1109 oko_PropertyAutoUpdate(uint32_t deviceh, const char *name, uint32_t freq_ms);
1110 
1124 OKO_API oko_res_type OKO_EXPORT
1125 oko_StartPropertyLogging(uint32_t deviceh, const char *filename, uint32_t freq_ms);
1126 
1132 OKO_API oko_res_type OKO_EXPORT
1133 oko_StopPropertyLogging(uint32_t deviceh);
1134 
1141 OKO_API oko_res_type OKO_EXPORT
1142 oko_PropertyLoggingGetFileName(uint32_t deviceh, char *filename);
1143 
1156 OKO_API oko_res_type OKO_EXPORT
1157 oko_StartPlayback(uint32_t deviceh, const char *filename);
1158 
1164 OKO_API oko_res_type OKO_EXPORT
1165 oko_StopPlayback(uint32_t deviceh);
1166 
1173 OKO_API oko_res_type OKO_EXPORT
1174 oko_PlaybakGetFileName(uint32_t deviceh, char *filename);
1175 
1189 OKO_API oko_res_type OKO_EXPORT
1190 oko_CommandExecute(uint32_t deviceh, const char *name);
1191 
1192 
1194 OKO_API oko_res_type OKO_EXPORT
1195 oko_OkolabSetDebugPropertiesUsage(bool debug_properties);
1196 
1197 OKO_API oko_res_type OKO_EXPORT
1198 oko_OkolabGetLastProtocolError(uint32_t deviceh, const char *name, int *err);
1205 #ifdef __cplusplus
1206 }
1207 #endif
1208 
1209 #endif /* _OKOLIB_H_ */
1210 
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:397
enum _oko_res_type oko_res_type
Specifies the return values.
@ OKO_ERR_PORT_NOTVALID
Port not valid.
Definition: okolib.h:407
@ OKO_ERR_DEV_SLAVE
Slave device.
Definition: okolib.h:414
@ OKO_ERR_FAIL
A system error occurred while executing the operation.
Definition: okolib.h:401
@ OKO_ERR_DEV_NOTFOUND
Device not found.
Definition: okolib.h:410
@ OKO_ERR_MODULE_NOTFOUND
Module specified not found.
Definition: okolib.h:413
@ OKO_ERR_MEMORY
Memory allocation failed.
Definition: okolib.h:416
@ OKO_ERR_PROP_NOTFOUND
Property not found.
Definition: okolib.h:409
@ OKO_ERR_CLOSED
The specified device is not opened.
Definition: okolib.h:403
@ OKO_ERR_NOTSUPP
The requested operation is not supported by this system or device.
Definition: okolib.h:402
@ OKO_ERR_COMM
Communication error.
Definition: okolib.h:411
@ OKO_ERR_ENUM_NOTFOUND
Enum of the Property not found.
Definition: okolib.h:412
@ OKO_ERR_TIMEOUT
Timeout error.
Definition: okolib.h:417
@ OKO_ERR_DB_OPEN
Database error on open.
Definition: okolib.h:408
@ OKO_ERR_ARG
Invalid arguments were passed to the function.
Definition: okolib.h:400
@ OKO_ERR_UNCONN
The specified device is not connected.
Definition: okolib.h:404
@ OKO_OK
Operation completed successfully.
Definition: okolib.h:398
@ OKO_ERR_UNDEF
Undefined error.
Definition: okolib.h:418
@ OKO_ERR_UNINIT
Library not initialized yet.
Definition: okolib.h:399
@ OKO_ERR_PORT_BUSY
Serial port busy.
Definition: okolib.h:405
@ OKO_ERR_PORT_CFG
Port configuration failed.
Definition: okolib.h:406
@ OKO_ERR_DEV_NOTRUNNING
Device not running.
Definition: okolib.h:415
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:497
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:501
@ OKO_MODULE_MAXNUM
Number of available modules.
Definition: okolib.h:502
@ OKO_MODULE_TEMP
Temperature module.
Definition: okolib.h:498
@ OKO_MODULE_CO2
CO2 module.
Definition: okolib.h:499
@ OKO_MODULE_O2
O2 module.
Definition: okolib.h:500
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:893
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:809
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:894
@ OKO_WRITE_EEPROM
Only standard write is available.
Definition: okolib.h:895
@ OKO_WRITE_BOTH
Standard and volatile write types are available.
Definition: okolib.h:897
@ OKO_WRITE_VOLATILE
Only volatile write is available.
Definition: okolib.h:896
@ OKO_PROP_INT
Integer (long) property type.
Definition: okolib.h:812
@ OKO_PROP_ENUM
Enum property type.
Definition: okolib.h:814
@ OKO_PROP_DOUBLE
Double property type.
Definition: okolib.h:813
@ OKO_PROP_UNDEF
Undefined property type.
Definition: okolib.h:810
@ OKO_PROP_STRING
String property type.
Definition: okolib.h:811
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.