From f48c034011c153760c586fe397c66e4d37046e6a Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 17:38:18 +0100 Subject: [PATCH 1/6] Bump version and add device listing Updated the project version reflecting new features. Extended the LimeConfig_t struct to include a device string supporting device specification. Introduced a new function `get_device_list` in the Python binding, allowing users to retrieve a list of available devices, enhancing usability. This change improves user interactions with the hardware, making device management more intuitive. --- pyproject.toml | 2 +- src/limedriver/limedriver.pyx | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 85ff8e8..173e588 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "limedriver" -version = "0.3.0" +version = "0.4.0" description = "Python bindings for limedriver" authors = [{name = "Kumi", email = "limedriver@kumi.email"}] license = {file = "LICENSE"} diff --git a/src/limedriver/limedriver.pyx b/src/limedriver/limedriver.pyx index 4bd4a5e..63bc855 100644 --- a/src/limedriver/limedriver.pyx +++ b/src/limedriver/limedriver.pyx @@ -5,13 +5,15 @@ from cpython.mem cimport PyMem_Malloc, PyMem_Free from libc.stdlib cimport malloc, free from libc.string cimport memcpy, strcpy - +from libcpp.vector cimport vector from libcpp.string cimport string import pathlib cdef extern from "limedriver.h": cdef struct LimeConfig_t: + string device + float srate int channel int TX_matching @@ -92,6 +94,8 @@ cdef extern from "limedriver.h": cdef LimeConfig_t initializeLimeConfig(int Npulses) cdef int run_experiment_from_LimeCfg(LimeConfig_t config) + + cdef vector[string] getDeviceList() cdef class PyLimeConfig: @@ -703,4 +707,7 @@ cdef class PyLimeConfig: path = self.save_path + self.file_stamp + '_' + self.file_pattern + '.h5' path = pathlib.Path(path).absolute() return path - \ No newline at end of file + +def get_device_list(): + cdef vector[string] devices = getDeviceList() + return [device.decode('utf-8') for device in devices] \ No newline at end of file From 0696cc3b203443dcc8006018d6298f2919cad2ad Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 17:46:07 +0100 Subject: [PATCH 2/6] Add device property to PyLimeConfig Introduced a getter and setter for the 'device' property, allowing for UTF-8 encoding/decoding of the device string in the PyLimeConfig class. This enhances string handling consistency across the interface. --- src/limedriver/limedriver.pyx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/limedriver/limedriver.pyx b/src/limedriver/limedriver.pyx index 63bc855..da4ded8 100644 --- a/src/limedriver/limedriver.pyx +++ b/src/limedriver/limedriver.pyx @@ -660,6 +660,14 @@ cdef class PyLimeConfig: self._config.c3_synth[i] = values[i] # String properties + @property + def device(self): + return self._config.device.decode('utf-8') + + @device.setter + def device(self, str value): + self._config.device = value.encode('utf-8') + @property def file_pattern(self): return self._config.file_pattern.decode() From ce89c445d79cc6bb2aa57e036b296fce6d8fbbef Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 18:02:59 +0100 Subject: [PATCH 3/6] Enhance device channel handling Introduced a new utility function to extract and return the number of channels associated with a given device, improving the driver's ability to handle device-specific configurations. Also expanded the C++ bindings by importing the pair class, which is pivotal for representing the channel information. This enhancement facilitates more granular control and paves the way for future features that may require detailed channel info. --- src/limedriver/limedriver.pyx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/limedriver/limedriver.pyx b/src/limedriver/limedriver.pyx index da4ded8..9bda00b 100644 --- a/src/limedriver/limedriver.pyx +++ b/src/limedriver/limedriver.pyx @@ -7,6 +7,7 @@ from libc.string cimport memcpy, strcpy from libcpp.vector cimport vector from libcpp.string cimport string +from libcpp.pair cimport pair import pathlib @@ -95,6 +96,8 @@ cdef extern from "limedriver.h": cdef int run_experiment_from_LimeCfg(LimeConfig_t config) + cdef pair[int, int] getChannelsFromInfo(string device) + cdef vector[string] getDeviceList() @@ -718,4 +721,8 @@ cdef class PyLimeConfig: def get_device_list(): cdef vector[string] devices = getDeviceList() - return [device.decode('utf-8') for device in devices] \ No newline at end of file + return [device.decode('utf-8') for device in devices] + +def get_channels_for_device(device): + cdef pair[int, int] channels = getChannelsFromInfo(device) + return channels.first, channels.second From 8874795fd0432e6f04e783230edb786295986b33 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 18:04:10 +0100 Subject: [PATCH 4/6] Set default parameter for get_channels_for_device Optional device specifier: Adjusted get_channels_for_device function to include a default empty string parameter. Enables calls without specifying a device, reducing the need for client code to handle default cases explicitly. --- src/limedriver/limedriver.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/limedriver/limedriver.pyx b/src/limedriver/limedriver.pyx index 9bda00b..c47e190 100644 --- a/src/limedriver/limedriver.pyx +++ b/src/limedriver/limedriver.pyx @@ -723,6 +723,6 @@ def get_device_list(): cdef vector[string] devices = getDeviceList() return [device.decode('utf-8') for device in devices] -def get_channels_for_device(device): +def get_channels_for_device(device = ""): cdef pair[int, int] channels = getChannelsFromInfo(device) return channels.first, channels.second From fc536126bc922f5b2665521aaad65d7a4f261340 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 18:06:55 +0100 Subject: [PATCH 5/6] Encode device parameter before channel retrieval Fixed an issue in the `get_channels_for_device` function where the input device name wasn't being encoded before passing it to the underlying C function `getChannelsFromInfo`. This change ensures compatibility with the expected string encoding, preventing potential runtime errors related to string handling across the Python-C boundary. --- src/limedriver/limedriver.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/limedriver/limedriver.pyx b/src/limedriver/limedriver.pyx index c47e190..039da97 100644 --- a/src/limedriver/limedriver.pyx +++ b/src/limedriver/limedriver.pyx @@ -724,5 +724,5 @@ def get_device_list(): return [device.decode('utf-8') for device in devices] def get_channels_for_device(device = ""): - cdef pair[int, int] channels = getChannelsFromInfo(device) + cdef pair[int, int] channels = getChannelsFromInfo(device.encode()) return channels.first, channels.second From 5c3202305a51a92367257acf04583eb2fb19e56b Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 18:21:04 +0100 Subject: [PATCH 6/6] Update limedriver submodule to latest commit Upgraded the 'limedriver' submodule to incorporate the latest fixes and improvements from the upstream repository, ensuring compatibility and enhanced stability. --- extern/limedriver | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/limedriver b/extern/limedriver index d1e1cd6..294e31d 160000 --- a/extern/limedriver +++ b/extern/limedriver @@ -1 +1 @@ -Subproject commit d1e1cd6bba209c0ca604411d50329abaa5a824b1 +Subproject commit 294e31d9cfa3f49f4973b92dc5d93a757653057e