Loading...
Searching...
No Matches
nonblockingExperiment.py
1"""! @example nonblockingExperiment.py """
2import sys
3from PySide6.QtWidgets import QApplication
4from PySide6.QtCore import QTimer
5from SquidstatPyLibrary import AisDeviceTracker
6from SquidstatPyLibrary import AisInstrumentHandler
7from SquidstatPyLibrary import AisErrorCode
8
9
10# Define relavant device information, for easy access
11
12CHANNEL = 0
13
14app = QApplication()
15
17
18def connectSignals(handler):
19 handler.activeDCDataReady.connect(lambda channel, data: print(f"Timestamp: {data.timestamp} Current: {data.current} Voltage: {data.workingElectrodeVoltage} CE Voltage : {data.counterElectrodeVoltage}"))
20 handler.activeACDataReady.connect(lambda channel, data: print(f"Frequency: {data.frequency} Absolute Impedance: {data.absoluteImpedance} Phase Angle: {data.phaseAngle}"))
21 handler.experimentNewElementStarting.connect(lambda channel, nodeInfo: print(f"New Node Beginning"))
22 handler.experimentStopped.connect(lambda channel, reason: print(f"Experiment Stopped Signal {channel}, {reason}"))
23
24def startExperiment(deviceName):
25 handler = tracker.getInstrumentHandler(deviceName)
26
27 connectSignals(handler)
28
29 error = handler.startManualExperiment(CHANNEL)
30 if error.value() != AisErrorCode.Success:
31 print(error.message())
32 app.quit()
33
34 error = handler.setManualModeSamplingInterval(CHANNEL, 2)
35 if error.value() != AisErrorCode.Success:
36 print(error.message())
37 app.quit()
38
39 error = handler.setManualModeConstantVoltage(CHANNEL, 2)
40 if error.value() != AisErrorCode.Success:
41 print(error.message())
42 app.quit()
43
44 error = handler.setManualModeOCP(CHANNEL)
45 if error.value() != AisErrorCode.Success:
46 print(error.message())
47 app.quit()
48
49 def stopExperiment():
50 error = handler.stopExperiment(CHANNEL)
51 if error.value() != AisErrorCode.Success:
52 print(error.message())
53 app.quit()
54
55 QTimer.singleShot(25000, stopExperiment)
56
57 # Allow the recent loop to process other events while the current experiment is running
58 while handler.isChannelBusy(CHANNEL):
59 app.processEvents()
60
61 # Process any remaining events
62 app.processEvents()
63
64tracker.newDeviceConnected.connect(startExperiment)
65
66numDevices = tracker.connectAllPluggedInDevices()
67if numDevices == 0:
68 print("No devices connected")
69 sys.exit()
70
71# Calling sys.exit(app.exec()) will keep the program running until the application is exited
72sys.exit(app.exec())
static AisDeviceTracker * Instance()
get the instance of the device tracker.