From f687805651b312457107fcbc919c0318bdaf855a Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 19 Jun 2019 15:39:54 +0100 Subject: [PATCH 1/9] Fix to avoid analogue channels --- .../inspectionProfiles/profiles_settings.xml | 3 +- .idea/misc.xml | 12 +- .idea/modules.xml | 1 + .idea/workspace.xml | 212 +++++++++--------- DAQ.py | 42 +++- 5 files changed, 155 insertions(+), 115 deletions(-) diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml index 3b31283..105ce2d 100644 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -1,7 +1,6 @@ - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 5e11765..cc75a76 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,14 +1,4 @@ - - - - - - - - - - - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 71b2f86..fb8818c 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,7 @@ + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 325af3f..071d1a1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,13 +1,15 @@ - + - + + + @@ -18,7 +20,6 @@ - @@ -28,26 +29,43 @@ - + - - + + - - - - + + + + + + + + + + + - + + + + + + + + + + + @@ -72,26 +90,16 @@ - - - - - - - - - - + @@ -110,12 +118,6 @@ - - - - - + - - + - + - - + + + - + + - - @@ -485,15 +498,30 @@ + + + + + + + + + + + + + + + + + + - + - - - @@ -501,7 +529,7 @@ - + @@ -509,12 +537,9 @@ - + - - - @@ -522,12 +547,9 @@ - + - - - @@ -535,14 +557,14 @@ - + - + @@ -550,12 +572,9 @@ - + - - - @@ -563,14 +582,14 @@ - + - + @@ -578,12 +597,9 @@ - + - - - @@ -591,7 +607,7 @@ - + @@ -599,12 +615,9 @@ - + - - - @@ -612,12 +625,9 @@ - + - - - @@ -625,19 +635,16 @@ - + - + - - - @@ -645,12 +652,9 @@ - + - - - @@ -658,7 +662,7 @@ - + @@ -666,37 +670,43 @@ - + - + - - + + + - + - - - - - - - - + + + - + - - + + + + + + + + + + + + \ No newline at end of file diff --git a/DAQ.py b/DAQ.py index 3bf3809..7db93db 100644 --- a/DAQ.py +++ b/DAQ.py @@ -82,7 +82,7 @@ def __init__(self, device, samprate, secs, write, clock=''): self.AutoRegisterDoneEvent(0) - self.write = Util.binaryToDigitalMap(write) + self.write = Util.binary_to_digital_map(write) def DoTask(self): print ('Starting digital output') @@ -240,6 +240,46 @@ def DoneCallback(self, status): # region [MultiTasks] +class DoCoTask: + def __init__(self, do_device, co_device, samp_rate, secs, write): + self.do_handle = TaskHandle(0) + self.co_handle = TaskHandle(1) + + DAQmxCreateTask('', byref(self.do_handle)) + DAQmxCreateTask('', byref(self.co_handle)) + + DAQmxCreateCOPulseChanFreq(self.co_handle, 'cDAQ1/Ctr0', '', DAQmx_Val_Hz, DAQmx_Val_Low, 0.0, samp_rate, 0.5) + DAQmxCreateDOChan(self.do_handle, do_device, '', DAQmx_Val_ChanForAllLines) + + self.totalLength = numpy.uint64(samp_rate * secs) + self.secs = secs + print(self.totalLength) + self.sampsPerChanWritten = int32() + self.write = Util.binary_to_digital_map(write) + self.sampsPerChan = self.write.shape[1] + self.write = numpy.sum(self.write, axis=0) + + DAQmxCfgImplicitTiming(self.co_handle, DAQmx_Val_FiniteSamps, self.totalLength) + DAQmxCfgSampClkTiming(self.do_handle, '/cDAQ1/Ctr0InternalOutput', samp_rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, + numpy.uint64(self.totalLength)) + + def DoTask(self): + DAQmxWriteDigitalU32(self.do_handle, self.sampsPerChan, 0, -1, DAQmx_Val_GroupByChannel, self.write, + byref(self.sampsPerChanWritten), None) + + DAQmxStartTask(self.do_handle) + DAQmxStartTask(self.co_handle) + time.sleep(self.secs + 0.05) + + self.ClearTasks() + + def ClearTasks(self): + time.sleep(0.05) + DAQmxStopTask(self.do_handle) + DAQmxStopTask(self.co_handle) + + DAQmxClearTask(self.do_handle) + DAQmxClearTask(self.co_handle) class DoAiMultiTask: def __init__(self, ai_device, ai_channels, do_device, samp_rate, secs, write, sync_clock): From ace4a6444f8252df099de1879e80ca5319f40792 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 4 Jul 2019 14:52:56 +0100 Subject: [PATCH 2/9] Revert "Merge branch 'master' of https://github.com/RoboDoig/daqface" This reverts commit 052b479fe35bc8e0d06eab0900f63b5df7545439, reversing changes made to c61abb2a9992b18db09c25c6971f152b4b30de2e. --- README.md | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 6234804..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# daqface -A high-level python interface for a number of common NI DAQmx hardware tasks. From 5732c9930e6955128e26902fa0ba3faf07461913 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 11 Jul 2019 14:29:14 +0100 Subject: [PATCH 3/9] Add DoTriggeredCoTask Adds triggered task if there are no analogue channels --- DAQ.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/DAQ.py b/DAQ.py index 7db93db..1a05c5b 100644 --- a/DAQ.py +++ b/DAQ.py @@ -239,6 +239,55 @@ def DoneCallback(self, status): # region [MultiTasks] +class DoTriggeredCoTask: + def __init__(self, do_device, co_device, samp_rate, secs, write, trigger_source): + self.do_handle = TaskHandle(0) + self.co_handle = TaskHandle(1) + + + DAQmxCreateTask('', byref(self.do_handle)) + DAQmxCreateTask('', byref(self.co_handle)) + + DAQmxCreateCOPulseChanFreq(self.co_handle, '/cDAQ1/Ctr0', '', DAQmx_Val_Hz, DAQmx_Val_Low, 0.0, samp_rate, 0.5) + DAQmxCreateDOChan(self.do_handle, do_device, '', DAQmx_Val_ChanForAllLines) + + + DAQmxCfgDigEdgeStartTrig(self.co_handle, trigger_source, DAQmx_Val_Rising) + self.totalLength = numpy.uint64(samp_rate * secs) + self.secs = secs + self.sampsPerChanWritten = int32() + self.write = Util.binary_to_digital_map(write) + self.sampsPerChan = self.write.shape[1] + self.write = numpy.sum(self.write, axis=0) + + + DAQmxCfgImplicitTiming(self.co_handle, DAQmx_Val_FiniteSamps, self.totalLength) + DAQmxCfgSampClkTiming(self.do_handle, '/cDAQ1/Ctr0InternalOutput', samp_rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, + numpy.uint64(self.totalLength)) + + def DoTask(self): + + DAQmxWriteDigitalU32(self.do_handle, self.sampsPerChan, 0, -1, DAQmx_Val_GroupByChannel, self.write, + byref(self.sampsPerChanWritten), None) + + + DAQmxStartTask(self.do_handle) + DAQmxStartTask(self.co_handle) + + DAQmxWaitUntilTaskDone(self.co_handle, 100) + DAQmxWaitUntilTaskDone(self.do_handle, 100) + + self.ClearTasks() + + def ClearTasks(self): + time.sleep(0.05) + + DAQmxStopTask(self.do_handle) + DAQmxStopTask(self.co_handle) + + DAQmxClearTask(self.do_handle) + DAQmxClearTask(self.co_handle) + class DoCoTask: def __init__(self, do_device, co_device, samp_rate, secs, write): @@ -269,7 +318,9 @@ def DoTask(self): DAQmxStartTask(self.do_handle) DAQmxStartTask(self.co_handle) - time.sleep(self.secs + 0.05) + DAQmxWaitUntilTaskDone(self.co_handle, 100) + DAQmxWaitUntilTaskDone(self.do_handle, 100) + self.ClearTasks() @@ -360,6 +411,7 @@ def __init__(self, ai_device, ai_channels, do_device, samp_rate, secs, write, sy numpy.uint64(self.totalLength)) def DoTask(self): + DAQmxWriteDigitalU32(self.do_handle, self.sampsPerChan, 0, -1, DAQmx_Val_GroupByChannel, self.write, byref(self.sampsPerChanWritten), None) From 26a7c4a8ac617bfe91d11f49a17da3b89610b0a3 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 27 Feb 2020 20:31:46 +0000 Subject: [PATCH 4/9] remove length print --- DAQ.py | 1 - 1 file changed, 1 deletion(-) diff --git a/DAQ.py b/DAQ.py index 1a05c5b..4ac0643 100644 --- a/DAQ.py +++ b/DAQ.py @@ -302,7 +302,6 @@ def __init__(self, do_device, co_device, samp_rate, secs, write): self.totalLength = numpy.uint64(samp_rate * secs) self.secs = secs - print(self.totalLength) self.sampsPerChanWritten = int32() self.write = Util.binary_to_digital_map(write) self.sampsPerChan = self.write.shape[1] From 1a5b444dfd32f0e4ecbf9fde8bd2786ea8c6653b Mon Sep 17 00:00:00 2001 From: warnerwarner Date: Mon, 22 Feb 2021 14:00:19 +0000 Subject: [PATCH 5/9] init close_valves --- DAQ.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/DAQ.py b/DAQ.py index 4ac0643..a8aa3d2 100644 --- a/DAQ.py +++ b/DAQ.py @@ -297,8 +297,8 @@ def __init__(self, do_device, co_device, samp_rate, secs, write): DAQmxCreateTask('', byref(self.do_handle)) DAQmxCreateTask('', byref(self.co_handle)) - DAQmxCreateCOPulseChanFreq(self.co_handle, 'cDAQ1/Ctr0', '', DAQmx_Val_Hz, DAQmx_Val_Low, 0.0, samp_rate, 0.5) - DAQmxCreateDOChan(self.do_handle, do_device, '', DAQmx_Val_ChanForAllLines) + DAQmxCreateCOPulseChanFreq(self.co_handle, 'cDAQ1/Ctr0', '', DAQmx_Val_Hz, DAQmx_Val_Low, 0.0, samp_rate, 0.5) ## Creates a channel to generate digital pulses + DAQmxCreateDOChan(self.do_handle, do_device, '', DAQmx_Val_ChanForAllLines) self.totalLength = numpy.uint64(samp_rate * secs) self.secs = secs @@ -518,6 +518,21 @@ def DoTask(self): self.totalLength * self.di_channels, byref(self.di_read), None) +def closeValves(do_device): + do_handle = TaskHandle(0) + DAQmxCreateTask('', byref(do_handle)) + + DAQmxCreateDOChan(do_handle, do_device, '', DAQmx_Val_ChanForAllLines) + DAQmxWriteDigitalU32(do_handle, 100, 0, -1, DAQmx_Val_GroupByChannel, numpy.zeros(100), + byref(int32()), None) + + DAQmxStartTask(do_handle) + DAQmxWaitUntilTaskDone(do_handle, 100) + + time.sleep(0.05) + DAQmxStopTask(do_handle) + DAQmxClearTask(do_handle) + # TODO TESTING # # region DoAiMultiTaskTest From 77569f35ebb30efd36ba2b6c67e96369f24cfc8d Mon Sep 17 00:00:00 2001 From: Tom Warner Date: Mon, 22 Feb 2021 14:02:59 +0000 Subject: [PATCH 6/9] basic print statement --- DAQ.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DAQ.py b/DAQ.py index 4ac0643..4579206 100644 --- a/DAQ.py +++ b/DAQ.py @@ -306,6 +306,8 @@ def __init__(self, do_device, co_device, samp_rate, secs, write): self.write = Util.binary_to_digital_map(write) self.sampsPerChan = self.write.shape[1] self.write = numpy.sum(self.write, axis=0) + print(self.write.shape) + print(self.write[:200]) DAQmxCfgImplicitTiming(self.co_handle, DAQmx_Val_FiniteSamps, self.totalLength) DAQmxCfgSampClkTiming(self.do_handle, '/cDAQ1/Ctr0InternalOutput', samp_rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, @@ -319,8 +321,6 @@ def DoTask(self): DAQmxStartTask(self.co_handle) DAQmxWaitUntilTaskDone(self.co_handle, 100) DAQmxWaitUntilTaskDone(self.do_handle, 100) - - self.ClearTasks() def ClearTasks(self): From 0d370a294fe54c7745599e50e1262766b523c268 Mon Sep 17 00:00:00 2001 From: Tom Warner Date: Tue, 23 Feb 2021 13:12:51 +0000 Subject: [PATCH 7/9] fixed close valve function --- DAQ.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/DAQ.py b/DAQ.py index 2fe973d..1d16025 100644 --- a/DAQ.py +++ b/DAQ.py @@ -520,16 +520,28 @@ def DoTask(self): def closeValves(do_device): do_handle = TaskHandle(0) + co_handle = TaskHandle(1) DAQmxCreateTask('', byref(do_handle)) - - DAQmxCreateDOChan(do_handle, do_device, '', DAQmx_Val_ChanForAllLines) - DAQmxWriteDigitalU32(do_handle, 100, 0, -1, DAQmx_Val_GroupByChannel, numpy.zeros(100), + DAQmxCreateTask('', byref(co_handle)) + + DAQmxCreateCOPulseChanFreq(co_handle, 'cDAQ1/Ctr0', '', DAQmx_Val_Hz, DAQmx_Val_Low, 0.0, 20000, 0.5) + DAQmxCreateDOChan(do_handle, do_device, '', DAQmx_Val_ChanForAllLines) + + DAQmxCfgImplicitTiming(co_handle, DAQmx_Val_FiniteSamps, 100) + DAQmxCfgSampClkTiming(do_handle, '/cDAQ1/Ctr0InternalOutput', 20000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, + numpy.uint64(100)) + DAQmxWriteDigitalU32(do_handle, 100, 0, -1, DAQmx_Val_GroupByChannel, numpy.zeros(100, dtype=numpy.uint32), byref(int32()), None) DAQmxStartTask(do_handle) - DAQmxWaitUntilTaskDone(do_handle, 100) + DAQmxStartTask(co_handle) + # DAQmxWaitUntilTaskDone(co_handle, 100) + # DAQmxWaitUntilTaskDone(do_handle, 100) time.sleep(0.05) + DAQmxStopTask(co_handle) + DAQmxClearTask(co_handle) + DAQmxStopTask(do_handle) DAQmxClearTask(do_handle) From 5124b0b46c82812c627528e16703ea9643745379 Mon Sep 17 00:00:00 2001 From: Tom Warner Date: Mon, 3 May 2021 14:20:24 +0100 Subject: [PATCH 8/9] some carrier flow control additions --- DAQ.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/DAQ.py b/DAQ.py index 1d16025..a3b4a26 100644 --- a/DAQ.py +++ b/DAQ.py @@ -240,9 +240,10 @@ def DoneCallback(self, status): # region [MultiTasks] class DoTriggeredCoTask: - def __init__(self, do_device, co_device, samp_rate, secs, write, trigger_source): + def __init__(self, do_device, co_device, samp_rate, secs, write, trigger_source, controlled_carrier=False): self.do_handle = TaskHandle(0) self.co_handle = TaskHandle(1) + self.do_device = do_device DAQmxCreateTask('', byref(self.do_handle)) @@ -258,9 +259,10 @@ def __init__(self, do_device, co_device, samp_rate, secs, write, trigger_source) self.sampsPerChanWritten = int32() self.write = Util.binary_to_digital_map(write) self.sampsPerChan = self.write.shape[1] + self.chans = self.write.shape[0] self.write = numpy.sum(self.write, axis=0) - - + if controlled_carrier: + self.write += 2**(self.chans+1) DAQmxCfgImplicitTiming(self.co_handle, DAQmx_Val_FiniteSamps, self.totalLength) DAQmxCfgSampClkTiming(self.do_handle, '/cDAQ1/Ctr0InternalOutput', samp_rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, numpy.uint64(self.totalLength)) @@ -287,12 +289,13 @@ def ClearTasks(self): DAQmxClearTask(self.do_handle) DAQmxClearTask(self.co_handle) - + #closeValves(self.do_device) class DoCoTask: - def __init__(self, do_device, co_device, samp_rate, secs, write): + def __init__(self, do_device, co_device, samp_rate, secs, write, controlled_carrier=False): self.do_handle = TaskHandle(0) self.co_handle = TaskHandle(1) + self.do_device = do_device DAQmxCreateTask('', byref(self.do_handle)) DAQmxCreateTask('', byref(self.co_handle)) @@ -305,9 +308,13 @@ def __init__(self, do_device, co_device, samp_rate, secs, write): self.sampsPerChanWritten = int32() self.write = Util.binary_to_digital_map(write) self.sampsPerChan = self.write.shape[1] + self.chans = self.write.shape[0] self.write = numpy.sum(self.write, axis=0) - print(self.write.shape) - print(self.write[:200]) + # if controlled_carrier: + # self.write += 2**(self.chans+1) + print(self.write) + print(len(self.write)) + print(type(self.write[0])) DAQmxCfgImplicitTiming(self.co_handle, DAQmx_Val_FiniteSamps, self.totalLength) DAQmxCfgSampClkTiming(self.do_handle, '/cDAQ1/Ctr0InternalOutput', samp_rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, @@ -330,6 +337,7 @@ def ClearTasks(self): DAQmxClearTask(self.do_handle) DAQmxClearTask(self.co_handle) + #closeValves(self.do_device) class DoAiMultiTask: def __init__(self, ai_device, ai_channels, do_device, samp_rate, secs, write, sync_clock): @@ -546,6 +554,52 @@ def closeValves(do_device): DAQmxClearTask(do_handle) +## TODO generalise for other devices, currently needs to be the same one as the valves +# def carrierControlTask(do_device, samp_rate, secs): +# do_handle = TaskHandle(2) +# co_handle = TaskHandle(3) +# DAQmxCreateTask('', byref(do_handle)) +# DAQmxCreateTask('', byref(co_handle)) +# DAQmxCreateCOPulseChanFreq(co_handle, 'cDAQ1/Ctr0', '', DAQmx_Val_Hz, DAQmx_Val_Low, 0.0, samp_rate, 0.5) ## Creates a channel to generate digital pulses +# DAQmxCreateDOChan(do_handle, do_device, '', DAQmx_Val_ChanForAllLines) +# totallength = numpy.uint64(samp_rate * secs) +# secs = secs +# sampsPerChanWritten = int32() +# chan_index = int(do_device[-1]) +# write = np.ones(totallength)*(2**chan_index) +# write = write.astype(np.uint32) +# print(write) +# DAQmxCfgImplicitTiming(co_handle, DAQmx_Val_FiniteSamps, totallength) +# DAQmxCfgSampClkTiming(do_handle, '/cDAQ1/Ctr0InternalOutput', samp_rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, +# numpy.uint64(totallength)) +# DAQmxWriteDigitalU32(do_handle, len(write), 0, -1, DAQmx_Val_GroupByChannel, write, +# byref(sampsPerChanWritten), None) +# DAQmxStartTask(do_handle) +# DAQmxStartTask(co_handle) +# DAQmxWaitUntilTaskDone(co_handle, 100) +# DAQmxWaitUntilTaskDone(do_handle, 100) +# # do_handle = TaskHandle(2) +# # DAQmxCreateTask('', byref(do_handle)) +# # DAQmxCreateDOChan(do_handle, do_device, '', DAQmx_Val_ChanForAllLines) +# # totallength = numpy.uint64(samp_rate * secs) +# # secs = secs +# # sampsPerChanWritten = int32() +# # write = np.ones(totallength)*512 +# # write = write.astype(np.uint32) +# # print(write) +# # DAQmxCfgSampClkTiming(do_handle, '/cDAQ1/Ctr0InternalOutput', samp_rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, +# # numpy.uint64(totallength)) +# # DAQmxWriteDigitalU32(do_handle, totallength, 0, -1, DAQmx_Val_GroupByChannel, write, +# # byref(sampsPerChanWritten), None) +# # DAQmxStartTask(do_handle) +# # DAQmxWaitUntilTaskDone(do_handle, 10) +# DAQmxStopTask(co_handle) +# DAQmxClearTask(co_handle) +# DAQmxStopTask(do_handle) +# DAQmxClearTask(do_handle) + + +# carrierControlTask(do_device, 20000, 2) # TODO TESTING # # region DoAiMultiTaskTest # a = DoAiMultiTask('cDAQ1Mod3/ai0', 1, 'cDAQ1Mod1/port0/line0', 1000.0, 1.0, numpy.zeros((2, 1000)), From 3f521f20eb436f98d5231da63947dfed3f1feb36 Mon Sep 17 00:00:00 2001 From: Tom Warner Date: Thu, 10 Mar 2022 13:43:11 +0000 Subject: [PATCH 9/9] hopeful removal of print message --- DAQ.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/DAQ.py b/DAQ.py index a3b4a26..2a3ed76 100644 --- a/DAQ.py +++ b/DAQ.py @@ -312,9 +312,6 @@ def __init__(self, do_device, co_device, samp_rate, secs, write, controlled_carr self.write = numpy.sum(self.write, axis=0) # if controlled_carrier: # self.write += 2**(self.chans+1) - print(self.write) - print(len(self.write)) - print(type(self.write[0])) DAQmxCfgImplicitTiming(self.co_handle, DAQmx_Val_FiniteSamps, self.totalLength) DAQmxCfgSampClkTiming(self.do_handle, '/cDAQ1/Ctr0InternalOutput', samp_rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps,