diff --git a/Python/lib/AWG.py b/Python/lib/AWG.py index 558680579a21ae197d5f15a67b9a4710b342ac4a..2b87c522d0e71fca6b065fc15f0b2a36f0054534 100644 --- a/Python/lib/AWG.py +++ b/Python/lib/AWG.py @@ -230,18 +230,25 @@ class AWG: "HOLDLAST": SPCM_STOPLVL_HOLDLAST} if not self.is_connected(): return - if self.channel[ch] == 0: - self.channel[ch] = 1 - self.ch_amp = amplitude - spcm_dwSetParam_i64(self.card, SPC_CHENABLE, int64(2**ch)) # see CHANNEL0-3 in regs.py for detail - spcm_dwSetParam_i32(self.card, SPC_ENABLEOUT0 + ch * (SPC_ENABLEOUT1 - SPC_ENABLEOUT0), 1) - spcm_dwSetParam_i32(self.card, SPC_AMP0 + ch * (SPC_AMP1 - SPC_AMP0), amplitude) - spcm_dwSetParam_i32(self.card, SPC_CH0_STOPLEVEL + ch * (SPC_CH1_STOPLEVEL - SPC_CH0_STOPLEVEL), stopmask[stoplvl]) - else: - self.channel[ch] = 0 - spcm_dwSetParam_i32(self.card, SPC_ENABLEOUT0 + ch * (SPC_ENABLEOUT1 - SPC_ENABLEOUT0), 0) - # self.check_error("Checking error at enable_channel") - # print("Channels enabled: ", self.channel) + enable_mask = 0 + + for c in ch: + self.channel[c] = 1 + enable_mask = enable_mask | 2**c + spcm_dwSetParam_i64(self.card, SPC_CHENABLE, enable_mask) # see CHANNEL0-3 in regs.py for detail + + for c in ch: + c = int(c) + spcm_dwSetParam_i32(self.card, SPC_ENABLEOUT0 + c * (SPC_ENABLEOUT1 - SPC_ENABLEOUT0), 1) + spcm_dwSetParam_i32(self.card, SPC_AMP0 + c * (SPC_AMP1 - SPC_AMP0), amplitude) + spcm_dwSetParam_i32(self.card, SPC_CH0_STOPLEVEL + c * (SPC_CH1_STOPLEVEL - SPC_CH0_STOPLEVEL), stopmask[stoplvl]) + + def get_channel_count(self) -> int: + if not self.is_connected(): + return + chcount = int32(0) + spcm_dwGetParam_i32(self.card, SPC_CHCOUNT, byref(chcount)) + return chcount.value def set_trigger(self, **kwargs): """ @@ -302,11 +309,12 @@ class AWG: if self.mode != "Sequence Replay": print("Wrong method, current mode is: " + self.mode) return - nch = np.sum(self.channel) # number of activated channels + chcount = int32(0) + spcm_dwGetParam_i32(self.card, SPC_CHCOUNT, byref(chcount)) # if data.dtype != int: # sys.stdout.write("data must be in int type\n") # return - if data.size > self.mem_size.value / np.sum(self.channel) / 2: + if data.size > self.mem_size.value / chcount.value / 2: sys.stdout.write("data is too big") return spcm_dwSetParam_i32(self.card, SPC_SEQMODE_WRITESEGMENT, segment) # set current segment to write on @@ -314,13 +322,15 @@ class AWG: # data transfer sample_len = data.size - buflength = uint32(sample_len * 2 * nch) # samples * (2 bytes/sample) * number of activated channels + buflength = uint32(sample_len * 2) # samples * (2 bytes/sample) data_ptr = data.ctypes.data_as(ptr16) # cast data array into a c-like array buffer = pvAllocMemPageAligned(sample_len * 2) # buffer now holds a page-aligned location buffer_data = cast(addressof(buffer), ptr16) # cast it to int16 array memmove(buffer_data, data_ptr, sample_len * 2) # moving data into the page-aligned block - spcm_dwDefTransfer_i64(self.card, SPCM_BUF_DATA, SPCM_DIR_PCTOCARD, int32(0), byref(buffer), int64(0), int64(buflength.value)) + spcm_dwDefTransfer_i64(self.card, SPCM_BUF_DATA, SPCM_DIR_PCTOCARD, 0, byref(buffer), 0, buflength) + # self.check_error("Checking error at write_segment") spcm_dwSetParam_i32(self.card, SPC_M2CMD, M2CMD_DATA_STARTDMA | M2CMD_DATA_WAITDMA) + spcm_dwSetParam_i32(self.card, SPC_M2CMD, M2CMD_DATA_STOPDMA) # self.check_error("Checking error at write_segment") def configure_step(self, step: int, segment: int, nextstep: int, loop: int, condition: int):