nisync 0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ import ctypes
2
+ import platform
3
+ import threading
4
+
5
+ from nisync import _library, errors
6
+
7
+ _instance = None
8
+ _instance_lock = threading.Lock()
9
+ _library_info = {
10
+ "Linux": {
11
+ "32bit": {"name": "libnisync.so", "type": "cdll"},
12
+ "64bit": {"name": "libnisync.so", "type": "cdll"},
13
+ },
14
+ "Windows": {
15
+ "32bit": {"name": "nisync.dll", "type": "windll"},
16
+ "64bit": {"name": "nisync.dll", "type": "cdll"},
17
+ },
18
+ }
19
+
20
+
21
+ def _get_library_name():
22
+ try:
23
+ return _library_info[platform.system()][platform.architecture()[0]]["name"]
24
+ except KeyError:
25
+ raise errors.UnsupportedConfigurationError
26
+
27
+
28
+ def _get_library_type():
29
+ try:
30
+ return _library_info[platform.system()][platform.architecture()[0]]["type"]
31
+ except KeyError:
32
+ raise errors.UnsupportedConfigurationError
33
+
34
+
35
+ def get():
36
+ """Returns a singleton instance of the nisync library."""
37
+ global _instance
38
+ global _instance_lock
39
+
40
+ with _instance_lock:
41
+ if _instance is None:
42
+ try:
43
+ library_type = _get_library_type()
44
+ if library_type == "windll":
45
+ ctypes_library = ctypes.WinDLL(_get_library_name())
46
+ else:
47
+ assert library_type == "cdll"
48
+ ctypes_library = ctypes.CDLL(_get_library_name())
49
+ except OSError:
50
+ raise errors.DriverNotInstalledError()
51
+ _instance = _library.Library(ctypes_library)
52
+ return _instance
nisync/_visatype.py ADDED
@@ -0,0 +1,20 @@
1
+ import ctypes
2
+
3
+ ViStatus = ctypes.c_int32
4
+ ViSession = ctypes.c_uint32
5
+ ViChar = ctypes.c_char
6
+ ViUInt64 = ctypes.c_uint64
7
+ ViUInt32 = ctypes.c_uint32
8
+ ViUInt16 = ctypes.c_uint16
9
+ ViUInt8 = ctypes.c_uint8
10
+ ViInt64 = ctypes.c_int64
11
+ ViInt32 = ctypes.c_int32
12
+ ViInt16 = ctypes.c_int16
13
+ ViInt8 = ctypes.c_int8
14
+ ViAttr = ctypes.c_long
15
+ ViBoolean = ctypes.c_ushort
16
+ ViReal32 = ctypes.c_float
17
+ ViReal64 = ctypes.c_double
18
+ ViString = ctypes.c_char_p
19
+ ViRsrc = ViString
20
+ ViConstString = ViString
nisync/constants.py ADDED
@@ -0,0 +1,130 @@
1
+ """This module defines constants for trigger and clock terminal names."""
2
+
3
+ # This file was generated
4
+
5
+ PXI_TRIG0 = "PXI_Trig0"
6
+ PXI_TRIG1 = "PXI_Trig1"
7
+ PXI_TRIG2 = "PXI_Trig2"
8
+ PXI_TRIG3 = "PXI_Trig3"
9
+ PXI_TRIG4 = "PXI_Trig4"
10
+ PXI_TRIG5 = "PXI_Trig5"
11
+ PXI_TRIG6 = "PXI_Trig6"
12
+ PXI_TRIG7 = "PXI_Trig7"
13
+
14
+ PXI_STAR0 = "PXI_Star0"
15
+ PXI_STAR1 = "PXI_Star1"
16
+ PXI_STAR2 = "PXI_Star2"
17
+ PXI_STAR3 = "PXI_Star3"
18
+ PXI_STAR4 = "PXI_Star4"
19
+ PXI_STAR5 = "PXI_Star5"
20
+ PXI_STAR6 = "PXI_Star6"
21
+ PXI_STAR7 = "PXI_Star7"
22
+ PXI_STAR8 = "PXI_Star8"
23
+ PXI_STAR9 = "PXI_Star9"
24
+
25
+ PXI_STAR10 = "PXI_Star10"
26
+ PXI_STAR11 = "PXI_Star11"
27
+ PXI_STAR12 = "PXI_Star12"
28
+ PXI_STAR13 = "PXI_Star13"
29
+ PXI_STAR14 = "PXI_Star14"
30
+ PXI_STAR15 = "PXI_Star15"
31
+ PXI_STAR16 = "PXI_Star16"
32
+ PXI_STAR = "PXI_Star"
33
+
34
+ PXIE_DSTARA0 = "PXIe_DStarA0"
35
+ PXIE_DSTARA1 = "PXIe_DStarA1"
36
+ PXIE_DSTARA2 = "PXIe_DStarA2"
37
+ PXIE_DSTARA3 = "PXIe_DStarA3"
38
+ PXIE_DSTARA4 = "PXIe_DStarA4"
39
+ PXIE_DSTARA5 = "PXIe_DStarA5"
40
+ PXIE_DSTARA6 = "PXIe_DStarA6"
41
+ PXIE_DSTARA7 = "PXIe_DStarA7"
42
+ PXIE_DSTARA8 = "PXIe_DStarA8"
43
+ PXIE_DSTARA9 = "PXIe_DStarA9"
44
+
45
+ PXIE_DSTARA10 = "PXIe_DStarA10"
46
+ PXIE_DSTARA11 = "PXIe_DStarA11"
47
+ PXIE_DSTARA12 = "PXIe_DStarA12"
48
+ PXIE_DSTARA13 = "PXIe_DStarA13"
49
+ PXIE_DSTARA14 = "PXIe_DStarA14"
50
+ PXIE_DSTARA15 = "PXIe_DStarA15"
51
+ PXIE_DSTARA16 = "PXIe_DStarA16"
52
+ PXIE_DSTARA = "PXIe_DStarA"
53
+
54
+ PXIE_DSTARB0 = "PXIe_DStarB0"
55
+ PXIE_DSTARB1 = "PXIe_DStarB1"
56
+ PXIE_DSTARB2 = "PXIe_DStarB2"
57
+ PXIE_DSTARB3 = "PXIe_DStarB3"
58
+ PXIE_DSTARB4 = "PXIe_DStarB4"
59
+ PXIE_DSTARB5 = "PXIe_DStarB5"
60
+ PXIE_DSTARB6 = "PXIe_DStarB6"
61
+ PXIE_DSTARB7 = "PXIe_DStarB7"
62
+ PXIE_DSTARB8 = "PXIe_DStarB8"
63
+ PXIE_DSTARB9 = "PXIe_DStarB9"
64
+
65
+ PXIE_DSTARB10 = "PXIe_DStarB10"
66
+ PXIE_DSTARB11 = "PXIe_DStarB11"
67
+ PXIE_DSTARB12 = "PXIe_DStarB12"
68
+ PXIE_DSTARB13 = "PXIe_DStarB13"
69
+ PXIE_DSTARB14 = "PXIe_DStarB14"
70
+ PXIE_DSTARB15 = "PXIe_DStarB15"
71
+ PXIE_DSTARB16 = "PXIe_DStarB16"
72
+ PXIE_DSTARB = "PXIe_DStarB"
73
+
74
+ PXIE_DSTARC0 = "PXIe_DStarC0"
75
+ PXIE_DSTARC1 = "PXIe_DStarC1"
76
+ PXIE_DSTARC2 = "PXIe_DStarC2"
77
+ PXIE_DSTARC3 = "PXIe_DStarC3"
78
+ PXIE_DSTARC4 = "PXIe_DStarC4"
79
+ PXIE_DSTARC5 = "PXIe_DStarC5"
80
+ PXIE_DSTARC6 = "PXIe_DStarC6"
81
+ PXIE_DSTARC7 = "PXIe_DStarC7"
82
+ PXIE_DSTARC8 = "PXIe_DStarC8"
83
+ PXIE_DSTARC9 = "PXIe_DStarC9"
84
+
85
+ PXIE_DSTARC10 = "PXIe_DStarC10"
86
+ PXIE_DSTARC11 = "PXIe_DStarC11"
87
+ PXIE_DSTARC12 = "PXIe_DStarC12"
88
+ PXIE_DSTARC13 = "PXIe_DStarC13"
89
+ PXIE_DSTARC14 = "PXIe_DStarC14"
90
+ PXIE_DSTARC15 = "PXIe_DStarC15"
91
+ PXIE_DSTARC16 = "PXIe_DStarC16"
92
+ PXIE_DSTARC = "PXIe_DStarC"
93
+
94
+ PFI_LVDS0 = "PFI_LVDS0"
95
+ PFI_LVDS1 = "PFI_LVDS1"
96
+ PFI_LVDS2 = "PFI_LVDS2"
97
+
98
+ PFI0 = "PFI0"
99
+ PFI1 = "PFI1"
100
+ PFI2 = "PFI2"
101
+ PFI3 = "PFI3"
102
+ PFI4 = "PFI4"
103
+ PFI5 = "PFI5"
104
+ GROUND = "Ground"
105
+ SYNC_CLK_FULL_SPEED = "SyncClkFullSpeed"
106
+ SYNC_CLK_DIVIDED1 = "SyncClkDivided1"
107
+ SYNC_CLK_DIVIDED2 = "SyncClkDivided2"
108
+ SYNC_CLK_ASYNC = "SyncClkAsync"
109
+ GLOBAL_SOFTWARE_TRIGGER = "GlobalSoftwareTrigger"
110
+
111
+ PXI_CLK10 = "PXI_Clk10"
112
+ PXI_CLK10_IN = "PXI_Clk10_In"
113
+ CLK_IN = "ClkIn"
114
+ CLK_OUT = "ClkOut"
115
+ OSCILLATOR = "Oscillator"
116
+ DDS = "DDS"
117
+
118
+ PXIE_CLK100 = "PXIe_Clk100"
119
+ ALL_CONNECTED = "AllConnected"
120
+ DDS_UPDATE_IMMEDIATE = "DDS_UpdateImmediate"
121
+
122
+ RTSI0 = "RTSI0"
123
+ RTSI1 = "RTSI1"
124
+ RTSI2 = "RTSI2"
125
+ RTSI3 = "RTSI3"
126
+ RTSI4 = "RTSI4"
127
+ RTSI5 = "RTSI5"
128
+ RTSI6 = "RTSI6"
129
+ RTSI7 = "RTSI7"
130
+ BOARD_CLK = "BoardClk"
nisync/enums.py ADDED
@@ -0,0 +1,147 @@
1
+ # This file was generated
2
+
3
+ from enum import IntEnum
4
+
5
+
6
+ class CtypesEnum(IntEnum):
7
+ @classmethod
8
+ def from_param(cls, obj):
9
+ return int(obj)
10
+
11
+
12
+ class BMCAMode(CtypesEnum):
13
+ SLAVE_ONLY = 0
14
+ MASTER_SLAVE = 1
15
+
16
+
17
+ class Edge(CtypesEnum):
18
+ RISING = 0
19
+ FALLING = 1
20
+ ANY = 2
21
+
22
+
23
+ class ExternalCalibrationAction(CtypesEnum):
24
+ ABORT = 0
25
+ COMMIT = 1
26
+
27
+
28
+ class GPSStatus(CtypesEnum):
29
+ UNINITIALIZED = 0
30
+ ANTENNA_ERROR = 1
31
+ NO_USEABLE_SATELLITE = 2
32
+ ONE_USEABLE_SATELLITE = 3
33
+ TWO_USEABLE_SATELLITES = 4
34
+ THREE_USEABLE_SATELLITES = 5
35
+ NO_GPS_TIME = 6
36
+ PDOP_TOO_HIGH = 7
37
+ UNUSABLE_SATELLITE = 8
38
+ UNUSEABLE_SATELLITE = 8
39
+ FIX_REJECTED = 9
40
+ SELF_SURVEY_COMPLETE = 10
41
+ SELF_SURVEY_NOT_COMPLETE = 11
42
+
43
+
44
+ class IEEE1588ClockAccuracy(CtypesEnum):
45
+ UNKNOWN = 0
46
+ WITHIN_25_NSEC = 1
47
+ WITHIN_100_NSEC = 2
48
+ WITHIN_250_NSEC = 3
49
+ WITHIN_1_USEC = 4
50
+ WITHIN_2500_NSEC = 5
51
+ WITHIN_10_USEC = 6
52
+ WITHIN_25_USEC = 7
53
+ WITHIN_100_USEC = 8
54
+ WITHIN_250_USEC = 9
55
+ WITHIN_1_MSEC = 10
56
+ WITHIN_2500_USEC = 11
57
+ WITHIN_10_MSEC = 12
58
+ WITHIN_25_MSEC = 13
59
+ WITHIN_100_MSEC = 14
60
+ WITHIN_250_MSEC = 15
61
+ WITHIN_1_SEC = 16
62
+ WITHIN_10_SEC = 17
63
+ GREATER_THAN_10_SEC = 18
64
+
65
+
66
+ class IEEE1588ClockClass(CtypesEnum):
67
+ DEFAULT = 248
68
+
69
+
70
+ class IEEE1588PortState(CtypesEnum):
71
+ NOT_DEFINED = -1
72
+ INIT = 0
73
+ FAULT = 1
74
+ DISABLE = 2
75
+ LISTENING = 3
76
+ PREMASTER = 4
77
+ MASTER = 5
78
+ PASSIVE = 6
79
+ UNCALIBRATED = 7
80
+ SLAVE = 8
81
+ STOPPED = 9
82
+
83
+
84
+ class IEEE8021ASClockAccuracy(CtypesEnum):
85
+ WITHIN_25_NSEC = 32
86
+ WITHIN_100_NSEC = 33
87
+ WITHIN_250_NSEC = 34
88
+ WITHIN_1_USEC = 35
89
+ WITHIN_2500_NSEC = 36
90
+ WITHIN_10_USEC = 37
91
+ WITHIN_25_USEC = 38
92
+ WITHIN_100_USEC = 39
93
+ WITHIN_250_USEC = 40
94
+ WITHIN_1_MSEC = 41
95
+ WITHIN_2500_USEC = 42
96
+ WITHIN_10_MSEC = 43
97
+ WITHIN_25_MSEC = 44
98
+ WITHIN_100_MSEC = 45
99
+ WITHIN_250_MSEC = 46
100
+ WITHIN_1_SEC = 47
101
+ WITHIN_10_SEC = 48
102
+ GREATER_THAN_10_SEC = 49
103
+ UNKNOWN = 254
104
+
105
+
106
+ class IEEE8021ASPortState(CtypesEnum):
107
+ DISABLED = 3
108
+ MASTER = 6
109
+ PASSIVE = 7
110
+ SLAVE = 9
111
+
112
+
113
+ class IRIGType(CtypesEnum):
114
+ IRIGB_DC = 0
115
+ IRIGB_AM = 1
116
+
117
+
118
+ class InitialTimeSource(CtypesEnum):
119
+ SYSTEM_CLK = 0
120
+ MANUAL = 1
121
+
122
+
123
+ class Level(CtypesEnum):
124
+ LOW = 0
125
+ HIGH = 1
126
+
127
+
128
+ class SyncInterval(CtypesEnum):
129
+ _125_MSEC = -3
130
+ _250_MSEC = -2
131
+ HALF_SEC = -1
132
+ ONE_SEC = 0
133
+ TWO_SEC = 1
134
+
135
+
136
+ class TimeReference(CtypesEnum):
137
+ GPS = 0
138
+ IRIG = 1
139
+ PPS = 2
140
+ IEEE_1588_ORDINARY_CLOCK = 3
141
+ FREERUNNING = 4
142
+ IEEE_8021AS = 5
143
+
144
+
145
+ class UpdateEdge(CtypesEnum):
146
+ RISING = 0
147
+ FALLING = 1
nisync/errors.py ADDED
@@ -0,0 +1,87 @@
1
+ import platform
2
+ import warnings
3
+
4
+ from nisync._errorcodes import Status
5
+
6
+
7
+ def _is_success(code):
8
+ return code == 0
9
+
10
+
11
+ def _is_error(code):
12
+ return code < 0
13
+
14
+
15
+ def _is_warning(code):
16
+ return code > 0
17
+
18
+
19
+ class Error(Exception):
20
+ def __init__(self, message):
21
+ super(Error, self).__init__(message)
22
+
23
+
24
+ class DriverError(Error):
25
+ def __init__(self, code, description):
26
+ assert _is_error(code), "Should not raise Error if code is not fatal."
27
+ self.code = code
28
+ self.description = description
29
+ super(DriverError, self).__init__(str(self.code) + ": " + self.description)
30
+
31
+
32
+ class DriverWarning(Warning):
33
+ def __init__(self, code, description):
34
+ assert _is_warning(code), "Should not create Warning if code is not positive."
35
+ super(DriverWarning, self).__init__(
36
+ "Warning {0} occurred.\n\n{1}".format(code, description)
37
+ )
38
+
39
+
40
+ class UnsupportedConfigurationError(Error):
41
+ def __init__(self):
42
+ super(UnsupportedConfigurationError, self).__init__(
43
+ "System configuration is unsupported: "
44
+ + platform.architecture()[0]
45
+ + " "
46
+ + platform.system()
47
+ )
48
+
49
+
50
+ class DriverNotInstalledError(Error):
51
+ def __init__(self):
52
+ super(DriverNotInstalledError, self).__init__(
53
+ "The NI-DMM runtime could not be loaded. Make sure it is installed and its bitness matches that of your Python interpreter. Please visit http://www.ni.com/downloads/drivers/ to download and install it."
54
+ )
55
+
56
+
57
+ def _lookup_error_code(code):
58
+ try:
59
+ return Status(code)
60
+ except ValueError:
61
+ # code is not in the nisync error codes enum
62
+ return code
63
+
64
+
65
+ def handle_error(session, code, ignore_warnings=False, is_error_handling=False):
66
+ if _is_success(code) or (_is_warning(code) and ignore_warnings):
67
+ return
68
+
69
+ code_to_use = _lookup_error_code(code)
70
+ if is_error_handling:
71
+ # The caller is in the midst of error handling and an error occurred.
72
+ # Don't try to get the description or we'll start recursing until the stack overflows.
73
+ description = ""
74
+ else:
75
+ if isinstance(code_to_use, Status):
76
+ description = session._get_error_description(code_to_use)
77
+ else:
78
+ description = ""
79
+
80
+ if _is_error(code_to_use):
81
+ raise DriverError(code_to_use, description)
82
+
83
+ assert _is_warning(code_to_use)
84
+ warnings.warn(DriverWarning(code_to_use, description))
85
+
86
+
87
+ warnings.filterwarnings("always", category=DriverWarning)