1919import sys
2020import ctypes
2121import os
22+ import warnings
2223
2324import numpy as np
2425import quantities as pq
@@ -131,6 +132,10 @@ def read_segment(self, import_neuroshare_segment=True,
131132
132133 seg = Segment (file_origin = os .path .basename (self .filename ), )
133134
135+ if self .dllname == '' :
136+ warnings .warn ('No neuroshare dll provided. Can not load data.' )
137+ return Segment ()
138+
134139 if sys .platform .startswith ('win' ):
135140 neuroshare = ctypes .windll .LoadLibrary (self .dllname )
136141 elif sys .platform .startswith ('linux' ):
@@ -147,7 +152,7 @@ def read_segment(self, import_neuroshare_segment=True,
147152
148153 # open file
149154 hFile = ctypes .c_uint32 (0 )
150- neuroshare .ns_OpenFile (ctypes .c_char_p (self .filename ), ctypes .byref (hFile ))
155+ neuroshare .ns_OpenFile (ctypes .c_char_p (bytes ( self .filename , 'utf-8' ) ), ctypes .byref (hFile ))
151156 fileinfo = ns_FILEINFO ()
152157 neuroshare .ns_GetFileInfo (hFile , ctypes .byref (fileinfo ), ctypes .sizeof (fileinfo ))
153158
@@ -176,8 +181,6 @@ def read_segment(self, import_neuroshare_segment=True,
176181 pdTimeStamp = ctypes .c_double (0. )
177182 pdwDataRetSize = ctypes .c_uint32 (0 )
178183
179- ea = Event (name = str (entityInfo .szEntityLabel ), )
180-
181184 times = []
182185 labels = []
183186 for dwIndex in range (entityInfo .dwItemCount ):
@@ -186,9 +189,10 @@ def read_segment(self, import_neuroshare_segment=True,
186189 ctypes .sizeof (pData ), ctypes .byref (pdwDataRetSize ))
187190 times .append (pdTimeStamp .value )
188191 labels .append (str (pData .value ))
189- ea . times = times * pq .s
190- ea . labels = np .array (labels , dtype = 'U' )
192+ times = times * pq .s
193+ labels = np .array (labels , dtype = 'U' )
191194
195+ ea = Event (name = str (entityInfo .szEntityLabel ), times = times , labels = labels )
192196 seg .events .append (ea )
193197
194198 # analog
@@ -212,7 +216,7 @@ def read_segment(self, import_neuroshare_segment=True,
212216 ctypes .POINTER (ctypes .c_double )))
213217 total_read += pdwContCount .value
214218
215- signal = pq .Quantity (pData , units = pAnalogInfo .szUnits , copy = False )
219+ signal = pq .Quantity (pData , units = pAnalogInfo .szUnits . decode () , copy = False )
216220
217221 # t_start
218222 dwIndex = 0
0 commit comments