endaq.device Concepts and Quick Start Guide¶
Here are some concept summaries and common usage examples to help you get started with endaq.device.
Note
This documentation is in very early development.
Basic usage¶
Finding attached devices¶
An endaq.device “Hello World”:
>>> import endaq.device
>>> endaq.device.getDevices()
[<EndaqS S3-E25D40 "Example S3" SN:S0009468 (D:\)>]
Accessing basic recorder properties¶
Most common properties are read-only attributes of endaq.device.Recorder. getDevices() returns a list of
endaq.device.Recorder objects, each of which represents a connected device.
To access information about a single device, use indexing.
>>> dev = endaq.device.getDevices()[0]
>>> dev.name
'Example S3'
>>> dev.serial
'S0009468'
>>> dev.hardwareVersion
'2.0'
Some endaq.device.Recorder properties are identical to those of an
idelib.Dataset
(an imported recording file). These include:
sensors: The device’s sensors, a dictionary of idelib.Sensor objects.channels: The device’s Channels, a dictionary of idelib.Channel objects.transforms: The device’s data conversion and calibration polynomials, as idelib.transforms.Transform objects.
>>> dev.channels
{8: <Channel 8 '25g PE Acceleration': Acceleration (g)>, 80: <Channel 80 '40g DC Acceleration': Acceleration (g)>, 36: <Channel 36 'Pressure/Temperature': Pressure (Pa), Temperature (°C)>, 65: <Channel 65 'Absolute Orientation': Quaternion (q)>, 70: <Channel 70 'Relative Orientation': Quaternion (q)>, 47: <Channel 47 'Rotation': Rotation (dps)>, 59: <Channel 59 'Control Pad Pressure/Temperature/Humidity': Pressure (Pa), Temperature (°C), Relative Humidity (RH)>, 76: <Channel 76 'Light Sensor': Light (Ill), Light (Index)>}
Configuration¶
Configuration is done via the configuration interface.
>>> dev.config.enableChannel(dev.channels[8][0], True)
>>> dev.config.setSampleRate(dev.channels[8], 3600)
Control¶
Device control is done via the command interface.
>>> dev.command.startRecording()
Virtual devices¶
An enDAQ .IDE recording file can be used to create a ‘virtual’ version
of the recorder that created it. This provides an easy way to retrieve
information about the device and how it was configured. Virtual devices can not
be commanded.
>>> from idelib.importer import openFile
>>> with openFile('test.ide') as doc:
... virtual_dev = endaq.device.fromRecording(doc)
Quick Start Example Code¶
Here is some starter code for introducing yourself to the endaq.device library. Use it to familiarize yourself with with how to use endaq.device and learn about some of its basic applications. Make sure to follow the installation instructions found on the homepage first.
1"""
2Quick Start example code for using the endaq.device library.
3
4CONNECTING:
5This code will find all connected devices and print their serial numbers. It
6will then select the first connected device and assign it to the 'dev'
7variable so we can interface with that device.
8
9CONFIGURING:
10Next, the device is configured to have the sample rate of the 40g
11accelerometer (Channel 80) set to 4kHz. Retrigger is then turned off. For the
12final bit of configuration, if the device's firmware is older than version
133.01.06, the recording time limit is set to 30 seconds, since those firmware
14versions do not support the 'stopRecording()' function.
15
16STARTING THE RECORDING:
17Now the `startRecording()` command is sent and the device's green light
18should begin blinking to indicate that it is recording. If the device is old
19enough that it does not have a serial command interface, a message will be
20printed asking for the recording to be started manually, and then the code
21will wait until the device disappears, indicating that the recording has
22started.
23
24STOPPING THE RECORDING:
25If the device's FW is new enough, it will be told to stop recording after 30
26seconds. If the FW is old enough that there was a recording time limit set
27earlier, then the code will wait for the device to reappear after the
28recording automatically stops. If the device fails to reappear within 60
29seconds, an error will be raised.
30
31COPYING THE RECORDING FILE:
32When the device reconnects, the most recent recording on the enDAQ will be
33copied to a local directory of your choosing. REPLACE THE 'destination'
34VARIABLE WITH YOUR DESIRED FILE PATH. The name of this recording file
35will then be printed.
36"""
37# Import endaq.device and other useful libraries.
38import time
39import os.path
40import shutil
41import endaq.device
42from endaq.device.exceptions import CommandError, DeviceTimeout
43
44# Find all connected devices and print their serial numbers
45device_list = endaq.device.getDevices()
46print("Connected Device Serial Number(s):")
47for device in device_list:
48 print(device.serial)
49
50# Select the first device from the list of available devices
51dev = endaq.device.getDevices()[0]
52
53# Update configuration
54dev.config.setSampleRate(dev.channels[80], 4000) # Set Ch 80 SR to 4000 Hz
55dev.config.retrigger = False # Turn off retrigger
56if dev.firmwareVersion < 30106: # Since stopRecording doesn't work on old FW...
57 dev.config.recordingTimeLimit = 30 # Set recording limit to 30 secs
58
59# Start Recording
60dev.command.startRecording()
61
62# For older devices without a SerialCommandInterface
63if not isinstance(dev.command, endaq.device.SerialCommandInterface):
64 print("Start command failed, please push the button to start a recording.")
65 dev.command.awaitDisconnect() # Wait for the device to disconnect
66
67# Stop Recording
68if dev.firmwareVersion >= 30106:
69 time.sleep(30)
70 dev.command.stopRecording()
71else:
72 if dev.command.awaitReconnect(timeout=60) is False:
73 raise DeviceTimeout("Device did not reconnect in 60 seconds after recording.")
74
75# Copy the most recent recording on the enDAQ to your local directory
76destination = "/destination/" # Replace with desired destination path
77
78path = os.path.join(dev.path, 'DATA', 'RECORD')
79newest = sorted(os.listdir(path))[-1]
80shutil.copy2(os.path.join(path, newest), os.path.join(destination, newest))
81# Print the copied file's name
82print(f"Name of the most recent recording: {newest}")