1"""! @example dataOutput.py """
2import sys
3from PySide6.QtWidgets import QApplication
4from PySide6.QtCore import QTextStream, QFile, QStandardPaths, QIODevice
5from SquidstatPyLibrary import AisDeviceTracker, AisErrorCode
6from SquidstatPyLibrary import AisExperiment
7from SquidstatPyLibrary import AisInstrumentHandler
8from SquidstatPyLibrary import AisConstantPotElement
9from SquidstatPyLibrary import AisConstantCurrentElement
10
11
12COMPORT = "COM1"
13CHANNEL = 0
14
15app = QApplication()
16
18
21
23
24success = True
25
26success &= experiment.appendElement(cvElement, 1)
27success &= experiment.appendElement(ccElement, 1)
28
29if not success:
30 print("Error building experiment")
31 sys.exit()
32
33filePath = ""
34fileNum = 1
35
36def onNewElementStarting(channel, info):
37 name = f"/{fileNum}_{info.stepNumber}_{info.stepName}.csv"
38 filePath = QStandardPaths.writableLocation(QStandardPaths.DesktopLocation) + name
39
40 file = QFile(filePath)
41 if not file.open(QIODevice.WriteOnly | QIODevice.Text):
42 return
43
44
45 out = QTextStream(file)
46 out << "Time Stamp, Counter Electrode Voltage, Working Electrode Voltage, Current \n"
47 file.close()
48
49 print(f"New element beginning: {info.stepName} step: {info.stepNumber}")
50
51def onActiveDCDataReady(channel, data):
52 print(f"current: {data.current} voltage: {data.workingElectrodeVoltage} counter electrode: {data.counterElectrodeVoltage} timestamp: {data.timestamp}")
53
54
55 file = QFile(filePath)
56 if not file.open(QIODevice.Append | QIODevice.WriteOnly | QIODevice.Text):
57 return
58
59 out = QTextStream(file)
60 out << data.timestamp << ","<< data.counterElectrodeVoltage << "," << data.workingElectrodeVoltage << "," << data.current << "\n"
61 file.close()
62
63def connectSignals(handler):
64 handler.activeDCDataReady.connect(onActiveDCDataReady)
65 handler.activeACDataReady.connect(lambda channel, data: print(f"Timestamp: {data.timestamp} Frequency: {data.frequency} Absolute Impedance: {data.absoluteImpedance}"))
66 handler.experimentNewElementStarting.connect(onNewElementStarting)
67 handler.experimentStopped.connect(lambda channel, reason: (print(f"Experiment Stopped Signal {channel}, {reason}"), app.quit()))
68 handler.deviceError.connect(lambda channel, error: print(f"Device Error: {error}"))
69
70def runExperiment(deviceName):
71 handler = tracker.getInstrumentHandler(deviceName)
72
73 connectSignals(handler)
74
75 error = handler.uploadExperimentToChannel(CHANNEL, experiment)
76
77 if error.value() != AisErrorCode.Success:
78 print(error.message())
79 app.quit()
80
81 error = handler.startUploadedExperiment(CHANNEL)
82
83 if error.value() != AisErrorCode.Success:
84 print(error.message())
85 app.quit()
86
87tracker.newDeviceConnected.connect(runExperiment)
88tracker.deviceDisconnected.connect(lambda deviceName: print(f"Device Disconnected: {deviceName}"))
89
90error = tracker.connectToDeviceOnComPort(COMPORT)
91
92if error.value() != AisErrorCode.Success:
93 print(error.message())
94 sys.exit()
95
96
97sys.exit(app.exec())
an experiment that simulates a constant current flow with more advance options for stopping the exper...
Definition AisConstantCurrentElement.h:18
an experiment that simulates a constant applied voltage.
Definition AisConstantPotElement.h:18
static AisDeviceTracker * Instance()
get the instance of the device tracker.
this class is used to create custom experiments. A custom experiment contains one or more elements....
Definition AisExperiment.h:22