-
Notifications
You must be signed in to change notification settings - Fork 9
/
script_wrapper.py
2328 lines (1824 loc) · 82.8 KB
/
script_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
r"""
____ __ __ __ __ _ __
/_ / ___ _/ / ___ ___ ___________ / /__ / /__/ /_____(_) /__
/ /_/ _ `/ _ \/ _ \/ -_) __/___/ -_) / -_) '_/ __/ __/ / '_/
/___/\_,_/_//_/_//_/\__/_/ \__/_/\__/_/\_\\__/_/ /_/_/\_\
Copyright 2024 Zahner-Elektrik GmbH & Co. KG
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from enum import Enum, IntEnum
import re
import shutil
import os
from typing import Optional, Union, Any, List
from thales_remote.error import ThalesRemoteError, TermConnectionError
from thales_remote.connection import ThalesRemoteConnection
MINIMUM_THALES_VERSION = "5.9.2"
def versiontuple(v):
return tuple(map(int, (v.split("."))))
class PotentiostatMode(IntEnum):
r"""
Working modes for the potentiostat
"""
POTMODE_POTENTIOSTATIC = 1
POTMODE_GALVANOSTATIC = 2
POTMODE_PSEUDOGALVANOSTATIC = 3
class ScanStrategy(IntEnum):
r"""
Options for the EIS scan strategy
* SINGLE_SINE: single frequency sweep
* MULTI_SINE: multi sine
* TABLE: frequency table
"""
SINGLE_SINE = 0
MULTI_SINE = 1
TABLE = 2
@classmethod
def stringToEnum(cls, string: str):
stringEnumMap = {
"single": ScanStrategy.SINGLE_SINE,
"multi": ScanStrategy.MULTI_SINE,
"table": ScanStrategy.TABLE,
}
if not string in stringEnumMap:
raise ValueError("invalid string: " + string)
return stringEnumMap.get(string)
class ScanDirection(IntEnum):
r"""
Set the scan direction for EIS measurements.
* START_TO_MAX: from the start frequency to the maximum frequency
* START_TO_MIN: from the start to the minimum frequency
"""
START_TO_MAX = 0
START_TO_MIN = 1
@classmethod
def stringToEnum(cls, string: str):
stringEnumMap = {
"startToMax": ScanDirection.START_TO_MAX,
"startToMin": ScanDirection.START_TO_MIN,
}
if not string in stringEnumMap:
raise ValueError("invalid string: " + string)
return stringEnumMap.get(string)
class FileNaming(IntEnum):
r"""
Options for the file names in Thales.
* DATE_TIME: naming with time stamp
* INDIVIDUAL: only the specified filename without extension
* COUNTER: consecutive number
"""
DATE_TIME = 0
COUNTER = 1
INDIVIDUAL = 2
@classmethod
def stringToEnum(cls, string: str):
stringEnumMap = {
"dateTime": FileNaming.DATE_TIME,
"individual": FileNaming.INDIVIDUAL,
"counter": FileNaming.COUNTER,
}
if not string in stringEnumMap:
raise ValueError("invalid string: " + string)
return stringEnumMap.get(string)
class Pad4Mode(IntEnum):
r"""
Options for the PAD4 operating mode.
All channels can be either voltage or current. Individual setting is not possible.
"""
VOLTAGE = 0
CURRENT = 1
class ThalesRemoteScriptWrapper(object):
r"""
Wrapper that uses the ThalesRemoteConnection class.
The commands are explained in the `Remote2-Manual <https://doc.zahner.de/manuals/remote2.pdf>`_.
In the document you can also find a table with error numbers which are returned.
:param remoteConnection: The connection object to the Thales software.
"""
undefindedStandardErrorString: str = ""
_remote_connection: ThalesRemoteConnection
def __init__(self, remoteConnection: ThalesRemoteConnection):
self._remote_connection = remoteConnection
try:
versionReply = self.getThalesVersion(timeout=1)
except TermConnectionError as err:
raise ThalesRemoteError(
"Please update the Thales software, it is too old for this package version."
)
if "devel" in versionReply:
print("devel version")
elif "" == versionReply:
# timeout
raise ThalesRemoteError(
"Please update the Thales software, it is too old for this package version."
)
else:
match = re.search(r"(\d+.\d+.\d+)", versionReply)
versionString = match.group(1)
thalesToOld = versiontuple(versionString) < versiontuple(
MINIMUM_THALES_VERSION
)
if thalesToOld:
raise ThalesRemoteError(
f"Please update the Thales software. This package requires at least version {MINIMUM_THALES_VERSION}, but version {versionString} is installed."
)
return
def getCurrent(self) -> float:
r"""
Read the measured current from the device
:returns: the measured current value
"""
return self._requestValueAndParseUsingRegexp(
"CURRENT", r"current=\s*(.*?)A?[\r\n]{0,2}$"
)
def getPotential(self) -> float:
r"""
Read the measured potential from the device
:returns: the measured potential value
"""
return self._requestValueAndParseUsingRegexp(
"POTENTIAL", r"potential=\s*(.*?)V?[\r\n]{0,2}$"
)
def getVoltage(self) -> float:
r"""
Read the measured potential from the device
:returns: the measured potential value
"""
return self.getPotential()
def setCurrent(self, current: float) -> str:
r"""
Set the output current
:param current: the output current to set
:returns: response string from the device
"""
return self.setValue("Cset", current)
def setPotential(self, potential: float) -> str:
r"""
Set the output potential
:param potential: the output potential to set
:returns: response string from the device
"""
return self.setValue("Pset", potential)
def setVoltage(self, potential) -> str:
r"""
Set the output potential
:param potential: the output potential to set
:returns: response string from the device
"""
return self.setPotential(potential)
def setMaximumShunt(self, shunt: int) -> str:
r"""
Set the maximum shunt index for measurement
Set the maximum shunt index for impedance measurements.
:param shunt: the number of the shunt
:returns: response string from the device
"""
return self.setValue("Rmax", shunt)
def setMinimumShunt(self, shunt) -> str:
r"""
Set the minimum shunt for measurement
Set the minimum shunt index for impedance measurements.
:param shunt: index of the shunt to set
:returns: response string from the device
"""
return self.setValue("Rmin", shunt)
def setShuntIndex(self, shunt: int) -> None:
r"""
Set the shunt index for measurement
Fixes the shunt to the passed index.
:param shunt: The number of the shunt.
:returns: reponse string from the device
"""
self.setMinimumShunt(shunt)
self.setMaximumShunt(shunt)
return
def setVoltageRangeIndex(self, vrange: int) -> str:
r"""
Set the voltage range for measurement
If a Zennium, Zennium E, Zennium E4 or a device from the IM6 series is
used, the set index must match the U-buffer. If the U-buffer does not
match the set value, the measurement is wrong.
The Zennium pro, Zennium X and Zennium XC series automatically change
the range.
:param vrange: index of the voltage range
:returns: response string from the device
"""
return self.setValue("Potrange", vrange)
def selectPotentiostat(self, device: int) -> str:
r"""
Select device onto which all subsequent calls to set* methods are forwarded
First, the device must be selected. Only then can devices other than
the internal main potentiostat be configured.
:param device: Number of the device. 0 = Main. 1 = EPC channel 1 and so on.
:returns: reponse string from the device
"""
return self.setValue("DEV%", device)
def selectPotentiostatWithoutPotentiostatStateChange(self, device: int) -> str:
r"""
Select device onto which all subsequent calls to set* methods are forwarded
Device which is to be selected, on which the settings are output.
First, the device must be selected.
Only then can devices other than the internal main potentiostat be configured.
The potentiostat is not turned off.
:param device: Number of the device. 0 = Main. 1 = EPC channel 1 and so on.
:returns: The response string from the device.
"""
return self.setValue("DEVHOT%", device)
def switchToSCPIControl(self) -> str:
r"""
Change away from operation as EPC device to SCPI operation
This command works only with external potentiostats of the latest generation PP212, PP222, PP242 and XPOT2.
After this command they are no longer accessible with the EPC interface.
Then you can connect to the potentiostat with USB via the Comports.
The change back to EPC operation is also done explicitly from the USB side.
:returns: response string from the device
"""
return self.executeRemoteCommand("SETUSB")
def switchToSCPIControlWithoutPotentiostatStateChange(self) -> str:
r"""
Change away from operation as EPC device to SCPI operation.
This command works only with external potentiostats of the latest generation XPOT2, PP2x2, EL1002.
This requires a device firmware with at least version 1.0.4.
After this command they are no longer accessible with the EPC interface.
Then you can connect to the potentiostat with USB via the Comports.
The change back to EPC operation is also done explicitly from the USB side.
This function leaves the potentiostat in its current operating state and then switches to USB mode.
This should only be used when it is really necessary to leave the potentiostat on,
because between the change of control no quantities like current and voltage are monitored.
To ensure that the switch between Thales and Python/SCPI is interference-free, the following procedure should be followed.
This is necessary to ensure that both Thales and Python/SCPI have calibrated offsets, otherwise jumps may occur when switching modes:
1. Connect Zennium with USB and EPC-device/power potentiostat (XPOT2, PP2x2, EL1002) with USB to the computer. As well as Zennium to power potentiostat by EPC cable.
2. Switch on all devices.
3. Allow the equipment to warm up for at least 30 minutes.
4. Select and calibrate the EPC-device in Thales (with Remote2).
5. Switching the EPC-device to SCPI mode via Remote2 command.
6. Performing the offset calibration with Python/SCPI.
7. Then it is possible to switch between Thales and Python/SCPI with the potentiostat switched on.
With Thales, the DC operating point must first be set.
When changing the EPC device then measures current and voltage and sets the size internally.
When switching back to Thales, the same DC operating point must be set as when switching from Thales to USB.
:returns: The response string from the device.
"""
return self.executeRemoteCommand("HOT2USB")
def getSerialNumber(self) -> str:
r"""
Get the serial number of the active device
Active device ist the device selected with
:func:`~thales_remote.script_wrapper.ThalesRemoteScriptWrapper.selectPotentiostat`.
:returns: the device serial number
"""
reply = self.executeRemoteCommand("ALLNUM")
match = re.search(r"(.*);(.*);([a-zA-Z]*)", reply)
return match.group(2)
def getDeviceInformation(self) -> tuple[str, str]:
r"""
Get the name and serial number of the active device
:returns: tuple with the information about the selected potentiostat. (Name, Serialnumber).
"""
reply = self.executeRemoteCommand("DEVINF")
match = re.search(r"(.*);(.*);(.*);([0-9]*)", reply)
return match.group(3), match.group(4)
def getDeviceName(self) -> str:
r"""
Get the name of the active device
:returns: the device name
"""
reply = self.executeRemoteCommand("ALLNUM")
match = re.search(r"(.*);(.*);([a-zA-Z]*)", reply)
return match.group(3)
def readSetup(self) -> str:
r"""
Read the currently set parameters
A string containing the configuration is returned.
For Example:
.. code-block::
OK;SETUP;Pset=1.0000e-05;Cset=1.0000e-06;Frq=1.0000e+03;Ampl=0.0000e+00;Nw=1;Pot=0;Gal=0;GAL=0;Cmin=-3.0000e+00;Cmax=3.0000e+00;Pmin=-5.2377e+00;Pmax=5.2377e+00;DEV=0;EPC=0;MAXDEV=4;ENDSETUP
:returns: reponse string from the device
"""
return self.executeRemoteCommand("SENDSETUP")
def calibrateOffsets(self) -> str:
r"""
Perform offset calibration on the device
When the instrument has warmed up for about 30 minutes,
this command can be used to perform the offset calibration again.
:returns: response string from the device
"""
return self.executeRemoteCommand("CALOFFSETS")
def enablePotentiostat(self, enabled: bool = True) -> str:
r"""
Switch the potentiostat on or off
:param enabled: Switches the potentiostat on if True and off otherwise
:returns: response string from the device
"""
return self.executeRemoteCommand("Pot=" + ("-1" if enabled else "0"))
def disablePotentiostat(self) -> str:
r"""
Switch the potentiostat off
:returns: response string from the device
"""
return self.enablePotentiostat(False)
def setPotentiostatMode(self, potentiostatMode: PotentiostatMode) -> str:
r"""
Set the coupling of the potentiostat
This can be PotentiostatMode.POTMODE_POTENTIOSTATIC or PotentiostatMode.POTMODE_GALVANOSTATIC or
PotentiostatMode.POTMODE_PSEUDOGALVANOSTATIC.
:param potentiostatMode: The coupling of the potentiostat
:type potentiostatMode: :class:`~thales_remote.script_wrapper.PotentiostatMode`
:returns: response string from the device
"""
command_strings = {
PotentiostatMode.POTMODE_POTENTIOSTATIC: "Gal=0:GAL=0",
PotentiostatMode.POTMODE_GALVANOSTATIC: "Gal=-1:GAL=1",
PotentiostatMode.POTMODE_PSEUDOGALVANOSTATIC: "Gal=0:GAL=-1",
}
if not potentiostatMode in command_strings:
raise ValueError("invalid potentiostat mode: " + str(potentiostatMode))
return self.executeRemoteCommand(command_strings.get(potentiostatMode))
def enableRuleFileUsage(self, enable: bool = True) -> str:
r"""
Enable the usage of a rule file
If the usage of the rule file is activated all the parameters required
for the EIS, CV, and/or IE are taken from the rule file.
The exact usage can be found in the remote manual.
:param potentiostatMode: Enable the state of rule file usage.
:returns: response string from the device
"""
return self.setValue("UseRuleFile", 1 if enable else 0)
def disableRuleFileUsage(self) -> str:
r"""
Disable the usage of a rule file
:returns: reponse string from the device
"""
return self.enableRuleFileUsage(False)
"""
Section with PAD4 commands
"""
def setupPad4Channel(
self,
card: int,
channel: int,
state: Union[int, bool],
voltageRange: Optional[float] = None,
shuntResistor: Optional[float] = None,
) -> None:
r"""
Setting a channel of a PAD4 card for an EIS measurement
Each PAD4 channel must be configured individually. Each channel can be switched on or off individually.
But the PAD4 measurements must still be switched on globally with :func:`~thales_remote.script_wrapper.ThalesRemoteScriptWrapper.enablePad4Global`.
Each channel can be given a different voltage range or shunt.
:param card: index of the card starting at 1 and up to 4
:param channel: index of the card starting at 1 and up to 4
:param state: If `1` or `True` the channel is switched on else switched off
:param voltageRange: input voltage range, if this differs from 4 V
:param shuntResistor: shunt resistor, which is used. Only used if :func:`~thales_remote.script_wrapper.ThalesRemoteScriptWrapper.setupPad4ModeGlobal` is set to :class:`.Pad4Mode`.CURRENT
:returns: reponse string from the device
"""
commands = [f"PAD4={card};{channel};{1 if state else 0}"]
if voltageRange:
commands.append(f"PAD4_PRANGE={card};{channel};{voltageRange}")
if shuntResistor:
commands.append(f"PAD4_RSHUNT={card};{channel};{shuntResistor}")
for command in commands:
if isinstance(state, int):
state = state == 1
reply = self.executeRemoteCommand(command)
if "ERROR" in reply:
raise ThalesRemoteError(
reply.rstrip("\r")
+ ThalesRemoteScriptWrapper.undefindedStandardErrorString
)
return
def setupPad4ModeGlobal(self, mode: Pad4Mode) -> str:
r"""
Switch between current and voltage measurement
The user can switch the type of PAD4 channels between voltage sense (standard configuration) and current sense (with additional shunt resistor).
:param mode: :class:`.Pad4Mode`.VOLTAGE or :class:`.Pad4Mode`.CURRENT
:returns: reponse string from the device
"""
return self.executeRemoteCommand(f"PAD4MOD={mode.value}")
def enablePad4Global(self, state: bool = True) -> str:
r"""
Switch on the set PAD4 channels
The files of the measurement results with PAD4 are numbered consecutively.
The lowest number is the main channel of the potentiostat.
:param state: If state = True PAD4 channels are enabled.
:returns: reponse string from the device
"""
return self.setValue("PAD4ENA", 1 if state else 0)
def disablePad4Global(self) -> str:
r"""
Switch off the set PAD4 channels
:returns: reponse string from the device
"""
return self.enablePAD4(False)
def readPad4SetupGlobal(self) -> str:
r"""
Read the currently set PAD4 parameters
Reading the set PAD4 configuration.
A string containing the configuration is returned.
:returns: reponse string from the device
"""
reply = self.executeRemoteCommand("SENDPAD4SETUP")
if reply.find("ERROR") >= 0:
raise ThalesRemoteError(
reply.rstrip("\r")
+ ThalesRemoteScriptWrapper.undefindedStandardErrorString
)
return reply
"""
Section with settings for EIS measurements.
Additional informations can be found in the remote and EIS manual.
"""
def setFrequency(self, frequency: float) -> str:
r"""
Set the output frequency for single frequency impedance.
:param frequency: the output frequency for Impedance measurement to set
:returns: reponse string from the device
"""
return self.setValue("Frq", frequency)
def setAmplitude(self, amplitude: float) -> str:
r"""
Set the output amplitude
:param amplitude: the output amplitude for Impedance measurement to set in Volt or Ampere
:returns: reponse string from the device
"""
return self.setValue("Ampl", amplitude * 1e3)
def setNumberOfPeriods(self, number_of_periods: Union[int, float]):
r"""
Set the number of periods to average for one impedance measurement
:param number_of_periods: the number of periods / waves to average
:returns: reponse string from the device
"""
if isinstance(number_of_periods, float):
number_of_periods = round(number_of_periods)
if number_of_periods > 100:
number_of_periods = 100
if number_of_periods < 1:
number_of_periods = 1
return self.setValue("Nw", number_of_periods)
def setUpperFrequencyLimit(self, frequency: float) -> str:
r"""
Set the upper frequency limit for EIS measurements
:param frequency: the upper frequency limit to set
:returns: reponse string from the device
"""
return self.setValue("Fmax", frequency)
def setLowerFrequencyLimit(self, frequency: float) -> str:
r"""
Set the lower frequency limit for EIS measurements
:param frequency: the lower frequency limit to set
:returns: reponse string from the device
"""
return self.setValue("Fmin", frequency)
def setStartFrequency(self, frequency: float) -> str:
r"""
Set the start frequency for EIS measurements
:param frequency: the start frequency to set
:returns: reponse string from the device
"""
return self.setValue("Fstart", frequency)
def setUpperStepsPerDecade(self, steps: int) -> str:
r"""
Set the number of steps per decade in frequency range above 66 Hz for EIS measurements
:param steps: the number of steps per decade to set
:returns: reponse string from the device
"""
return self.setValue("dfm", steps)
def setLowerStepsPerDecade(self, steps: int) -> str:
r"""
Set the number of steps per decade in frequency range below 66 Hz for EIS measurements
:param steps: the number of steps per decade to set
:returns: reponse string from the device
"""
return self.setValue("dfl", steps)
def setUpperNumberOfPeriods(self, periods: int) -> str:
r"""
Set the number of periods to measure in frequency range above 66 Hz for EIS measurements
Note:
value must be greater or equal than the one set with
:func:`~thales_remote.script_wrapper.ThalesRemoteScriptWrapper.setLowerNumberOfPeriods`
:param periods: the number of periods to set
:returns: reponse string from the device
"""
return self.setValue("Nws", periods)
def setLowerNumberOfPeriods(self, periods: int) -> str:
r"""
Set the number of periods to measure in the frequency range at the lower frequency limit for EIS measurements.
Note:
value must be smaller or equal than the one set with
:func:`~thales_remote.script_wrapper.ThalesRemoteScriptWrapper.setUpperNumberOfPeriods`.
:param periods: the number of periods to set
:returns: reponse string from the device
"""
return self.setValue("Nwl", periods)
def setScanStrategy(self, strategy: Union[ScanStrategy, str]) -> str:
r"""
Set the scan strategy for EIS measurements.
strategy = "single": single sine.
strategy = "multi": multi sine.
strategy = "table": frequency table.
:param strategy: the scan strategy to set for EIS measurements
:returns: reponse string from the device
"""
strat = strategy
if isinstance(strategy, str):
strat = ScanStrategy.stringToEnum(strategy)
return self.setValue("ScanStrategy", strat.value)
def setScanDirection(self, direction: Union[ScanDirection, str]) -> str:
r"""
Set the scan direction for EIS measurements.
direction = "startToMax": Scan at first from start to maximum frequency.
direction = "startToMin": Scan at first from start to lower frequency.
:param direction: The scan direction for EIS measurements.
:type direction: string
:returns: reponse string from the device
"""
dir = direction
if isinstance(direction, str):
dir = ScanDirection.stringToEnum(direction)
return self.setValue("ScanDirection", dir.value)
def getImpedance(
self,
frequency: Optional[float] = None,
amplitude: Optional[float] = None,
number_of_periods: Optional[int] = None,
) -> complex:
r"""
Measure the impedance
Measure the impedance with the parameters. If the parameters are omitted the last will be used.
:param frequency: The frequency to measure the impedance at.
:param amplitude: The amplitude to measure the impedance with. In Volt if potentiostatic mode or Ampere for galvanostatic mode.
:param number_of_periods: The number of periods / waves to average.
:returns: Dict
:rtype: complex
"""
if frequency != None:
self.setFrequency(frequency)
if amplitude != None:
self.setAmplitude(amplitude)
if number_of_periods != None:
self.setNumberOfPeriods(number_of_periods)
reply = self.executeRemoteCommand("IMPEDANCE")
if reply.find("ERROR") >= 0:
raise ThalesRemoteError(
reply.rstrip("\r")
+ ThalesRemoteScriptWrapper.undefindedStandardErrorString
)
match = re.search("impedance=\\s*(.*?),\\s*(.*?)$", reply)
return complex(float(match.group(1)), float(match.group(2)))
def getImpedanceAsArray(
self,
frequency: Optional[float] = None,
amplitude: Optional[float] = None,
number_of_periods: Optional[int] = None,
) -> List[float]:
r"""
Measure the impedance
Measure the impedance with the parameters. If the parameters are omitted the last will be used.
:param frequency: The frequency to measure the impedance at.
:param amplitude: The amplitude to measure the impedance with. In Volt if potentiostatic mode or Ampere for galvanostatic mode.
:param number_of_periods: The number of periods / waves to average.
:returns: List wit [real, imag]
:rtype: List
"""
comp = self.getImpedance(frequency, amplitude, number_of_periods)
return [comp.real, comp.imag]
def getImpedancePad4(
self,
frequency: Optional[float] = None,
amplitude: Optional[float] = None,
number_of_periods: Optional[int] = None,
) -> dict[int, complex]:
r"""
Measure the impedance with PAD4 channels
Measure the impedance and activated PAD4 channels with the parameters. If the parameters are omitted the last will be used.
The method returns a dictionary containing the channels as keys and the complex impedance as value.
The MAIN channel has index 0. Switched off PAD4 channels have an impedance of 0.
:param frequency: The frequency to measure the impedance at.
:param amplitude: The amplitude to measure the impedance with. In Volt if potentiostatic mode or Ampere for galvanostatic mode.
:param number_of_periods: The number of periods / waves to average.
:returns: A dictionary with channel index as key and the complex impedance as value.
"""
if frequency != None:
self.setFrequency(frequency)
if amplitude != None:
self.setAmplitude(amplitude)
if number_of_periods != None:
self.setNumberOfPeriods(number_of_periods)
reply = self.executeRemoteCommand("PAD4IMP")
if reply.find("ERROR") >= 0:
raise ThalesRemoteError(
reply.rstrip("\r")
+ ThalesRemoteScriptWrapper.undefindedStandardErrorString
)
matches = re.finditer(r"=\s*(?P<real>.*?),\s*(?P<imag>.*?)(?:;|$)", reply)
return dict(
(key, complex(float(val.group("real")), float(val.group("imag"))))
for key, val in enumerate(matches)
)
def getImpedancePad4AsArray(
self,
frequency: Optional[float] = None,
amplitude: Optional[float] = None,
number_of_periods: Optional[int] = None,
) -> List[float]:
r"""
Measure the impedance with PAD4 channels
Measure the impedance and activated PAD4 channels with the parameters. If the parameters are omitted the last will be used.
The method returns a dictionary containing the channels as keys and the complex impedance as value.
The MAIN channel has index 0. Switched off PAD4 channels have an impedance of 0.
:param frequency: The frequency to measure the impedance at.
:param amplitude: The amplitude to measure the impedance with. In Volt if potentiostatic mode or Ampere for galvanostatic mode.
:param number_of_periods: The number of periods / waves to average.
:returns: List wit [real, imag,...]
:rtype: List
"""
comp = self.getImpedancePad4(frequency, amplitude, number_of_periods)
retval = []
for [key, val] in comp.items():
retval.append(val.real)
retval.append(val.imag)
return retval
def setEISNaming(self, naming: Union[str, FileNaming]) -> str:
r"""
Set the EIS measurement naming rule.
naming = "dateTime": extend the :func:`~thales_remote.script_wrapper.ThalesRemoteScriptWrapper.setEISOutputFileName` with date and time.
naming = "counter": extend the :func:`~thales_remote.script_wrapper.ThalesRemoteScriptWrapper.setEISOutputFileName` with an sequential number.
naming = "individual": the file is named like :func:`~thales_remote.script_wrapper.ThalesRemoteScriptWrapper.setEISOutputFileName`.
:param naming: the EIS measurement naming rule to set.
:returns: reponse string from the device
"""
nameingType = naming
if isinstance(naming, str):
nameingType = FileNaming.stringToEnum(naming)
return self.setValue("EIS_MOD", nameingType.value)
def setEISCounter(self, number: int) -> str:
r"""
Set the current number of EIS measurement for filename.
Current number for the file name for EIS measurements which is used next and then incremented.
:param number: the next measurement number to set
:returns: reponse string from the device
"""
return self.setValue("EIS_NUM", number)
def setEISOutputPath(self, path: str) -> str:
r"""
Set the path where the EIS measurements should be stored.
The results must be stored on the C hard disk.
If an error occurs test an alternative path or c:\THALES\temp.
The directory must exist.
:param path: path to the directory
:returns: reponse string from the device
"""
path = path.lower() # c: has to be lower case
self._checkForForbiddenCharactersInPath(path)
return self.setValue("EIS_PATH", path)
def setEISOutputFileName(self, name: str) -> str:
r"""
Set the basic EIS output filename.
The basic name of the file, which is extended by a sequential number or the date and time.
Only numbers, underscores and letters from a-Z may be used.
If the name is set to "individual", the file with the same name must not yet exist.
Existing files are not overwritten.
:param name: basic name of the file
:returns: reponse string from the device
"""
self._checkForForbiddenCharactersInFilename(name)
return self.setValue("EIS_ROOT", name)
def measureEIS(self) -> str:
r"""
Make an EIS measurement.
For the measurement all parameters must be specified before.
:returns: reponse string from the device
"""
reply = self.executeRemoteCommand("EIS")
if reply.find("ERROR") >= 0:
raise ThalesRemoteError(
reply.rstrip("\r")
+ ThalesRemoteScriptWrapper.undefindedStandardErrorString
)
return reply
"""
Section with settings for CV measurements.
Additional informations can be found in the remote and CV manual.
"""
def setCVStartPotential(self, potential: float) -> str:
r"""
Set the start potential of a CV measurement.
:param potential: the start potential to set
:returns: reponse string from the device
"""
return self.setValue("CV_Pstart", potential)
def setCVUpperReversingPotential(self, potential: float) -> str:
r"""
Set the upper reversal potential of a CV measurement.
:param potential: the upper reversal potential to set
:returns: reponse string from the device
"""
return self.setValue("CV_Pupper", potential)
def setCVLowerReversingPotential(self, potential: float) -> str:
r"""
Set the lower reversal potential of a CV measurement.
:param potential: the lower reversal potential to set
:returns: reponse string from the device
"""
return self.setValue("CV_Plower", potential)
def setCVEndPotential(self, potential: float) -> str:
r"""
Set the end potential of a CV measurement.
:param potential: the end potential to set
:returns: reponse string from the device
"""
return self.setValue("CV_Pend", potential)
def setCVStartHoldTime(self, time: float) -> str:
r"""
Setting the holding time at the start potential.
The time must be given in seconds.
:param time: the waiting time at start potential in s
:returns: reponse string from the device
"""
return self.setValue("CV_Tstart", time)
def setCVEndHoldTime(self, time: float) -> str:
r"""
Setting the holding time at the end potential.
The time must be given in seconds.
:param time: the waiting time at end potential in s
:returns: reponse string from the device
"""
return self.setValue("CV_Tend", time)
def setCVScanRate(self, scanRate: float) -> str:
r"""
Set the scan rate.
The scan rate must be specified in V/s.
:param scanRate: the scan rate to set in V/s
:returns: reponse string from the device
"""
return self.setValue("CV_Srate", scanRate)
def setCVCycles(self, cycles: float) -> str:
r"""
Set the number of cycles.
At least 0.5 cycles are necessary.
The number of cycles must be a multiple of 0.5. 3.5 are also possible, for example.
:param cycles: the number of CV cycles to set, at least 0.5.
:returns: reponse string from the device
"""
return self.setValue("CV_Periods", cycles)
def setCVSamplesPerCycle(self, samples: int) -> str:
r"""
Set the number of measurements per CV cycle.
:param samples: the number of measurments per cycle to set
:returns: reponse string from the device
"""
return self.setValue("CV_PpPer", samples)
def setCVMaximumCurrent(self, current: float) -> str:
r"""