1
+ """Document level docstring."""
1
2
#!/usr/bin/env python
2
3
3
4
from bitlib import *
4
5
5
6
class Channel :
6
-
7
- id = ""
8
- device = ""
9
- src = ""
10
- analog_count = ""
11
- logic_count = ""
12
- analog_range_count = ""
7
+ """channel class to select, configure and acquire data from channels."""
8
+
9
+ id = None
10
+ device = None
11
+ src = None
12
+ analog_count = None
13
+ logic_count = None
14
+ analog_range_count = None
13
15
14
16
def __init__ (self , device , channel ):
17
+ """Initialise channel objects.
15
18
19
+ :type device: int
20
+ :param device: device id
21
+ :type channel: int
22
+ :param channel: channel id
23
+ """
16
24
self .device = device
17
25
self .id = channel
18
26
# device is seleted from previous Device class
@@ -23,6 +31,10 @@ def __init__(self, device, channel):
23
31
self .analog_range_count = BL_Count (BL_COUNT_RANGE )
24
32
25
33
def select (self ):
34
+ """Request the selection of a current channel.
35
+
36
+ :return: current selection of channel is returned.
37
+ """
26
38
# check if the corresponding device is already selected
27
39
if self .device != BL_Select (BL_SELECT_DEVICE ,BL_ASK ):
28
40
# select the corresponding device first
@@ -35,13 +47,24 @@ def select(self):
35
47
# print "Selected Device : {} , Channel : {}".format(self.device,self.id)
36
48
37
49
def count (self ,type ):
50
+ """Return the number of channels or ranges per the type specifier(BL_COUNT_ANALOG=>devices, BL_COUNT_LOGIC=>analog, 2=>logic, BL_COUNT_RANGE=>ranges) using the prevailing device and/or channel for those types that require it.
51
+
52
+ :type type: BL_COUNT_ANALOG,BL_COUNT_LOGIC,BL_COUNT_RANGE
53
+ :param type: specifies the type for which count must be found
54
+ :return: count of the selected type
55
+ """
38
56
if type in [BL_COUNT_ANALOG ,BL_COUNT_LOGIC ,BL_COUNT_RANGE ]:
39
57
return BL_Count (type )
40
58
else :
41
59
print "Invalid Count Type"
42
60
return 0
43
61
44
62
def source (self ,type = BL_SOURCE_BNC ):
63
+ """Request the selection of a range or sources.
64
+
65
+ :type type: BL_SOURCE_POD, BL_SOURCE_BNC, BL_SOURCE_X10, BL_SOURCE_X20, BL_SOURCE_X50, BL_SOURCE_ALT, BL_SOURCE_GND
66
+ :param type: selects the type of source for a channel
67
+ """
45
68
self .select ()
46
69
47
70
if type in [BL_SOURCE_POD , BL_SOURCE_BNC , BL_SOURCE_X10 , BL_SOURCE_X20 , BL_SOURCE_X50 , BL_SOURCE_ALT , BL_SOURCE_GND ]:
@@ -50,26 +73,64 @@ def source(self,type=BL_SOURCE_BNC):
50
73
self .source = type
51
74
52
75
# set offset
53
- def offset (self , volt ):
76
+ def offset (self , offset ):
77
+ """Request offset and return the offset that is actually assigned to to
78
+ the selected device, channel and source. If a value beyond the
79
+ available offset range of the device is specified the closest available
80
+ offset for that channel is used.
81
+
82
+ :type offset: int
83
+ :param offset: the value to be offset
84
+ :return: offset that is actually assigned to the selected device, channel and source.
85
+ """
54
86
self .select ()
55
87
# set offset
56
88
BL_Offset (offset )
57
89
58
90
# set range
59
- def analog_range (self ,analog_range ):
91
+ def analog_range (self , range ):
92
+ """Selects range and returns the maximum peak-to-peak voltage the can
93
+ be captured on the selected device, channel and source. If the range is
94
+ omitted, the prevailing range scale is returned. The range must
95
+ otherwise be 0 to N where N is the number of available ranges).
96
+
97
+ :type range: int
98
+ :param range: maximum peak-to-peak voltage the can be captured on the selected device, channel and source.
99
+ :return: returns the maximum peak-to-peak voltage
100
+ """
60
101
self .select ()
61
102
# set range
62
- if analog_range >= 0 and analog_range <= (self .analog_range_count )- 1 :
63
- BL_Range (analog_range )
103
+ if range >= 0 and range <= (self .analog_range_count )- 1 :
104
+ BL_Range (range )
64
105
65
106
# set coupling
66
107
def coupling (self ,coupling ):
108
+ """Selects coupling and returns the same value as A if the requested
109
+ value is selectable on the current channel and source. If coupling is
110
+ omitted (or BL_ASK is specified), the prevailing coupling is returned.
111
+
112
+ :type coupling: BL_COUPLING_AC,BL_COUPLING_DC,BL_COUPLING_RF,BL_ASK
113
+ :param coupling: Selects coupling
114
+ :return: the prevailing coupling is returned
115
+ """
67
116
self .select ()
68
- if coupling in [BL_COUPLING_AC ,BL_COUPLING_DC ,BL_COUPLING_RF ]:
69
- BL_Coupling (coupling )
117
+ if coupling in [BL_COUPLING_AC ,BL_COUPLING_DC ,BL_COUPLING_RF , BL_ASK ]:
118
+ return BL_Coupling (coupling )
70
119
71
- def configure (self , source = BL_SOURCE_BNC , offset = BL_ZERO ,analog_range = 0 ,coupling = BL_COUPLING_DC ):
120
+ def configure (self , source = BL_SOURCE_BNC , offset = BL_ZERO , range = 0 , coupling = BL_COUPLING_DC ):
121
+ """Configure the channel parameters like source, offset, analog_range,
122
+ coupling for the selected device and channel.
72
123
124
+ :type source: BL_SOURCE_POD, BL_SOURCE_BNC, BL_SOURCE_X10, BL_SOURCE_X20, BL_SOURCE_X50, BL_SOURCE_ALT, BL_SOURCE_GND
125
+ :param source: selects the type of source for a channel
126
+ :type offset: int
127
+ :param offset: the value to be offset
128
+ :type range: int
129
+ :param range: maximum peak-to-peak voltage the can be captured on the selected device, channel and source.
130
+ :type coupling: BL_COUPLING_AC,BL_COUPLING_DC,BL_COUPLING_RF,BL_ASK
131
+ :param coupling: Selects coupling
132
+ """
133
+
73
134
self .select ()
74
135
if source in [BL_SOURCE_POD , BL_SOURCE_BNC , BL_SOURCE_X10 , BL_SOURCE_X20 , BL_SOURCE_X50 , BL_SOURCE_ALT , BL_SOURCE_GND ]:
75
136
# select the corresponding source for the channel
@@ -79,34 +140,56 @@ def configure(self, source=BL_SOURCE_BNC, offset=BL_ZERO,analog_range=0,coupling
79
140
# set offset
80
141
BL_Offset (offset )
81
142
# set range
82
- if analog_range >= 0 and analog_range <= (self .analog_range_count )- 1 :
83
- BL_Range (analog_range )
143
+ if range >= 0 and range <= (self .analog_range_count )- 1 :
144
+ BL_Range (range )
84
145
# set coupling
85
146
if coupling in [BL_COUPLING_AC ,BL_COUPLING_DC ,BL_COUPLING_RF ]:
86
147
BL_Coupling (coupling )
87
-
148
+
88
149
# enable channel
89
150
def enable (self ):
151
+ """Assign enable status E (boolean) on the selected channel.
152
+
153
+ :return: true if successful or false otherwise.
154
+ """
90
155
self .select ()
91
156
BL_Enable (1 )
92
157
print "Enabled Device : {} , Channel : {}" .format (self .device ,self .id )
93
-
158
+
94
159
# disable channel
95
160
def disable (self ):
161
+ """Assign diasble status E (boolean) on the selected channel.
162
+
163
+ :return: true if successful or false otherwise.
164
+ """
96
165
self .select ()
97
166
BL_Enable (0 )
98
167
print "Disabled Device : {} , Channel : {}" .format (self .device ,self .id )
99
-
168
+
100
169
# set index before reading the data
101
170
# assign the buffer offset (for dumps)
102
171
def index (self , offset = 0 ):
172
+ """Request the capture address offset and return the address actually
173
+ used A which may be different if the request is unavailable or invalid.
174
+ If offset is omitted the address is (re)set to zero.
175
+
176
+ :type offset: int
177
+ :param offset: Request the capture address offset
178
+ :return: the address actually used
179
+ """
103
180
self .select ()
104
- BL_Index (offset )
105
-
181
+ return BL_Index (offset )
182
+
106
183
# acquire data from channel
107
184
def acquire (self ):
185
+ """Reads N samples from the selected device (BL_Select) and channel and
186
+ writes them to list D.
187
+ Returns N samples (possibly updated value). Samples are
188
+ (nominally) floating point voltages. Logic channels are
189
+ (nominally) low (0V) or high (5V). Alternatively D and/or N may
190
+ be omitted. In either case the returned value is a new list of
191
+ size N (or BL_Size() if N is omitted).
192
+ """
108
193
self .select ()
109
194
print "Acquiring Data from Device : {} , Channel : {}" .format (self .device ,self .id )
110
- return BL_Acquire ()
111
-
112
-
195
+ return BL_Acquire ()
0 commit comments