-
-
Notifications
You must be signed in to change notification settings - Fork 248
/
attributes.py
4029 lines (2353 loc) · 95.6 KB
/
attributes.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
# -*- coding: utf-8 -*-
"""Descriptor to access VISA attributes.
Not all descriptors are used but they provide a reference regarding the
possible values for each attributes.
This file is part of PyVISA.
:copyright: 2014-2022 by PyVISA Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import enum
import sys
from collections import defaultdict
from typing import (
TYPE_CHECKING,
Any,
Dict,
Generic,
List,
Optional,
Set,
SupportsBytes,
SupportsInt,
Tuple,
Type,
TypeVar,
Union,
overload,
)
from typing_extensions import ClassVar, DefaultDict
from . import constants, util
if TYPE_CHECKING:
from .events import Event, IOCompletionEvent # noqa # pragma: no cover
from .resources import Resource # noqa # pragma: no cover
#: Not available value.
NotAvailable = object()
#: Attribute for all session types.
class AllSessionTypes: # We use a class to simplify typing
"""Class used as a placeholder to indicate an attribute exist on all resources."""
pass
#: Map resource to attribute
AttributesPerResource: DefaultDict[
Union[
Tuple[constants.InterfaceType, str], Type[AllSessionTypes], constants.EventType
],
Set[Type["Attribute"]],
] = defaultdict(set)
#: Map id to attribute
AttributesByID: Dict[int, Type["Attribute"]] = dict()
# --- Descriptor classes ---------------------------------------------------------------
T = TypeVar("T")
class Attribute(Generic[T]):
"""Base class for Attributes to be used as properties."""
#: List of resource or event types with this attribute.
#: each element is a tuple (constants.InterfaceType, str)
resources: ClassVar[
Union[
List[Union[Tuple[constants.InterfaceType, str], constants.EventType]],
Type[AllSessionTypes],
]
] = []
#: Name of the Python property to be matched to this attribute.
py_name: ClassVar[str] = "To be specified"
#: Name of the VISA Attribute
visa_name: ClassVar[str] = "To be specified"
#: Type of the VISA attribute
visa_type: ClassVar[str] = ""
#: Numeric constant of the VISA Attribute
attribute_id: ClassVar[int] = 0
#: Default value fo the VISA Attribute
default: ClassVar[Any] = "N/A"
#: Access
read: ClassVar[bool] = False
write: ClassVar[bool] = False
local: ClassVar[bool] = False
__doc__: str
@classmethod
def __init_subclass__(cls, **kwargs):
"""Register the subclass with the supported resources."""
super().__init_subclass__(**kwargs)
if not cls.__name__.startswith("AttrVI_"):
return
cls.attribute_id = getattr(constants, cls.visa_name)
# Check that the docstring are populated before extending them
# Cover the case of running with Python with -OO option
if cls.__doc__ is not None:
cls.redoc()
if cls.resources is AllSessionTypes:
AttributesPerResource[AllSessionTypes].add(cls)
else:
for res in cls.resources:
AttributesPerResource[res].add(cls)
AttributesByID[cls.attribute_id] = cls
@classmethod
def redoc(cls) -> None:
"""Generate a descriptive docstring."""
cls.__doc__ += "\n:VISA Attribute: %s (%s)" % (cls.visa_name, cls.attribute_id)
def post_get(self, value: Any) -> T:
"""Override to check or modify the value returned by the VISA function.
Parameters
----------
value : Any
Value returned by the VISA library.
Returns
-------
T
Equivalent python value.
"""
return value
def pre_set(self, value: T) -> Any:
"""Override to check or modify the value to be passed to the VISA function.
Parameters
----------
value : T
Python value to be passed to VISA library.
Returns
-------
Any
Equivalent value to pass to the VISA library.
"""
return value
@overload
def __get__(self, instance: None, owner) -> "Attribute":
pass
@overload # noqa: F811
def __get__(self, instance: Union["Resource", "Event"], owner) -> T: # noqa: F811
pass
def __get__(self, instance, owner): # noqa: F811
"""Access a VISA attribute and convert to a nice Python representation."""
if instance is None:
return self
if not self.read:
raise AttributeError("can't read attribute")
return self.post_get(instance.get_visa_attribute(self.attribute_id))
def __set__(self, instance: "Resource", value: T) -> None:
"""Set the attribute if writable."""
if not self.write:
raise AttributeError("can't write attribute")
# Here we use the bare integer value of the enumeration hence the type ignore
instance.set_visa_attribute(
self.attribute_id, # type: ignore
self.pre_set(value),
)
@classmethod
def in_resource(cls, session_type: Tuple[constants.InterfaceType, str]) -> bool:
"""Is the attribute part of a given session type.
Parameters
----------
session_type : Tuple[constants.InterfaceType, str]
Type of session for which to check the presence of an attribute.
Returns
-------
bool
Is the attribute present.
"""
if cls.resources is AllSessionTypes:
return True
return session_type in cls.resources # type: ignore
class EnumAttribute(Attribute):
"""Class for attributes with values that map to a PyVISA Enum."""
#: Enum type with valid values.
enum_type: ClassVar[Type[enum.IntEnum]]
@classmethod
def redoc(cls) -> None:
"""Add the enum member to the docstring."""
super(EnumAttribute, cls).redoc()
cls.__doc__ += "\n:type: :class:%s.%s" % (
cls.enum_type.__module__,
cls.enum_type.__name__,
)
def post_get(self, value: Any) -> enum.IntEnum:
"""Convert the VISA value to the proper enum member."""
return self.enum_type(value)
def pre_set(self, value: enum.IntEnum) -> Any:
"""Validate the value passed against the enum."""
# Python 3.8 raise if a non-Enum is used for value
try:
value = self.enum_type(value)
except ValueError:
raise ValueError(
"%r is an invalid value for attribute %s, "
"should be a %r" % (value, self.visa_name, self.enum_type)
)
return value
class FlagAttribute(Attribute):
"""Class for attributes with Flag values that map to a PyVISA Enum."""
#: Enum type with valid values.
enum_type: ClassVar[Type[enum.IntFlag]]
@classmethod
def redoc(cls) -> None:
"""Add the enum member to the docstring."""
super(FlagAttribute, cls).redoc()
cls.__doc__ += "\n:type: :class:%s.%s" % (
cls.enum_type.__module__,
cls.enum_type.__name__,
)
def post_get(self, value: Any) -> enum.IntFlag:
"""Convert the VISA value to the proper enum member."""
return self.enum_type(value)
def pre_set(self, value: enum.IntFlag) -> Any:
"""Validate the value passed against the enum."""
# Python 3.8 raise if a non-Enum is used for value
try:
value = self.enum_type(value)
except ValueError:
raise ValueError(
"%r is an invalid value for attribute %s, "
"should be a %r" % (value, self.visa_name, self.enum_type)
)
return value
class IntAttribute(Attribute):
"""Class for attributes with integers values."""
@classmethod
def redoc(cls) -> None:
"""Add the type of the returned value."""
super(IntAttribute, cls).redoc()
cls.__doc__ += "\n:type: int"
def post_get(self, value: SupportsInt) -> int:
"""Convert the returned value to an integer."""
return int(value)
class RangeAttribute(IntAttribute):
"""Class for integer attributes with values within a range."""
#: Range for the value, and iterable of extra values.
min_value: int
max_value: int
values: Optional[List[int]] = None
@classmethod
def redoc(cls) -> None:
"""Specify the range of validity for the attribute."""
super(RangeAttribute, cls).redoc()
cls.__doc__ += "\n:range: %s <= value <= %s" % (cls.min_value, cls.max_value)
if cls.values:
cls.__doc__ += " or in %s" % cls.values
def pre_set(self, value: int) -> int:
"""Check that the value falls in the specified range."""
if not self.min_value <= value <= self.max_value:
if not self.values:
raise ValueError(
"%r is an invalid value for attribute %s, "
"should be between %r and %r"
% (value, self.visa_name, self.min_value, self.max_value)
)
elif value not in self.values:
raise ValueError(
"%r is an invalid value for attribute %s, "
"should be between %r and %r or %r"
% (
value,
self.visa_name,
self.min_value,
self.max_value,
self.values,
)
)
return value
class ValuesAttribute(Attribute):
"""Class for attributes with values in a list."""
#: Valid values
values: list = []
@classmethod
def redoc(cls) -> None:
"""Add the allowed values to teh docs."""
super(ValuesAttribute, cls).redoc()
cls.__doc__ += "\n:values: %s" % cls.values
def pre_set(self, value: int) -> int:
"""Validate the value against the allowed values."""
if value not in self.values:
raise ValueError(
"%r is an invalid value for attribute %s, "
"should be in %s" % (value, self.visa_name, self.values)
)
return value
class BooleanAttribute(Attribute):
"""Class for attributes with boolean values."""
py_type: bool
@classmethod
def redoc(cls) -> None:
"""Add the type to the docs."""
super(BooleanAttribute, cls).redoc()
cls.__doc__ += "\n:type: bool"
def post_get(self, value: constants.VisaBoolean) -> bool:
"""Convert to a Python boolean."""
return value == constants.VisaBoolean.true
def pre_set(self, value: bool) -> constants.VisaBoolean:
"""Convert to a VISA boolean."""
return constants.VisaBoolean.true if value else constants.VisaBoolean.false
class CharAttribute(Attribute):
"""Class for attributes with char values."""
py_type = str
@classmethod
def redoc(cls) -> None:
"""Specify the valid characters."""
super(CharAttribute, cls).redoc()
cls.__doc__ += "\nASCII Character\n:type: str | bytes"
def post_get(self, value: int) -> str:
"""Convert the integer to a character."""
return chr(value)
def pre_set(self, value: Union[str, bytes]) -> int:
"""Convert a character to an integer."""
return ord(value)
# --- Session attributes ---------------------------------------------------------------
# Attributes are in the same order as in the constants.ResourceAttribute enum
class AttrVI_ATTR_RM_SESSION(Attribute):
"""Specifies the session of the Resource Manager used to open this session."""
resources = AllSessionTypes
py_name = ""
visa_name = "VI_ATTR_RM_SESSION"
visa_type = "ViSession"
default = NotAvailable
read, write, local = True, False, False
class AttrVI_ATTR_INTF_TYPE(EnumAttribute):
"""Interface type of the given session."""
resources = AllSessionTypes
py_name = "interface_type"
visa_name = "VI_ATTR_INTF_TYPE"
visa_type = "ViUInt16"
default = NotAvailable
read, write, local = True, False, False
enum_type = constants.InterfaceType
class AttrVI_ATTR_INTF_NUM(RangeAttribute):
"""Board number for the given interface."""
resources = AllSessionTypes
py_name = "interface_number"
visa_name = "VI_ATTR_INTF_NUM"
visa_type = "ViUInt16"
default = 0
read, write, local = True, False, False
min_value, max_value, values = 0x0, 0xFFFF, None
class AttrVI_ATTR_INTF_INST_NAME(Attribute):
"""Human-readable text that describes the given interface."""
resources = AllSessionTypes
py_name = ""
visa_name = "VI_ATTR_INTF_INST_NAME"
visa_type = "ViString"
default = NotAvailable
read, write, local = True, False, False
class AttrVI_ATTR_RSRC_CLASS(Attribute):
"""Resource class as defined by the canonical resource name.
Possible values are: INSTR, INTFC, SOCKET, RAW...
"""
resources = AllSessionTypes
py_name = "resource_class"
visa_name = "VI_ATTR_RSRC_CLASS"
visa_type = "ViString"
default = NotAvailable
read, write, local = True, False, False
class AttrVI_ATTR_RSRC_NAME(Attribute):
"""Unique identifier for a resource compliant with the address structure."""
resources = AllSessionTypes
py_name = "resource_name"
visa_name = "VI_ATTR_RSRC_NAME"
visa_type = "ViRsrc"
default = NotAvailable
read, write, local = True, False, False
class AttrVI_ATTR_RSRC_IMPL_VERSION(RangeAttribute):
"""Resource version that identifies the revisions or implementations of a resource.
This attribute value is defined by the individual manufacturer and increments
with each new revision. The format of the value has the upper 12 bits as
the major number of the version, the next lower 12 bits as the minor number
of the version, and the lowest 8 bits as the sub-minor number of the version.
"""
resources = AllSessionTypes
py_name = "implementation_version"
visa_name = "VI_ATTR_RSRC_IMPL_VERSION"
visa_type = "ViVersion"
default = NotAvailable
read, write, local = True, False, True
min_value, max_value, values = 0, 4294967295, None
class AttrVI_ATTR_RSRC_LOCK_STATE(EnumAttribute):
"""Current locking state of the resource.
The resource can be unlocked, locked with an exclusive lock,
or locked with a shared lock.
"""
resources = AllSessionTypes
py_name = "lock_state"
visa_name = "VI_ATTR_RSRC_LOCK_STATE"
visa_type = "ViAccessMode"
default = constants.AccessModes.no_lock
read, write, local = True, False, False
enum_type = constants.AccessModes
class AttrVI_ATTR_RSRC_SPEC_VERSION(RangeAttribute):
"""Version of the VISA specification to which the implementation is compliant.
The format of the value has the upper 12 bits as the major number of the version,
the next lower 12 bits as the minor number of the version, and the lowest 8 bits
as the sub-minor number of the version. The current VISA specification defines
the value to be 00300000h.
"""
resources = AllSessionTypes
py_name = "spec_version"
visa_name = "VI_ATTR_RSRC_SPEC_VERSION"
visa_type = "ViVersion"
default = 0x00300000
read, write, local = True, False, True
min_value, max_value, values = 0, 4294967295, None
class AttrVI_ATTR_RSRC_MANF_NAME(Attribute):
"""Manufacturer name of the vendor that implemented the VISA library.
This attribute is not related to the device manufacturer attributes.
Note The value of this attribute is for display purposes only and not for
programmatic decisions, as the value can differ between VISA implementations
and/or revisions.
"""
resources = AllSessionTypes
py_name = "resource_manufacturer_name"
visa_name = "VI_ATTR_RSRC_MANF_NAME"
visa_type = "ViString"
default = NotAvailable
read, write, local = True, False, False
class AttrVI_ATTR_RSRC_MANF_ID(RangeAttribute):
"""VXI manufacturer ID of the vendor that implemented the VISA library.
This attribute is not related to the device manufacturer attributes.
"""
resources = AllSessionTypes
py_name = ""
visa_name = "VI_ATTR_RSRC_MANF_ID"
visa_type = "ViUInt16"
default = NotAvailable
read, write, local = True, False, False
min_value, max_value, values = 0, 0x3FFF, None
class AttrVI_ATTR_TMO_VALUE(RangeAttribute):
"""Timeout in milliseconds for all resource I/O operations.
This value is used when accessing the device associated with the given
session.
Special values:
- **immediate** (``VI_TMO_IMMEDIATE``): 0
(for convenience, any value smaller than 1 is considered as 0)
- **infinite** (``VI_TMO_INFINITE``): ``float('+inf')``
(for convenience, None is considered as ``float('+inf')``)
To set an **infinite** timeout, you can also use:
>>> del instrument.timeout
A timeout value of VI_TMO_IMMEDIATE means that operations should never
wait for the device to respond. A timeout value of VI_TMO_INFINITE disables
the timeout mechanism.
"""
resources = AllSessionTypes
py_name = "timeout"
visa_name = "VI_ATTR_TMO_VALUE"
visa_type = "ViUInt32"
default = 2000
read, write, local = True, True, True
min_value, max_value, values = 0, 0xFFFFFFFF, None
def pre_set(self, value: Optional[Union[int, float]]) -> int:
"""Convert the timeout to an integer recognized by the VISA library."""
timeout = util.cleanup_timeout(value)
return timeout
def post_get(self, value: int) -> Union[int, float]: # type: ignore
"""Convert VI_TMO_INFINTE into float("+inf")."""
if value == constants.VI_TMO_INFINITE:
return float("+inf")
return value
def __delete__(self, instance: "Resource") -> None:
"""Set an infinite timeout upon deletion."""
instance.set_visa_attribute(
constants.ResourceAttribute.timeout_value, constants.VI_TMO_INFINITE
)
class AttrVI_ATTR_MAX_QUEUE_LENGTH(RangeAttribute):
"""Maximum number of events that can be queued at any time on the given session.
Events that occur after the queue has become full will be discarded.
"""
resources = AllSessionTypes
py_name = ""
visa_name = "VI_ATTR_MAX_QUEUE_LENGTH"
visa_type = "ViUInt32"
default = 50
read, write, local = True, True, True
min_value, max_value, values = 0x1, 0xFFFFFFFF, None
class AttrVI_ATTR_USER_DATA(RangeAttribute):
"""Maximum number of events that can be queued at any time on the given session.
Events that occur after the queue has become full will be discarded.
"""
resources = AllSessionTypes
py_name = ""
visa_name = "VI_ATTR_USER_DATA"
visa_type = "ViUInt64" if constants.is_64bits else "ViUInt32"
default = 0
read, write, local = True, True, True
min_value, max_value, values = (
0x0,
0xFFFFFFFFFFFFFFFF if constants.is_64bits else 0xFFFFFFFF,
None,
)
class AttrVI_ATTR_TRIG_ID(EnumAttribute):
"""Identifier for the current triggering mechanism."""
resources = [
(constants.InterfaceType.gpib, "INSTR"),
(constants.InterfaceType.gpib, "INTFC"),
(constants.InterfaceType.pxi, "INSTR"),
(constants.InterfaceType.pxi, "BACKPLANE"),
(constants.InterfaceType.asrl, "INSTR"),
(constants.InterfaceType.tcpip, "INSTR"),
(constants.InterfaceType.vxi, "BACKPLANE"),
(constants.InterfaceType.vxi, "INSTR"),
(constants.InterfaceType.vxi, "SERVANT"),
]
py_name = ""
visa_name = "VI_ATTR_TRIG_ID"
visa_type = "ViInt16"
default = constants.VI_TRIG_SW
read, write, local = True, True, True
enum_type = constants.TriggerID
class AttrVI_ATTR_SEND_END_EN(BooleanAttribute):
"""Should END be asserted during the transfer of the last byte of the buffer."""
# TODO find out if USB RAW should be listed
resources = [
(constants.InterfaceType.asrl, "INSTR"),
(constants.InterfaceType.gpib, "INSTR"),
(constants.InterfaceType.gpib, "INTFC"),
(constants.InterfaceType.tcpip, "INSTR"),
(constants.InterfaceType.tcpip, "SOCKET"),
(constants.InterfaceType.usb, "INSTR"),
(constants.InterfaceType.usb, "RAW"),
(constants.InterfaceType.vxi, "INSTR"),
(constants.InterfaceType.vxi, "SERVANT"),
]
py_name = "send_end"
visa_name = "VI_ATTR_SEND_END_EN"
visa_type = "ViBoolean"
default = True
read, write, local = True, True, True
class AttrVI_ATTR_SUPPRESS_END_EN(BooleanAttribute):
"""Whether to suppress the END indicator termination.
Only relevant in viRead and related operations.
"""
resources = [
(constants.InterfaceType.asrl, "INSTR"),
(constants.InterfaceType.gpib, "INSTR"),
(constants.InterfaceType.tcpip, "INSTR"),
(constants.InterfaceType.tcpip, "SOCKET"),
(constants.InterfaceType.usb, "INSTR"),
(constants.InterfaceType.usb, "RAW"),
(constants.InterfaceType.vxi, "INSTR"),
]
py_name = ""
visa_name = "VI_ATTR_SUPPRESS_END_EN"
visa_type = "ViBoolean"
default = False
read, write, local = True, True, True
class AttrVI_ATTR_TERMCHAR_EN(BooleanAttribute):
"""Should the read operation terminate when a termination character is received.
This attribute is ignored if VI_ATTR_ASRL_END_IN is set to VI_ASRL_END_TERMCHAR.
This attribute is valid for both raw I/O (viRead) and formatted I/O (viScanf).
For message based resource this automatically handled by the `read_termination`
property.
"""
resources = [
(constants.InterfaceType.gpib, "INSTR"),
(constants.InterfaceType.gpib, "INTFC"),
(constants.InterfaceType.asrl, "INSTR"),
(constants.InterfaceType.tcpip, "INSTR"),
(constants.InterfaceType.tcpip, "SOCKET"),
(constants.InterfaceType.usb, "INSTR"),
(constants.InterfaceType.usb, "RAW"),
(constants.InterfaceType.vxi, "INSTR"),
(constants.InterfaceType.vxi, "SERVANT"),
]
py_name = ""
visa_name = "VI_ATTR_TERMCHAR_EN"
visa_type = "ViBoolean"
default = False
read, write, local = True, True, True
class AttrVI_ATTR_TERMCHAR(CharAttribute):
"""VI_ATTR_TERMCHAR is the termination character.
When the termination character is read and VI_ATTR_TERMCHAR_EN is enabled
during a read operation, the read operation terminates.
For message based resource this automatically handled by the `read_termination`
property.
"""
resources = [
(constants.InterfaceType.gpib, "INSTR"),
(constants.InterfaceType.gpib, "INTFC"),
(constants.InterfaceType.asrl, "INSTR"),
(constants.InterfaceType.tcpip, "INSTR"),
(constants.InterfaceType.tcpip, "SOCKET"),
(constants.InterfaceType.usb, "INSTR"),
(constants.InterfaceType.usb, "RAW"),
(constants.InterfaceType.vxi, "INSTR"),
(constants.InterfaceType.vxi, "SERVANT"),
]
py_name = ""
visa_name = "VI_ATTR_TERMCHAR"
visa_type = "ViUInt8"
default = 0x0A # (linefeed)
read, write, local = True, True, True
class AttrVI_ATTR_IO_PROT(EnumAttribute):
"""IO protocol to use.
In VXI, you can choose normal word serial or fast data channel (FDC).
In GPIB, you can choose normal or high-speed (HS-488) transfers.
In serial, TCPIP, or USB RAW, you can choose normal transfers or
488.2-defined strings.
In USB INSTR, you can choose normal or vendor-specific transfers.
"""
# Crossing IVI and NI this is correct
resources = [
(constants.InterfaceType.gpib, "INTFC"),
(constants.InterfaceType.gpib, "INSTR"),
(constants.InterfaceType.asrl, "INSTR"),
(constants.InterfaceType.tcpip, "INSTR"),
(constants.InterfaceType.tcpip, "SOCKET"),
(constants.InterfaceType.usb, "INSTR"),
(constants.InterfaceType.usb, "RAW"),
(constants.InterfaceType.vxi, "INSTR"),
(constants.InterfaceType.vxi, "SERVANT"),
]
py_name = "io_protocol"
visa_name = "VI_ATTR_IO_PROT"
visa_type = "ViUInt16"
default = constants.IOProtocol.normal
read, write, local = True, True, True
enum_type = constants.IOProtocol
class AttrVI_ATTR_FILE_APPEND_EN(BooleanAttribute):
"""Should viReadToFile() overwrite (truncate) or append when opening a file."""
resources = [
(constants.InterfaceType.gpib, "INSTR"),
(constants.InterfaceType.gpib, "INTFC"),
(constants.InterfaceType.asrl, "INSTR"),
(constants.InterfaceType.tcpip, "INSTR"),
(constants.InterfaceType.tcpip, "SOCKET"),
(constants.InterfaceType.usb, "INSTR"),
(constants.InterfaceType.usb, "RAW"),
(constants.InterfaceType.vxi, "INSTR"),
(constants.InterfaceType.vxi, "SERVANT"),
]
py_name = ""
visa_name = "VI_ATTR_FILE_APPEND_EN"
visa_type = "ViBoolean"
default = False
read, write, local = True, True, True
class AttrVI_ATTR_RD_BUF_OPER_MODE(RangeAttribute):
"""Operational mode of the formatted I/O read buffer.
When the operational mode is set to VI_FLUSH_DISABLE (default), the buffer
is flushed only on explicit calls to viFlush(). If the operational mode is
set to VI_FLUSH_ON_ACCESS, the read buffer is flushed every time a
viScanf() (or related) operation completes.
"""
resources = [
(constants.InterfaceType.gpib, "INSTR"),
(constants.InterfaceType.gpib, "INTFC"),
(constants.InterfaceType.asrl, "INSTR"),
(constants.InterfaceType.tcpip, "INSTR"),
(constants.InterfaceType.tcpip, "SOCKET"),
(constants.InterfaceType.usb, "INSTR"),
(constants.InterfaceType.usb, "RAW"),
(constants.InterfaceType.vxi, "INSTR"),
(constants.InterfaceType.vxi, "SERVANT"),
]
py_name = ""
visa_name = "VI_ATTR_RD_BUF_OPER_MODE"
visa_type = "ViUInt16"
default = constants.VI_FLUSH_DISABLE
read, write, local = True, True, True
min_value, max_value, values = 0, 65535, None
class AttrVI_ATTR_RD_BUF_SIZE(RangeAttribute):
"""Current size of the formatted I/O input buffer for this session.
The user can modify this value by calling viSetBuf().
"""
resources = [
(constants.InterfaceType.gpib, "INSTR"),
(constants.InterfaceType.gpib, "INTFC"),
(constants.InterfaceType.asrl, "INSTR"),
(constants.InterfaceType.tcpip, "INSTR"),
(constants.InterfaceType.tcpip, "SOCKET"),
(constants.InterfaceType.usb, "INSTR"),
(constants.InterfaceType.usb, "RAW"),
(constants.InterfaceType.vxi, "INSTR"),
(constants.InterfaceType.vxi, "SERVANT"),
]
py_name = ""
visa_name = "VI_ATTR_RD_BUF_SIZE"
visa_type = "ViUInt32"
default = NotAvailable
read, write, local = True, False, True
min_value, max_value, values = 0, 4294967295, None
class AttrVI_ATTR_WR_BUF_OPER_MODE(RangeAttribute):