Skip to content

Commit

Permalink
Merge branch 'python' of https://github.com/CMS-HGCAL/rpi-daq into py…
Browse files Browse the repository at this point in the history
…thon
  • Loading branch information
DAQ committed Apr 18, 2018
2 parents 51e1cfc + 3867af6 commit 05bd8d4
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 24 deletions.
5 changes: 3 additions & 2 deletions daq-zmq-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def get_comma_separated_args(option, opt, value, parser):
parser = OptionParser()
parser.add_option("-a", "--externalChargeInjection", dest="externalChargeInjection",action="store_true",
help="set to use external injection",default=False)
parser.add_option("-b", "--acquisitionType", dest="acquisitionType",choices=["standard","sweep","fixed","const_inj"],
help="method for injection", default="standard")
choices_m=["standard","sweep","fixed","const_inj","instrumental_trigger","external_trigger"]
parser.add_option("-e", "--acquisitionType", dest="acquisitionType",choices=choices_m,
help="acquisition method, valid choices are:\t%s"%(choices_m), default="standard")
parser.add_option('-c', '--channelIds', dest="channelIds",action="callback",type=str,
help="channel Ids for charge injection", callback=get_comma_separated_args, default=[])
parser.add_option('-d','--injectionDAC',dest="injectionDAC",type="int",action="store",default=1000,
Expand Down
112 changes: 92 additions & 20 deletions rpi_daq.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def __init__(self,yaml_options,DAC_HIGH_WORD=0x42,DAC_LOW_WORD=0x0A,TRIGGER_DELA
res = self.gpio.set_bus_init()
##empty the fifo:
for i in xrange(0,33000):
res = self.gpio.read_local_fifo();
res = self.gpio.read_local_fifo()

if self.daq_options['externalChargeInjection']==False:
res = self.gpio.set_trigger_delay(self.TRIGGER_DELAY);
res = self.gpio.set_trigger_delay(self.TRIGGER_DELAY)
else:
res = self.gpio.set_trigger_delay(self.daq_options['pulseDelay']);
res = self.gpio.send_command(self.CMD_RSTBPULSE);
res = self.gpio.send_command(self.CMD_SETSELECT | 1);
res = self.gpio.set_trigger_delay(self.daq_options['pulseDelay'])
res = self.gpio.send_command(self.CMD_RSTBPULSE)
res = self.gpio.send_command(self.CMD_SETSELECT | 1)

if self.daq_options['compressRawData']==True:
self.rawdata=[0 for i in xrange(15394)]#15392 bytes of data + 2 bytes for injetion value
Expand All @@ -76,11 +76,11 @@ def configure(self,bit_string):
if len(bit_string)==384:
outputBitString=(ctypes.c_ubyte*384)()
print "try to prog with 384 bytes:\t",
self.gpio.progandverify384(bit_string,outputBitString);
self.gpio.progandverify384(bit_string,outputBitString)
print "completed"
elif len(bit_string)==48:
print "try to prog with 48 bytes:\t",
self.gpio.progandverify48(bit_string,outputBitString);
self.gpio.progandverify48(bit_string,outputBitString)
print "completed"
else:
print("size of bit string not correct : should be 48 or 384 instead of ",len(bit_string),"\t-> exit")
Expand All @@ -98,6 +98,75 @@ def configure(self,bit_string):

##########################################################

def configure_4chips(self,bit_string):
print("Configure rpi-daq")

self.eventID=0

print "\t send different bits string to the 4 chips:\t",
outputBitString=(ctypes.c_ubyte*48*4)()
if len(bit_string)==384*4:
outputBitString=(ctypes.c_ubyte*384*4)()
print "try to prog with 384*4 bytes:\t",
self.gpio.progandverify384_4chips(bit_string,outputBitString)
print "completed"
elif len(bit_string)==48*4:
print "try to prog with 48*4 bytes:\t",
self.gpio. progandverify48_4chips(bit_string,outputBitString)
print "completed"
else:
print("size of bit string not correct : should be 48*4 or 384*4 instead of ",len(bit_string),"\t-> exit")
sys.exit(1)

print("outputBitString = ",outputBitString)

res=self.gpio.send_command(self.CMD_SETSELECT)
sleep(0.01)

print("Configure completed")
return outputBitString

# print("Configure completed")

##########################################################

def acquire(self):
if self.daq_options['acquisitionType']=="instrumental_trigger" or self.daq_options['acquisitionType']=="external_trigger":
res = self.gpio.send_command(self.CMD_SETSTARTACQ | 1)

if self.daq_options['acquisitionType']=="instrumental_trigger":
res = self.gpio.instrumental_trigger()#firmware sets the trigger to the pin -> external device (e.g. pulse generator) -> external trigger

else:
if self.daq_options['acquisitionType']=="fixed":
res = self.gpio.fixed_acquisition()

elif self.daq_options['acquisitionType']=="standard":
res = self.gpio.send_command(self.CMD_SETSTARTACQ | 1)
sleep(0.00001)
res = self.gpio.send_command(self.CMD_SETSTARTACQ) ## <<<+++ THIS IS THE TRIGGER ##

elif self.daq_options['acquisitionType']=="sweep" or self.daq_options['acquisitionType']=="const_inj":
res = self.gpio.send_command(self.CMD_SETSTARTACQ | 1)
sleep(0.00001)
res = self.gpio.calib_gen()

# still needed when no hardware trigger
res = self.gpio.send_command(self.CMD_STARTCONPUL)
sleep(0.003)
res =self.gpio.send_command(self.CMD_STARTROPUL)


while True:
fifoSize = (self.gpio.read_usedwh() << 8) | self.gpio.read_usedwl()
if fifoSize>2000: #smaller value can be used when running without debug
#print "Done with fifoSize = ",fifoSize #comment this out when running whithout debug
break
else:
#print "fifoSize = ",fifoSize #comment this out when running whithout debug
sleep(0.0001)


def processEvent(self):
print("Start events acquisition %d",self.eventID)
dac_ctrl=0
Expand All @@ -122,20 +191,23 @@ def processEvent(self):
res = self.gpio.set_dac_low_word(self.DAC_LOW_WORD)

res = self.gpio.send_command(self.CMD_RESETPULSE)
sleep(0.0001);
if self.daq_options['acquisitionType']=="fixed":
res = self.gpio.fixed_acquisition()
else:
res = self.gpio.send_command(self.CMD_SETSTARTACQ | 1)
if self.daq_options['externalChargeInjection']==False:
res = self.gpio.send_command(self.CMD_SETSTARTACQ) ## <<<+++ THIS IS THE TRIGGER ##
else:
res = self.gpio.calib_gen()

res = self.gpio.send_command(self.CMD_STARTCONPUL)
sleep(0.003)
res =self.gpio.send_command(self.CMD_STARTROPUL)
sleep(0.0001)

self.acquire()

# if self.daq_options['acquisitionType']=="fixed":
# res = self.gpio.fixed_acquisition()
# else:
# res = self.gpio.send_command(self.CMD_SETSTARTACQ | 1)
# if self.daq_options['externalChargeInjection']==False:
# res = self.gpio.send_command(self.CMD_SETSTARTACQ) ## <<<+++ THIS IS THE TRIGGER ##
# else:
# res = self.gpio.calib_gen()

# res = self.gpio.send_command(self.CMD_STARTCONPUL)
# sleep(0.003)
# res =self.gpio.send_command(self.CMD_STARTROPUL)
# sleep(0.0001)

t = self.gpio.read_local_fifo()
if self.daq_options['compressRawData']==True:
Expand Down
11 changes: 9 additions & 2 deletions run_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def get_comma_separated_args(option, opt, value, parser):
parser = OptionParser()
parser.add_option("-d", "--externalChargeInjection", dest="externalChargeInjection",action="store_true",
help="set to use external injection",default=False)
parser.add_option("-e", "--acquisitionType", dest="acquisitionType",choices=["standard","sweep","fixed","const_inj"],
help="method for injection", default="standard")
choices_m=["standard","sweep","fixed","const_inj","instrumental_trigger","external_trigger"]
parser.add_option("-e", "--acquisitionType", dest="acquisitionType",choices=choices_m,
help="acquisition method, valid choices are:\t%s"%(choices_m), default="standard")
parser.add_option('-f', '--channelIds', dest="channelIds",action="callback",type=str,
help="channel Ids for charge injection", callback=get_comma_separated_args, default=[])
parser.add_option('-g','--injectionDAC',dest="injectionDAC",type="int",action="store",default=1000,
Expand Down Expand Up @@ -74,6 +75,12 @@ def get_comma_separated_args(option, opt, value, parser):
the_bits_c_uchar_p=the_bit_string.get_48_unsigned_char_p()
print( [hex(the_bits_c_uchar_p[i]) for i in range(48)] )

c_uchar_p = (ctypes.c_ubyte*192)()
for i in xrange(192):
index=i%48
c_uchar_p[i]=the_bits_c_uchar_p[index]
print( [hex(c_uchar_p[i]) for i in xrange(192)] )

theDaq=rpi_daq.rpi_daq(daq_options)
outputBitString=theDaq.configure(the_bits_c_uchar_p)

Expand Down
Loading

0 comments on commit 05bd8d4

Please sign in to comment.