Skip to content

Commit

Permalink
fix init snAPI for older python versions
Browse files Browse the repository at this point in the history
fix returning array size for getCountRates()
improve Tool_PlotCountRateByTriggerLevel.py to plot all channels
  • Loading branch information
tpoint75 committed Sep 20, 2023
1 parent 05a29dd commit 544a9d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
5 changes: 3 additions & 2 deletions snAPI/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down
34 changes: 20 additions & 14 deletions tools/Tool_PlotCountRateByTriggerLevel.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand All @@ -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()
Expand Down

0 comments on commit 544a9d1

Please sign in to comment.