Skip to content

Commit

Permalink
mdf4reader : handles byteorder swapping with dataRead
Browse files Browse the repository at this point in the history
  • Loading branch information
ratal committed Aug 11, 2015
1 parent 178f9b3 commit 5b6cef1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mdfreader/mdf4reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from struct import Struct
from struct import unpack as structunpack
from math import pow
from sys import platform, version_info, exc_info
from sys import platform, version_info, exc_info, byteorder
from io import open # for python 3 and 2 consistency
from .mdfinfo4 import info4, MDFBlock, ATBlock
from time import gmtime, strftime
Expand Down Expand Up @@ -1014,9 +1014,16 @@ def readBitarray(self, bita, channelList=None):
self.numberOfRecords, self.CGrecordLength, \
self[chan].bitOffset, self[chan].posByteBeg, self[chan].posByteEnd, \
self[chan].posBitEnd)
# correct endianess, not handled by dataRead outputing native byteorder
if not byteorder == 'little' and self[chan].signalDataType in (0, 2, 4, 8) \
and buf[self[chan].name].dtype.byteorder in ('>', '|', '='):
buf[self[chan].name] = buf[self[chan].name].newbyteorder() # swaps order
elif byteorder == 'little' and self[chan].signalDataType in (1, 3, 5, 9) \
and buf[self[chan].name].dtype.byteorder in ('<', '|', '='):
buf[self[chan].name] = buf[self[chan].name].newbyteorder() # swaps order
return buf
except:
print("Unexpected error:", exc_info()[0])
print('Unexpected error:', exc_info()[0])
print('dataRead crashed, back to python data reading')
from bitarray import bitarray
B = bitarray(endian="little") # little endian by default
Expand Down

0 comments on commit 5b6cef1

Please sign in to comment.