rename from counterbox to daq
This commit is contained in:
@ -14,13 +14,13 @@ TOTAL_CH = int(sys.argv[2]) # Number of Channels
|
||||
LOG2FILE = False if len(sys.argv) < 4 else bool(int(sys.argv[3]))
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger('counterbox')
|
||||
logger = logging.getLogger('daq')
|
||||
|
||||
if LOG2FILE:
|
||||
logging.basicConfig(filename=os.path.join(os.getcwd(), 'counterbox_sim.log'), level=logging.INFO)
|
||||
logging.basicConfig(filename=os.path.join(os.getcwd(), 'daq_sim.log'), level=logging.INFO)
|
||||
|
||||
|
||||
class CounterBox:
|
||||
class DAQ:
|
||||
def __init__(self, total_channels):
|
||||
self.total_channels = total_channels
|
||||
self.counts = [0] * self.total_channels
|
||||
@ -66,7 +66,7 @@ class CounterBox:
|
||||
return self.counts[channel - 1]
|
||||
|
||||
def getCounts(self):
|
||||
# The sinqtest box returns a maximum of 8
|
||||
# The sinqtest daq returns a maximum of 8
|
||||
return self.counts[0:min(len(self.counts), 8)]
|
||||
|
||||
def getMonitorCount(self):
|
||||
@ -217,7 +217,7 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
logger.info(f'RECEIVED: "{received}"')
|
||||
return received
|
||||
|
||||
counterbox = CounterBox(TOTAL_CH)
|
||||
daq = DAQ(TOTAL_CH)
|
||||
|
||||
while True:
|
||||
|
||||
@ -232,85 +232,85 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
send('')
|
||||
|
||||
elif data == 'ECHO 2':
|
||||
send('Counterbox') # Sends some sort of info command
|
||||
send('DAQ System Version Simulation') # Sends some sort of info command
|
||||
|
||||
elif data == 'RA':
|
||||
send(
|
||||
' '.join(map(str,
|
||||
[counterbox.getRunTime()] + \
|
||||
counterbox.getCounts()
|
||||
[daq.getRunTime()] + \
|
||||
daq.getCounts()
|
||||
))
|
||||
)
|
||||
|
||||
elif re.fullmatch(r'RC (\d+)', data):
|
||||
channel = int(re.fullmatch(r'RC (\d+)', data).group(1))
|
||||
count = counterbox.getCount(channel)
|
||||
count = daq.getCount(channel)
|
||||
send(f'{count}')
|
||||
|
||||
elif data == 'RS':
|
||||
send(str(counterbox.getStatus()))
|
||||
send(str(daq.getStatus()))
|
||||
|
||||
elif data == 'S':
|
||||
counterbox.stop()
|
||||
daq.stop()
|
||||
send('')
|
||||
|
||||
elif data == 'CT':
|
||||
counterbox.clearTime()
|
||||
daq.clearTime()
|
||||
send('')
|
||||
|
||||
elif re.fullmatch(r'CC (\d+)', data):
|
||||
counter = int(re.fullmatch(r'CC (\d+)', data).group(1))
|
||||
counterbox.clearCount(counter)
|
||||
daq.clearCount(counter)
|
||||
send('')
|
||||
|
||||
elif re.fullmatch(r'TP (\d+(\.\d+)?)', data):
|
||||
presettime = float(re.fullmatch(r'TP (\d+(\.\d+)?)', data).group(1))
|
||||
counterbox.startTimePreset(presettime)
|
||||
daq.startTimePreset(presettime)
|
||||
send('')
|
||||
|
||||
elif re.fullmatch(r'MP (\d+)', data):
|
||||
counts = int(re.fullmatch(r'MP (\d+)', data).group(1))
|
||||
counterbox.startCountPreset(counts)
|
||||
daq.startCountPreset(counts)
|
||||
send('')
|
||||
|
||||
elif data == 'PC':
|
||||
send(str(counterbox.getMonitorChannel()))
|
||||
send(str(daq.getMonitorChannel()))
|
||||
|
||||
elif re.fullmatch(r'PC (\d+)', data):
|
||||
channel = int(re.fullmatch(r'PC (\d+)', data).group(1))
|
||||
counterbox.setMonitorChannel(channel)
|
||||
daq.setMonitorChannel(channel)
|
||||
send('')
|
||||
|
||||
elif data == 'DR':
|
||||
send(str(counterbox.getMinRateChannel()))
|
||||
send(str(daq.getMinRateChannel()))
|
||||
|
||||
elif re.fullmatch(r'DR (\d+)', data):
|
||||
channel = int(re.fullmatch(r'DR (\d+)', data).group(1))
|
||||
counterbox.setMinRateChannel(channel)
|
||||
daq.setMinRateChannel(channel)
|
||||
send('')
|
||||
|
||||
elif re.fullmatch(r'DL (\d+)', data):
|
||||
channel = int(re.fullmatch(r'DL (\d+)', data).group(1))
|
||||
send('{:.3f}'.format(counterbox.getMinRate(channel)))
|
||||
send('{:.3f}'.format(daq.getMinRate(channel)))
|
||||
|
||||
elif re.fullmatch(r'DL (\d+) (\d+(?:.\d+)?)', data):
|
||||
channel, rate = re.fullmatch(r'DL (\d+) (\d+(?:.\d+)?)', data).groups()
|
||||
counterbox.setMinRate(int(channel), float(rate))
|
||||
daq.setMinRate(int(channel), float(rate))
|
||||
send('')
|
||||
|
||||
elif re.fullmatch(r'RR (\d+)', data):
|
||||
channel = int(re.fullmatch(r'RR (\d+)', data).group(1))
|
||||
send(counterbox.getRate(channel))
|
||||
send(daq.getRate(channel))
|
||||
|
||||
elif re.fullmatch(r'GT (\d+)', data):
|
||||
channel = int(re.fullmatch(r'GT (\d+)', data).group(1))
|
||||
enabled, highlow = counterbox.getGateStatus(channel)
|
||||
enabled, highlow = daq.getGateStatus(channel)
|
||||
send(f'{int(enabled)} {int(highlow)}')
|
||||
|
||||
elif re.fullmatch(r'GT (\d+) (\d+) (\d+)', data):
|
||||
channel, enable, highlow = re.fullmatch(r'GT (\d+) (\d+) (\d+)', data).groups()
|
||||
channel, enable, highlow = int(channel), bool(int(enable)), bool(int(highlow))
|
||||
counterbox.setGateStatus(channel, enable, highlow)
|
||||
daq.setGateStatus(channel, enable, highlow)
|
||||
if enable:
|
||||
send(f'Gate {channel} enabled, counting when input = {"high" if highlow else "low"}')
|
||||
else:
|
||||
@ -320,7 +320,7 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
elif re.fullmatch(r'GATE (\d+) (\d+)', data):
|
||||
channel, highlow = re.fullmatch(r'GATE (\d+) (\d+)', data).groups()
|
||||
channel, highlow = int(channel), bool(int(highlow))
|
||||
counterbox.setGate(channel, highlow)
|
||||
daq.setGate(channel, highlow)
|
||||
send('')
|
||||
|
||||
else:
|
Reference in New Issue
Block a user