OkoLib
library for accessing Okolab devices
Opening, closing and detecting devices

Functions

oko_res_type oko_LibGetNumberOfPorts (uint32_t *count)
 Refresh available ports and return the number of them. More...
 
oko_res_type oko_LibGetPortNames (char **names)
 Refresh available ports and return their names. More...
 
oko_res_type oko_LibGetPortName (uint32_t portidx, char *portname)
 Get the name of the specified port, using the ports refreshed by oko_LibGetNumberOfPorts. More...
 
oko_res_type oko_DeviceOpen (const char *port, uint32_t *deviceh)
 Open the specified device, returning a handle for it. More...
 
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. More...
 
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. More...
 
oko_res_type oko_DeviceDetectSingle (uint32_t *deviceh)
 Detect the first available device and open it, returning a handle for it. More...
 
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. More...
 
oko_res_type oko_DeviceClose (uint32_t deviceh)
 Close the specified device. More...
 
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. More...
 
oko_res_type oko_DevicesCloseAll (void)
 Close all the opened devices. More...
 

Detailed Description

Function Documentation

oko_res_type oko_DeviceClose ( uint32_t  deviceh)

Close the specified device.

Parameters
[in]devicehA valid device handle.
Returns
OKO_OK upon success, an error code otherwise.
oko_res_type oko_DeviceDetectSingle ( uint32_t *  deviceh)

Detect the first available device and open it, returning a handle for it.

Parameters
[out]devicehThe device handle.
Returns
OKO_OK upon success, an error code otherwise.
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.

Parameters
[out]devicehThe device handle.
[in]name_filterThe filter on the product name (Product.name)
Returns
OKO_OK upon success, an error code otherwise.
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.

Parameters
[in]devicehA valid device handle.
[out]errmsgA pointer to a valid string, pre-allocated by the caller, where the error message will be stored in.
[in]maxsizeMaximum size of the error message. If bigger, the message will be truncated.
Returns
OKO_OK upon success, an error code otherwise.
oko_res_type oko_DeviceOpen ( const char *  port,
uint32_t *  deviceh 
)

Open the specified device, returning a handle for it.

Parameters
[in]portThe serial port name (eg. 'COM1' on Windows and '/dev/ttyS0' on Linux).
[out]devicehThe device handle.
Returns
OKO_OK upon success, an error code otherwise.
oko_res_type oko_DevicesCloseAll ( void  )

Close all the opened devices.

Returns
OKO_OK upon success, an error code otherwise.
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.

Parameters
[in]max_numThe max number of devices to detect.
[out]deviceshArray of handles to the detected devices.
[out]detected_numnumber of detected devices. It is the length of devicesh array.
Returns
OKO_OK upon success, an error code otherwise.
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.

Parameters
[in]max_numThe max number of devices to detect.
[out]deviceshArray of handles to the detected devices.
[in]name_filterThe filter on the product name (Product.name). If void no filter will be applied on the name.
[out]detected_numnumber of detected devices. It is the length of devicesh array.
Returns
OKO_OK upon success, an error code otherwise.
oko_res_type oko_LibGetNumberOfPorts ( uint32_t *  count)

Refresh available ports and return the number of them.

Parameters
[out]countnumber of available ports
Returns
OKO_OK upon success, an error code otherwise.
oko_res_type oko_LibGetPortName ( uint32_t  portidx,
char *  portname 
)

Get the name of the specified port, using the ports refreshed by oko_LibGetNumberOfPorts.

Parameters
[in]portidxzero-based port index
[out]portnamethe specified port name, pre-allocated by the caller.
Returns
OKO_OK upon success, an error code otherwise.
Note
It does not refresh available ports, so oko_LibGetNumberOfPorts needs to be called first
oko_res_type oko_LibGetPortNames ( char **  names)

Refresh available ports and return their names.

Parameters
[out]namesarray of names, pre-allocated by the caller
Returns
OKO_OK upon success, an error code otherwise.