Skip to content

Pypl2lib fixes #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implemented pypl2lib's pl2_get_analog_channel_data_subset.
  • Loading branch information
Nikhil Chandra committed Oct 15, 2024
commit 0129c1598a477480468ea8a24e25b7e48bcf12a2
64 changes: 62 additions & 2 deletions pypl2lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,68 @@ def pl2_get_analog_channel_data(self, zero_based_channel_index):

return fragment_timestamps, fragment_counts, values

def pl2_get_analog_channel_data_subset(self):
pass
def pl2_get_analog_channel_data_subset(self, zero_based_channel_index, zero_based_start_value_index, num_subset_values):
"""
Retrieve analog channel data subset

Args:
zero_based_channel_index - zero based channel index
zero_based_start_value_index - zero based sample index of the start of the subset
num_subset_values - how many values to return in the subset

Returns:
fragment_timestamps - array the size of num_fragments_returned
fragment_counts - array the size of num_fragments_returned
values - array the size of num_subset_values
"""

achannel_info = self.pl2_get_analog_channel_info(zero_based_channel_index)

num_fragments_returned = ctypes.c_ulonglong(achannel_info.m_MaximumNumberOfFragments)
num_data_points_returned = ctypes.c_ulonglong(achannel_info.m_NumberOfValues)
fragment_timestamps = (ctypes.c_longlong * achannel_info.m_MaximumNumberOfFragments)()
fragment_counts = (ctypes.c_ulonglong * achannel_info.m_MaximumNumberOfFragments)()
values = (ctypes.c_short * num_subset_values)()

self.pl2_dll.PL2_GetAnalogChannelDataSubset.argtypes = (
ctypes.c_int,
ctypes.c_int,
ctypes.c_ulonglong,
ctypes.c_uint,
ctypes.POINTER(ctypes.c_ulonglong),
ctypes.POINTER(ctypes.c_ulonglong),
ctypes.POINTER(ctypes.c_longlong),
ctypes.POINTER(ctypes.c_ulonglong),
ctypes.POINTER(ctypes.c_short),
)

self.pl2_dll.PL2_GetAnalogChannelDataSubset.memsync = [
{"p": [6], "l": [4], "t": ctypes.c_longlong},
{"p": [7], "l": [4], "t": ctypes.c_ulonglong},
{"p": [8], "l": ([4],), "func": f"lambda x: {num_subset_values}", "t": ctypes.c_short},
]

result = self.pl2_dll.PL2_GetAnalogChannelDataSubset(
self._file_handle,
zero_based_channel_index,
zero_based_start_value_index,
num_subset_values,
num_fragments_returned,
num_data_points_returned,
fragment_timestamps,
fragment_counts,
values,
)

if not result:
self._print_error()
return None

fragment_timestamps = to_array(fragment_timestamps)[:num_fragments_returned.value]
fragment_counts = to_array(fragment_counts)[:num_fragments_returned.value]
values = to_array(values)

return fragment_timestamps, fragment_counts, values

def pl2_get_analog_channel_data_by_name(self, channel_name):
"""
Expand Down