liblabpro
Portable C library for data collection from Vernier LabPro devices
liblabpro.h
Go to the documentation of this file.
1 /* liblabpro, a C library for using Vernier LabPro devices.
2  * Based on the original FreeLab Ruby implementation by Ben Crowell.
3  *
4  * * www.lightandmatter.com/freelab
5  * * liblabpro.sf.net
6  *
7  * Copyright (C) 2018 Matthew Trescott <matthewtrescott@gmail.com>
8  *
9  * liblabpro is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * liblabpro is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with liblabpro. If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23 
52 #pragma once
53 #include <stdbool.h>
54 #include <libusb-1.0/libusb.h>
55 
62 
65 
68 
71 
74 
78 
81 
86 
98 };
99 
107 };
108 
125 };
126 
136  LABPRO_CHANOP_VOLTAGE10V, // Range from -10V to +10V. Same for period, frequency, and transitions ops below.
172 };
173 
201 };
215 };
224 };
241 };
242 
251 
254 
257 
262 
267 
273 
279 
285 
290 };
291 
298  LABPRO_ERR_USB_IO = LIBUSB_ERROR_IO,
299  LABPRO_ERR_USB_ACCESS = LIBUSB_ERROR_ACCESS,
300  LABPRO_ERR_USB_NO_DEVICE = LIBUSB_ERROR_NO_DEVICE,
301  LABPRO_ERR_USB_PIPE = LIBUSB_ERROR_PIPE,
302  LABPRO_ERR_USB_INTERRUPTED = LIBUSB_ERROR_INTERRUPTED,
303  LABPRO_ERR_USB_NO_MEM = LIBUSB_ERROR_NO_MEM,
304  LABPRO_ERR_USB_OTHER = LIBUSB_ERROR_OTHER
305 };
306 
310 typedef struct {
311  libusb_context *usb_link;
313 
317 typedef struct {
318  libusb_device_handle *device_handle;
319 
321  bool is_open;
322 
328  bool is_busy;
329 
336 
342 
344  unsigned char in_endpt_addr;
345 
347  unsigned char out_endpt_addr;
348 
350  unsigned int timeout;
351 
356  char software_id[7];
358  enum LabPro_Battery_Level battery_level;
359 
360 } LabPro;
361 
365 typedef struct {
367  unsigned short num;
368 
370  LabPro *labpros[5];
371 } LabPro_List;
372 
389 typedef struct {
391  enum LabPro_Channels channel;
392 
398 
412 
423  enum LabPro_Analog_PostProc postproc;
424 
442  enum LabPro_Sampling_Modes sampling_mode;
443 
449 
458 int LabPro_init(LabPro_Context* context);
459 
463 void LabPro_exit(LabPro_Context* context);
464 
478 
487 void LabPro_close_labpro(LabPro* labpro);
488 
501 int LabPro_reset(LabPro* labpro, bool force);
502 
514 int LabPro_check_data_session(LabPro_Data_Session* session, int** errors);
515 
535 int LabPro_send_raw(LabPro* labpro, char* command, int* length_transferred);
536 
560 int LabPro_read_raw(LabPro* labpro, char** string, int* length);
561 
573 int LabPro_trim_response(char* string);
574 
Have the LabPro store all the datapoints in RAM and wait for a "get" command to transfer them...
Definition: liblabpro.h:221
LabPro_Battery_Level
Battery levels reported by the LabPro.
Definition: liblabpro.h:103
Return distance, velocity, and acceleration in m, m/s, and m/(s^2), plus delta t. If used with non-re...
Definition: liblabpro.h:198
Used when e.g. resetting all channels at once.
Definition: liblabpro.h:114
The LabPro is currently collecting data.
Definition: liblabpro.h:234
LabPro_System_Status
LabPro system status.
Definition: liblabpro.h:228
The LabPro is waiting for a command.
Definition: liblabpro.h:230
Measure the signal frequency on a ±10 V signal. Channel 1 only.
Definition: liblabpro.h:144
unsigned int timeout
How long libusb waits before timing out on a transfer. Default is 5000.
Definition: liblabpro.h:350
unsigned short num
Number of available LabPros. Max is 5.
Definition: liblabpro.h:367
Return distance in meters and change in time since last measurement Fun fact: the manual states that ...
Definition: liblabpro.h:182
Higher-precision voltage measurement I assume this is just like the ±10 V measurement, but more precise due to the smaller range.
Definition: liblabpro.h:171
void LabPro_exit(LabPro_Context *context)
De-initialize liblabpro.
Definition: liblabpro.c:59
int LabPro_init(LabPro_Context *context)
Initialize liblabpro. Currently just a wrapper around libusb_init().
Definition: liblabpro.c:46
bool is_collecting_data
Whether data is currently being collected. This doesn&#39;t determine whether we should be sending comman...
Definition: liblabpro.h:341
void LabPro_handle_device_disconnect(LabPro *labpro)
Definition: liblabpro.c:359
libusb_device_handle * device_handle
Definition: liblabpro.h:318
Count signal transitions on a ±10 V signal. Channel 1 only.
Definition: liblabpro.h:146
LabPro_Sonic_Chan_Operations
Operations for sonic channels.
Definition: liblabpro.h:177
The LabPro is watching for a trigger condition to start collecting data.
Definition: liblabpro.h:232
Turn the channel off.
Definition: liblabpro.h:132
Measure resistance.
Definition: liblabpro.h:140
Set data collection rate and time, etc.
Definition: liblabpro.h:67
The underlying libusb_device is not open.
Definition: liblabpro.h:256
Struct acting as an array of LabPros.
Definition: liblabpro.h:365
Clear RAM and reset the LabPro.
Definition: liblabpro.h:61
Get a single point of data outside of active data collection.
Definition: liblabpro.h:83
void LabPro_close_labpro(LabPro *labpro)
Close the LabPro.
Definition: liblabpro.c:180
Have the LabPro send datapoints as they&#39;re collected without storing them.
Definition: liblabpro.h:223
LabPro_Errors
Errors related to the "front-end" These errors are specific to use of the LabPro and are positive int...
Definition: liblabpro.h:248
LabPro_USB_Errors
Some errorcodes from libusb These are error codes that might be returned by LabPro_read_raw() or LabP...
Definition: liblabpro.h:297
LabPro_List LabPro_list_labpros(LabPro_Context *context)
Obtain a list connected LabPro devices.
Definition: liblabpro.c:63
Set up a manual conversion equation rather than one obtained by Auto-ID.
Definition: liblabpro.h:70
The LabPro is initializing.
Definition: liblabpro.h:240
bool is_busy
Whether there is a pending transfer request. Some commands do not return data so it&#39;s OK to send them...
Definition: liblabpro.h:328
LabPro_Channels
Channel ports on the LabPro interface.
Definition: liblabpro.h:112
Calculate d/dt and d^2/dt^2. Only allowed in non-real-time mode.
Definition: liblabpro.h:214
Return distance in meters, velocity in m/s, and delta t. If used with non-real-time mode sampling...
Definition: liblabpro.h:190
Range from -10 V to +10 V.
Definition: liblabpro.h:136
See LABPRO_DISTANCE_VELOCITY_ACCEL_AND_DT_METERS.
Definition: liblabpro.h:200
LabPro_Analog_Chan_Operations
Operations for analog channels.
Definition: liblabpro.h:130
Measure temperature (Fahrenheit) from the TI Temperature probe This is for measuring temperature in F...
Definition: liblabpro.h:160
int errorcode
Definition: liblabpro.h:357
The post-processing was set to a nonzero value on a realtime capture. This is not allowed...
Definition: liblabpro.h:289
The LabPro is waiting for a "get" command to fetch the collected data.
Definition: liblabpro.h:236
bool use_sonic_temp_compensation
Definition: liblabpro.h:446
The LabPro&#39;s self-test is running.
Definition: liblabpro.h:238
Measure temperature (Celsius) from the TI Temperature probe This is for measuring temperature in Cels...
Definition: liblabpro.h:153
The LabPro is transferring data, so we cannot send a command that requires a response from the LabPro...
Definition: liblabpro.h:261
int LabPro_trim_response(char *string)
Trim trailing junk that the LabPro sent Since the LabPro always returns data in multiples of 64 bytes...
Definition: liblabpro.c:350
Select channels and units for data collection.
Definition: liblabpro.h:64
int LabPro_reset(LabPro *labpro, bool force)
Send a reset command to the specified LabPro.
Definition: liblabpro.c:186
Calculate d/dt. Only allowed in non-real-time mode.
Definition: liblabpro.h:212
Measure the signal period on a ±10 V signal. Channel 1 only.
Definition: liblabpro.h:142
Presumably 0 Amps to 10 Amps.
Definition: liblabpro.h:138
liblabpro couldn&#39;t allocate memory.
Definition: liblabpro.h:253
Struct representing a LabPro device.
Definition: liblabpro.h:317
int LabPro_send_raw(LabPro *labpro, char *command, int *length_transferred)
Send a raw command to the LabPro.
Definition: liblabpro.c:225
Get a data point during non-realtime collection.
Definition: liblabpro.h:80
Measure light from the TI Light Sensor This is for the Texas Instruments light sensor. (I think) it causes the LabPro to return units of milliwatts per square centimeter, since that is what the CBL2 technical manual says its units are. However, it also states that this sensor Auto-IDs, so I&#39;m not sure this is necessary.
Definition: liblabpro.h:167
LabPro_Analog_PostProc
Post-processing performed on analog data. As with data collection from sonic channels, please calculate the derivatives in your application rather than making the LabPro compute them. The extra computations will raise the temperature of the LabPro and make its readings less accurate.
Definition: liblabpro.h:208
Thin wrapper around libusb_context.
Definition: liblabpro.h:310
char * sonic_temp_compensation_equation
Definition: liblabpro.h:447
Set parameters for what data points will be returned.
Definition: liblabpro.h:73
unsigned char out_endpt_addr
The USB "out" endpoint address.
Definition: liblabpro.h:347
int LabPro_check_data_session(LabPro_Data_Session *session, int **errors)
Check a data session for problems before running it on the LabPro.
Definition: liblabpro.c:204
Return distance in feet and change in time since last measurement.
Definition: liblabpro.h:184
bool is_open
Whether the underlying USB device handle is open.
Definition: liblabpro.h:321
Auto-ID the sensor; units can be fetched from the sensor&#39;s description.
Definition: liblabpro.h:134
Struct representing a "data session" Data sessions are an abstraction over the LabPro&#39;s command-orien...
Definition: liblabpro.h:389
libusb_context * usb_link
Definition: liblabpro.h:311
bool is_fastmode_running
In FastMode (20µs between samples), we cannot send any commands or we will interrupt the sampling...
Definition: liblabpro.h:335
Set various settings for the LabPro itself.
Definition: liblabpro.h:76
See LABPRO_DISTANCE_VELOCITY_AND_DT_METERS.
Definition: liblabpro.h:192
LabPro_Sampling_Modes
Sampling modes.
Definition: liblabpro.h:219
char * onboard_conversion_equation
Definition: liblabpro.h:445
unsigned char in_endpt_addr
The USB "in" endpoint address.
Definition: liblabpro.h:344
The post-processing was set to a nonzero value for a sonic data capture. For sonic data like from mot...
Definition: liblabpro.h:284
int LabPro_read_raw(LabPro *labpro, char **string, int *length)
Read raw bytes from the LabPro.
Definition: liblabpro.c:281
OK status.
Definition: liblabpro.h:250
Perform no post-processing. This is the only acceptable value in real-time mode.
Definition: liblabpro.h:210
LabPro_Commands
Commands that can be sent to the LabPro.
Definition: liblabpro.h:59