Adds more functionality to the simulation
This commit is contained in:
@ -16,6 +16,7 @@ class CounterBox:
|
||||
def __init__(self, total_channels):
|
||||
self.total_channels = total_channels
|
||||
self.counts = [0] * self.total_channels
|
||||
self.rates = [randrange(5) for i in range(self.total_channels)]
|
||||
|
||||
self.status = 0
|
||||
self.countmode = 'time'
|
||||
@ -41,7 +42,8 @@ class CounterBox:
|
||||
|
||||
def updateCounts(self):
|
||||
for i in range(self.total_channels):
|
||||
self.counts[i] += randrange(5)
|
||||
self.rates[i] = randrange(5)
|
||||
self.counts[i] += self.rates[i]
|
||||
|
||||
def getRunTime(self):
|
||||
elapsed = round(time.time() - self.starttime, 3)
|
||||
@ -68,6 +70,10 @@ class CounterBox:
|
||||
|
||||
return self.elapsed
|
||||
|
||||
def stop(self):
|
||||
self.getRunTime()
|
||||
self.status = 0
|
||||
|
||||
def startTimePreset(self, presettime):
|
||||
self.countmode = 'time'
|
||||
self.status = 1
|
||||
@ -79,6 +85,15 @@ class CounterBox:
|
||||
self.status = 1
|
||||
self.presetcount = presetcount
|
||||
self.resetCounts()
|
||||
|
||||
def setMonitorChannel(self, channel):
|
||||
self.monitor = channel - 1
|
||||
|
||||
def getMonitorChannel(self):
|
||||
return self.monitor + 1
|
||||
|
||||
def getRate(self, channel):
|
||||
return float(self.rates[channel - 1])
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
|
||||
@ -129,6 +144,9 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
elif data == 'RS':
|
||||
send(str(counterbox.getStatus()))
|
||||
|
||||
elif data == 'S':
|
||||
counterbox.stop()
|
||||
|
||||
elif re.fullmatch(r'TP (\d+(\.\d+)?)', data):
|
||||
presettime = float(re.fullmatch(r'TP (\d+(\.\d+)?)', data).group(1))
|
||||
counterbox.startTimePreset(presettime)
|
||||
@ -139,6 +157,17 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
counterbox.startCountPreset(counts)
|
||||
send('')
|
||||
|
||||
elif data == 'PC':
|
||||
send(str(counterbox.getMonitorChannel()))
|
||||
|
||||
elif re.fullmatch(r'PC (\d+)', data):
|
||||
channel = int(re.fullmatch(r'PC (\d+)', data).group(1))
|
||||
counterbox.setMonitorChannel(channel)
|
||||
|
||||
elif re.fullmatch(r'RR (\d+)', data):
|
||||
channel = int(re.fullmatch(r'RR (\d+)', data).group(1))
|
||||
send(counterbox.getRate(channel))
|
||||
|
||||
else:
|
||||
send('?2') # Bad command
|
||||
|
||||
|
Reference in New Issue
Block a user