@@ -107,7 +107,7 @@ def __init__(self, filename, pl2_dll_file_path=None):
107107 # download default PL2 dll once if not yet available
108108 if pl2_dll_file_path is None :
109109 architecture = platform .architecture ()[0 ]
110- if architecture == "64bit" and platform .system () == "Windows" :
110+ if architecture == "64bit" and platform .system () in [ "Windows" , "Darwin" ]:
111111 file_name = "PL2FileReader64.dll"
112112 else : # Apparently wine uses the 32 bit version in linux
113113 file_name = "PL2FileReader.dll"
@@ -120,16 +120,27 @@ def __init__(self, filename, pl2_dll_file_path=None):
120120 dist = urlopen (url = url )
121121
122122 with open (pl2_dll_file_path , "wb" ) as f :
123- print (f"Downloading plexon dll to { pl2_dll_file_path } " )
123+ warnings . warn (f"dll file does not exist, downloading plexon dll to { pl2_dll_file_path } " )
124124 f .write (dist .read ())
125125
126126 # Instantiate wrapper for Windows DLL
127127 from neo .rawio .plexon2rawio .pypl2 .pypl2lib import PyPL2FileReader
128128
129129 self .pl2reader = PyPL2FileReader (pl2_dll_file_path = pl2_dll_file_path )
130130
131- # Open the file.
132- self .pl2reader .pl2_open_file (self .filename )
131+
132+ reading_attempts = 10
133+ for attempt in range (reading_attempts ):
134+ self .pl2reader .pl2_open_file (self .filename )
135+
136+ # Verify the file handle is valid.
137+ if self .pl2reader ._file_handle .value != 0 :
138+ # File handle is valid, exit the loop early
139+ break
140+ else :
141+ if attempt == reading_attempts - 1 :
142+ self .pl2reader ._print_error ()
143+ raise IOError (f"Opening { self .filename } failed after { reading_attempts } attempts." )
133144
134145 def _source_name (self ):
135146 return self .filename
@@ -146,7 +157,6 @@ def _parse_header(self):
146157 Source = namedtuple ("Source" , "id name sampling_rate n_samples" )
147158 for c in range (self .pl2reader .pl2_file_info .m_TotalNumberOfAnalogChannels ):
148159 achannel_info = self .pl2reader .pl2_get_analog_channel_info (c )
149-
150160 # only consider active channels
151161 if not achannel_info .m_ChannelEnabled :
152162 continue
@@ -262,8 +272,10 @@ def _parse_header(self):
262272 # python is 1..12 https://docs.python.org/3/library/datetime.html#datetime.datetime
263273 # so month needs to be tm_mon+1; also tm_sec could cause problems in the case of leap
264274 # seconds, but this is harder to defend against.
275+ year = tmo .tm_year # This has base 1900 in the c++ struct specification so we need to add 1900
276+ year += 1900
265277 dt = datetime (
266- year = tmo . tm_year ,
278+ year = year ,
267279 month = tmo .tm_mon + 1 ,
268280 day = tmo .tm_mday ,
269281 hour = tmo .tm_hour ,
@@ -317,7 +329,6 @@ def _parse_header(self):
317329 "m_OneBasedChannelInTrode" ,
318330 "m_Source" ,
319331 "m_Channel" ,
320- "m_Name" ,
321332 "m_MaximumNumberOfFragments" ,
322333 ]
323334
0 commit comments