Skip to content

Commit

Permalink
Update library to DWDataReader v4.2.0.31 (#66)
Browse files Browse the repository at this point in the history
* Update library to DWDataReader v4.2.0.31

* Exclude numpy 2.0 for now

* Handle unknown errors gracefully

* Force count to be ctypes_c_int64

* Fix typo

* Add undocumented error numbers defined in DWLoadLib.h example

* Correct typo

* Avoid testing channels whose channel_index begins with CAN

* Add test of ENG_RPM whose channel_index begins with CAN

* Add expectedFailure decorator for test_CAN_channel

* Allow numpy >= 1.16.0

* Workaround CAN bug in the example

* Version bump 0.15.5
  • Loading branch information
costerwi authored Nov 3, 2024
1 parent e579a23 commit bb63445
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 484 deletions.
Binary file modified dwdatareader/DWDataReaderLib.dll
Binary file not shown.
Binary file modified dwdatareader/DWDataReaderLib.so
Binary file not shown.
Binary file modified dwdatareader/DWDataReaderLib64.dll
Binary file not shown.
Binary file modified dwdatareader/DWDataReaderLib64.so
Binary file not shown.
27 changes: 18 additions & 9 deletions dwdatareader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
print(ch.name, ch.series().mean())
"""
__all__ = ['DWError', 'DWFile', 'getVersion']
__version__ = '0.15.4'
__version__ = '0.15.5'

DLL = None # module variable accessible to other classes
encoding = 'ISO-8859-1' # default encoding
Expand All @@ -27,13 +27,22 @@

class DWError(RuntimeError):
"""Interpret error number returned from dll"""
errors = ("status OK", "error in DLL", "cannot open d7d file",
"file already in use", "d7d file corrupt", "memory allocation",
"creating uncompressed file", "extracting data",
"opening uncompressed file")
errors = {0: "status OK",
1: "error in DLL",
2: "cannot open d7d file",
3: "file already in use",
4: "d7d file corrupt",
5: "memory allocation",
6: "creating uncompressed file",
7: "extracting data",
8: "opening uncompressed file",
9: "invalid intermediate buffer level (ib_level)",
10: "CAN not supported",
}

def __init__(self, value):
super(DWError, self).__init__(self.errors[value])
error = self.errors.get(value, 'Unknown error {}'.format(value))
super(DWError, self).__init__(error)


class DWInfo(ctypes.Structure):
Expand Down Expand Up @@ -190,7 +199,7 @@ def scaled(self, arrayIndex=0):
count = self.number_of_samples
data = numpy.empty(count*self.array_size, dtype=numpy.double)
time = numpy.empty(count, dtype=numpy.double)
stat = DLL.DWGetScaledSamples(self.index, ctypes.c_int64(0), count,
stat = DLL.DWGetScaledSamples(self.index, ctypes.c_int64(0), ctypes.c_int64(count),
data.ctypes, time.ctypes)
if stat:
raise DWError(stat)
Expand All @@ -208,7 +217,7 @@ def dataframe(self):
count = self.number_of_samples
data = numpy.empty(count*self.array_size, dtype=numpy.double)
time = numpy.empty(count, dtype=numpy.double)
stat = DLL.DWGetScaledSamples(self.index, ctypes.c_int64(0), count,
stat = DLL.DWGetScaledSamples(self.index, ctypes.c_int64(0), ctypes.c_int64(count),
data.ctypes, time.ctypes)
if stat:
raise DWError(stat)
Expand Down Expand Up @@ -294,7 +303,7 @@ def series_generator(self, chunk_size, arrayIndex=0):
chunk_size = min(chunk_size, count - chunk)
stat = DLL.DWGetScaledSamples(
self.index,
ctypes.c_int64(chunk), chunk_size,
ctypes.c_int64(chunk), ctypes.c_int64(chunk_size),
data.ctypes, time.ctypes)
if stat:
raise DWError(stat)
Expand Down
Loading

0 comments on commit bb63445

Please sign in to comment.