diff --git a/snAPI/Main.py b/snAPI/Main.py index b794c56..1dcfa80 100644 --- a/snAPI/Main.py +++ b/snAPI/Main.py @@ -199,7 +199,7 @@ def __new__(cls, *args, **kwargs): return super().__new__(cls) - def __init__(self, systemIni: str | None = None, libType: LibType | None = LibType.MH): + def __init__(self, systemIni: typing.Union[str, None] = None, libType: typing.Union[LibType, None] = LibType.MH): if systemIni is None: systemIni = "\\".join(inspect.getfile(snAPI).split("\\")[:-1])+'\\system.ini' self.device = Device(self) @@ -543,6 +543,7 @@ def getFileDevice(self, path: str): SBuf = path.encode('utf-8') if ok:= self.dll.getFileDevice(SBuf): ok = self.getDeviceConfig() + ok &= self.getMeasDescription() return ok @@ -893,7 +894,7 @@ def getCountRates(self,): countRates = ct.ARRAY(ct.c_int, 64)() ok = self.dll.getCountRates(syncRate, countRates) a = np.array(countRates) - a = np.resize(a, self.getNumAllChannels()) + a = np.resize(a, self.deviceConfig["NumChans"]) a = np.insert(a, 0, syncRate.contents.value) return a diff --git a/tools/Tool_PlotCountRateByTriggerLevel.py b/tools/Tool_PlotCountRateByTriggerLevel.py index f6f5715..e491dce 100644 --- a/tools/Tool_PlotCountRateByTriggerLevel.py +++ b/tools/Tool_PlotCountRateByTriggerLevel.py @@ -1,5 +1,6 @@ import sys -import os +import os +import time sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from snAPI.Main import * @@ -10,38 +11,43 @@ if(__name__ == "__main__"): - sn = snAPI(libType=LibType.HH) + sn = snAPI(libType=LibType.PH330) sn.getDevice() sn.initDevice() - x, sync, chan1, chan2, chan3, chan4 = [],[],[],[],[],[] + sn.loadIniConfig("config\PH330_Edge.ini") + numChans = sn.deviceConfig["NumChans"] + x, sync = [],[] + chan = [[] for _ in range(numChans)] + plt.show(block=False) - + init = True # set start, stop, step for the trigger level scan - for trigLvl in range(0, 500, 10): + for trigLvl in range(-500, 0, 1): if sn.deviceConfig["SyncTrigMode"] == "Edge": sn.device.setInputEdgeTrig(-1, trigLvl, 0) sn.device.setSyncEdgeTrig(trigLvl, 0) elif sn.deviceConfig["SyncTrigMode"] == "CFD": sn.device.setInputCFD(-1, trigLvl, 0) sn.device.setSyncCFD(trigLvl, 0) + + if init: + init = False + time.sleep(0.1) cntRs = sn.getCountRates() sn.logPrint(trigLvl, cntRs) x.append(trigLvl) sync.append(cntRs[0]) - chan1.append(cntRs[1]) - chan2.append(cntRs[2]) - # chan3.append(cntRs[3]) - # chan4.append(cntRs[4]) + for i in range(numChans): + chan[i].append(cntRs[i+1]) plt.clf() - plt.plot(x, sync, linewidth=2.0, label='sync') - plt.plot(x, chan1, linewidth=2.0, label='chan1') - plt.plot(x, chan2, linewidth=2.0, label='chan2') - # plt.plot(x, chan3, linewidth=2.0, label='chan3') - # plt.plot(x, chan4, linewidth=2.0, label='chan4') + plt.plot(x, chan[0], linewidth=2.0, label='sync') + for i in range(numChans): + plt.plot(x, chan[i], linewidth=2.0, label=f"chan{str(i)}") + plt.xlabel('Trigger Level [mV]') plt.ylabel('Counts') plt.legend()