Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Rework on acq2106_435st trigger selection. #2284

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions pydevices/HtsDevices/acq2106_435sc.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,37 @@ class _ACQ2106_435SC(acq2106_435st._ACQ2106_435ST):
]

def init(self):
uut = self.getUUT()
self.slots = super(_ACQ2106_435SC, self).getSlots()

for card in self.slots:
if self.is_global.data() == 1:
# Global controls for GAINS and OFFSETS
self.slots[card].SC32_OFFSET_ALL = self.def_offset.data()
print("Site {} OFFSET ALL {}".format(card, self.def_offset.data()))

if self.debug:
print("Site %s OFFSET ALL %d" % (card, int(self.def_offset.data())))

self.slots[card].SC32_G1_ALL = self.def_gain1.data()
print("Site {} GAIN 1 ALL {}".format(card, self.def_gain1.data()))

if self.debug:
print("Site %s GAIN 1 ALL %d" % (card, int(self.def_gain1.data())))

self.slots[card].SC32_G2_ALL = self.def_gain2.data()
print("Site {} GAIN 2 ALL {}".format(card, self.def_gain2.data()))

if self.debug:
print("Site %s GAIN 2 ALL %d" % (card, int(self.def_gain2.data())))
else:
self.setGainsOffsets(card)

self.slots[card].SC32_GAIN_COMMIT = 1
print("GAINs Committed for site {}".format(card))

if self.debug:
print("GAINs Committed for site %s" % (card,))

# Here, the argument to the init of the superclass:
# - init(True) => use resampling function:
# makeSegmentResampled(begin, end, dim, b, resampled, res_factor)
super(_ACQ2106_435SC, self).init(resampling = True)
super(_ACQ2106_435SC, self).init(resampling=True)

INIT=init

Expand All @@ -104,7 +112,6 @@ def getUUT(self):
return uut

def setGainsOffsets(self, card):
uut = self.getUUT()
for ic in range(1,32+1):
if card == 1:
setattr(self.slots[card], 'SC32_OFFSET_%2.2d' % (ic,), getattr(self, 'INPUT_%3.3d:SC_OFFSET' % (ic,)).data())
Expand Down Expand Up @@ -141,46 +148,46 @@ def assemble(cls):
'options': ('no_write_model', 'write_once',)
},
{
'path': ':INPUT_%3.3d:DECIMATE'%(i+1,),
'path': ':INPUT_%3.3d:DECIMATE' % (i+1,),
'type':'NUMERIC',
'valueExpr':'head.def_dcim',
'options':('no_write_shot',)
},
{
'path': ':INPUT_%3.3d:COEFFICIENT'%(i+1,),
'path': ':INPUT_%3.3d:COEFFICIENT' % (i+1,),
'type':'NUMERIC',
'options':('no_write_model',
'write_once',)
},
{
'path': ':INPUT_%3.3d:OFFSET'%(i+1,),
'path': ':INPUT_%3.3d:OFFSET' % (i+1,),
'type':'NUMERIC',
'options':('no_write_model', 'write_once',)
},
{
# Local (per channel) SC gains
'path': ':INPUT_%3.3d:SC_GAIN1'%(i+1,),
'path': ':INPUT_%3.3d:SC_GAIN1' % (i+1,),
'type':'NUMERIC',
'valueExpr':'head.def_gain1',
'options':('no_write_shot',)
},
{
# Local (per channel) SC gains
'path': ':INPUT_%3.3d:SC_GAIN2'%(i+1,),
'path': ':INPUT_%3.3d:SC_GAIN2' % (i+1,),
'type':'NUMERIC',
'valueExpr':'head.def_gain2',
'options':('no_write_shot',)
},
{
# Local (per channel) SC offsets
'path': ':INPUT_%3.3d:SC_OFFSET'%(i+1,),
'path': ':INPUT_%3.3d:SC_OFFSET' % (i+1,),
'type':'NUMERIC',
'valueExpr':'head.def_offset',
'options':('no_write_shot',)
},
{
# Conditioned signal goes here:
'path': ':INPUT_%3.3d:SC_INPUT'%(i+1,),
'path': ':INPUT_%3.3d:SC_INPUT' % (i+1,),
'type': 'SIGNAL',
'valueExpr':
'ADD(MULTIPLY(head.INPUT_%3.3d, MULTIPLY(head.INPUT_%3.3d.SC_GAIN1, head.INPUT_%3.3d.SC_GAIN2)), head.INPUT_%3.3d.SC_OFFSET)'
Expand Down
137 changes: 73 additions & 64 deletions pydevices/HtsDevices/acq2106_435st.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,10 @@ class _ACQ2106_435ST(MDSplus.Device):
'valueExpr': "Action(Dispatch('CAMAC_SERVER','STORE',50,None),Method(None,'STOP',head))",
'options': ('no_write_shot',)
},

#Trigger sources
{
'path':':TRIG_SRC',
'type':'text',
'value': 'NONE',
'options':('no_write_shot',)
},
]

data_socket = -1

trig_types = ['hard', 'soft', 'automatic']

class MDSWorker(threading.Thread):
NUM_BUFFERS = 20

Expand Down Expand Up @@ -222,10 +212,8 @@ def __init__(self, dev):
self.device_thread = self.DeviceWorker(self)

def run(self):
import acq400_hapi
import ast
import re
uut = acq400_hapi.Acq400(self.dev.node.data(), monitor=False)

def lcm(a, b):
from fractions import gcd
Expand Down Expand Up @@ -389,29 +377,43 @@ def run(self):
else:
self.full_buffers.put(buf)

def init(self, resampling = False):
import acq400_hapi
MIN_FREQUENCY = 10000
# The minimum frequency we can operate at
MIN_FREQUENCY = 10000

uut = acq400_hapi.Acq400(self.node.data(), monitor=False)
# These are partial lists of the options we support.
# For a complete list, consult D-Tacq

# Trigger Source Options for Signal Highway d0
TRIG_SRC_OPTS_0 = [
'ext', # External Trigger
'hdmi', # HDMI Trigger
'gpg0', # Gateway Pulse Generator Trigger
'wrtt0' # White Rabbit Trigger
]

# Trigger Source Options for Signal Highway d1
TRIG_SRC_OPTS_1 = [
'strig', # Software Trigger
'hdmi_gpio', # HDMI General Purpose I/O Trigger
'gpg1', # Gateway Pulse Generator Trigger
'fp_sync', # Front Panel SYNC
'wrtt1' # White Rabbit Trigger
]

def init(self, resampling=False):
uut = self.getUUT()
uut.s0.set_knob('set_abort', '1')

if self.ext_clock.length > 0:
raise Exception('External Clock is not supported')

# Initializing Sources to NONE:
# D0 signal:
uut.s0.SIG_SRC_TRG_0 = 'NONE'
# D1 signal:
uut.s0.SIG_SRC_TRG_1 = 'NONE'

freq = int(self.freq.data())
# D-Tacq Recommendation: the minimum sample rate is 10kHz.
if freq < MIN_FREQUENCY:
if freq < self.MIN_FREQUENCY:
raise MDSplus.DevBAD_PARAMETER(
"Sample rate should be greater or equal than 10kHz")

mode = self.trig_mode.data()
mode = str(self.trig_mode.data()).lower()
if mode == 'hard':
role = 'master'
trg = 'hard'
Expand All @@ -422,39 +424,41 @@ def init(self, resampling = False):
role = mode.split(":")[0]
trg = mode.split(":")[1]

print("Role is {} and {} trigger".format(role, trg))
if self.debug:
print("Role is %s and %s trigger" % (role, trg))


src_trg_0 = None
src_trg_1 = None

if trg == 'hard':
trg_dx = 'd0'
elif trg == 'automatic':
src_trg_0 = 'EXT' # External Trigger
elif trg == 'soft' or trg == 'automatic':
trg_dx = 'd1'
elif trg == 'soft':
src_trg_1 = 'STRIG' # Soft Trigger
elif trg in self.TRIG_SRC_OPTS_0:
trg_dx = 'd0'
src_trg_0 = trg
elif trg in self.TRIG_SRC_OPTS_1:
trg_dx = 'd1'
src_trg_1 = trg
elif trg != 'none':
raise MDSplus.DevBAD_PARAMETER("TRIG_MODE does not contain a valid trigger source")

# USAGE sync_role {fpmaster|rpmaster|master|slave|solo} [CLKHZ] [FIN]
# modifiers [CLK|TRG:SENSE=falling|rising] [CLK|TRG:DX=d0|d1]
# modifiers [TRG=int|ext]
# modifiers [CLKDIV=div]
uut.s0.sync_role = '%s %s TRG:DX=%s' % (role, self.freq.data(), trg_dx)

# The following allows for any source to be chosen, among other things the WR source.
# Signal highway d0:
srcs_0 = ['EXT', 'HDMI', 'HOSTB', 'GPG0', 'DSP0', 'nc', 'WRTT0', 'NONE']
# Signal highway d1:
srcs_1 = ['STRIG', 'HOSTA', 'HDMI_GPIO', 'GPG1', 'DSP1', 'FP_SYNC', 'WRTT1', 'NONE']

if trg_dx == 'd0':
if str(self.trig_src.data()) in srcs_0:
uut.s0.SIG_SRC_TRG_0 = str(self.trig_src.data())
else:
sys.exit("TRIG_SRC should be one of {}".format(srcs_0))

elif trg_dx == 'd1':
if str(self.trig_src.data()) in srcs_1:
uut.s0.SIG_SRC_TRG_1 = str(self.trig_src.data())
else:
sys.exit("TRIG_SRC should be one of {}".format(srcs_1))
# snyc_role will set a default trigger source, we need to override it to the selected trigger source
# These must be uppercase
if src_trg_0:
uut.s0.SIG_SRC_TRG_0 = src_trg_0.upper()

if src_trg_1:
uut.s0.SIG_SRC_TRG_1 = src_trg_1.upper()

# Fetching all calibration information from every channel.
uut.fetch_all_calibration()
Expand All @@ -473,63 +477,68 @@ def init(self, resampling = False):

# Hardware decimation:
if self.debug:
print("Hardware Filter (NACC) from tree node is {}".format(
print("Hardware Filter (NACC) from tree node is %d" % (
int(self.hw_filter.data())))

# Hardware Filter: Accumulate/Decimate filter. Accumulate nacc_samp samples, then output one value.
nacc_samp = int(self.hw_filter.data())
print("Number of sites in use {}".format(self.sites))

if self.debug:
print("Number of sites in use %d" % (self.sites,))

# Get the slots (aka sites, or cards) that are physically active in the chassis of the ACQ
self.slots = self.getSlots()

for card in self.slots:
if 1 <= nacc_samp <= 32:
if nacc_samp >= 1 and nacc_samp <= 32:
for card in self.slots:
self.slots[card].nacc = ('%d' % nacc_samp).strip()
else:
print(
"WARNING: Hardware Filter samples must be in the range [0,32]. 0 => Disabled == 1")
self.slots[card].nacc = '1'
else:
print("WARNING: Hardware Filter samples must be in the range [0,32]. 0 => Disabled == 1")
self.slots[card].nacc = '1'

self.running.on = True
# If resampling=1, then resampling is used during streaming:
# If resampling == 1, then resampling is used during streaming:
self.resampling = resampling

thread = self.MDSWorker(self)
thread.start()
INIT = init

def getSlots(self):
import acq400_hapi
uut = acq400_hapi.Acq400(self.node.data(), monitor=False)
uut = self.getUUT()

# Ask UUT what are the sites that are actually being populatee with a 435ELF
slot_list = {}
for (site, module) in sorted(uut.modules.items()):
for (site, _) in sorted(uut.modules.items()):
site_number = int(site)
if site_number == 1:
slot_list[site_number]=uut.s1
slot_list[site_number] = uut.s1
elif site_number == 2:
slot_list[site_number]=uut.s2
slot_list[site_number] = uut.s2
elif site_number == 3:
slot_list[site_number]=uut.s3
slot_list[site_number] = uut.s3
elif site_number == 4:
slot_list[site_number]=uut.s4
slot_list[site_number] = uut.s4
elif site_number == 5:
slot_list[site_number]=uut.s5
slot_list[site_number] = uut.s5
elif site_number == 6:
slot_list[site_number]=uut.s6
slot_list[site_number] = uut.s6
return slot_list

def stop(self):
self.running.on = False
STOP = stop

def trig(self):
import acq400_hapi
uut = acq400_hapi.Acq400(self.node.data(), monitor=False)
uut = self.getUUT()
uut.s0.set_knob('soft_trigger', '1')
TRIG = trig

def getUUT(self):
import acq400_hapi
uut = acq400_hapi.Acq400(self.node.data(), monitor=False, has_wr=True)
return uut

def setChanScale(self, num):
chan = self.__getattr__('INPUT_%3.3d' % num)
chan.setSegmentScale(MDSplus.ADD(MDSplus.MULTIPLY(
Expand Down