##// END OF EJS Templates
Sync
Alexis Jeandet -
r4:82c303974ea4 default
parent child
Show More
@@ -175,6 +175,19 class Discovery(object):
175 errors = {0: RuntimeError("No card opened"),
175 errors = {0: RuntimeError("No card opened"),
176 1: UserWarning("Parameter out of bound"),
176 1: UserWarning("Parameter out of bound"),
177 }
177 }
178 def findDevice(self,device):
179 if not self.__opened:
180 raise self.errors.get(0)
181 nbDevices = c_int()
182 self.__libdwf.FDwfEnum(c_int(0), byref(nbDevices))
183 SN = create_string_buffer(32)
184 for i in range(nbDevices.value):
185 self.__libdwf.FDwfEnumSN(c_int(i), SN)
186 if SN.value.decode("UTF-8") == device:
187 return i
188 return -1
189
190
178 def __init__(self,card=-1):
191 def __init__(self,card=-1):
179 if sys.platform.startswith("win"):
192 if sys.platform.startswith("win"):
180 self.__libdwf = cdll.dwf
193 self.__libdwf = cdll.dwf
@@ -184,6 +197,11 class Discovery(object):
184 self.__libdwf = cdll.LoadLibrary("libdwf.so")
197 self.__libdwf = cdll.LoadLibrary("libdwf.so")
185 self.__opened = True
198 self.__opened = True
186 self.__hdwf = c_int()
199 self.__hdwf = c_int()
200 if card != -1:
201 SN=card
202 card = self.findDevice(card)
203 if card == -1:
204 raise RuntimeError( "Card not found "+ SN)
187 self.__libdwf.FDwfDeviceOpen(c_int(card), byref(self.__hdwf))
205 self.__libdwf.FDwfDeviceOpen(c_int(card), byref(self.__hdwf))
188 if self.__hdwf.value == nodev.value:
206 if self.__hdwf.value == nodev.value:
189 szerr = create_string_buffer(512)
207 szerr = create_string_buffer(512)
@@ -266,8 +284,8 class Discovery(object):
266 ch2data = (c_double*cnt)()
284 ch2data = (c_double*cnt)()
267 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
285 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
268 return [np.array([ch1data,ch2data]),frequency]
286 return [np.array([ch1data,ch2data]),frequency]
269 else:
287 else:
270 return [np.array([ch1data]),frequency]
288 return [np.array([ch1data]),frequency]
271 if ch2:
289 if ch2:
272 ch2data = (c_double*cnt)()
290 ch2data = (c_double*cnt)()
273 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
291 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
@@ -290,13 +308,15 class Discovery(object):
290 #############################################################
308 #############################################################
291 # AnalogOut
309 # AnalogOut
292 #############################################################
310 #############################################################
293 def analog_out_gen(self,frequency=1000, shape='Sine', channel=0, amplitude=1.0, offset=0.0):
311 def analog_out_gen(self,frequency=1000, shape='Sine', channel=0, amplitude=1.0, offset=0.0,phase=0.0):
294 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
312 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
295 self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
313 self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
296 self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get(shape)))
314 self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get(shape)))
297 self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genFreq(frequency)))
315 if shape!="DC":
298 self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genAmplitude(amplitude)))
316 self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genFreq(frequency)))
317 self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genAmplitude(amplitude)))
299 self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(offset)))
318 self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(offset)))
319 self.__libdwf.FDwfAnalogOutNodePhaseSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(phase))
300 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
320 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
301
321
302 def analog_out_gen_arbit(self,samplesBuffer ,repeatingFrequency=100, channel=0, amplitude=1.0, offset=0.0):
322 def analog_out_gen_arbit(self,samplesBuffer ,repeatingFrequency=100, channel=0, amplitude=1.0, offset=0.0):
@@ -304,7 +324,7 class Discovery(object):
304 cnt=self.__limits.genBuffSize(len(samplesBuffer))
324 cnt=self.__limits.genBuffSize(len(samplesBuffer))
305 buf=(c_double*cnt)()
325 buf=(c_double*cnt)()
306 buf[:]=samplesBuffer[0:cnt]
326 buf[:]=samplesBuffer[0:cnt]
307 repeatingFrequency = self.__limits.genFreq(repeatingFrequency*cnt)/cnt
327 #repeatingFrequency = self.__limits.genFreq(repeatingFrequency*cnt)/cnt
308 self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
328 self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
309 self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get("Custom")))
329 self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get("Custom")))
310 self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(repeatingFrequency))
330 self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(repeatingFrequency))
General Comments 0
You need to be logged in to leave comments. Login now