Skip to content

Commit 28980ff

Browse files
committed
Add docstrings and Add pydoc generated doc files
This Commit, - adds docstrings to all the python modules, class and functions - adds pydoc generated doc files to doc/pydoc/ dir
1 parent 3299717 commit 28980ff

File tree

12 files changed

+1575
-36
lines changed

12 files changed

+1575
-36
lines changed
File renamed without changes.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ the example file at `bitscope/examples/scope/scope_plot.py`
4747

4848
## Library Overview
4949

50-
The Library provides full programmed access to the BitScope Capture Engine. It is implemented using a small set of portable functions. Programming BitScope to capture waveforms and logic is simply a matter of calling the correct sequence of these functions from your program. There are no complicated data structures, parameter lists or callbacks.
50+
The Library provides full programmed access to the BitScope Capture Engine. It is implemented using a small set of portable functions. Programming BitScope to capture waveforms and logic is simply a matter of calling the correct sequence of these functions from your program.
5151

5252
See BitScope Programming and Library Reference for details.
5353

bitscope/channel.py

Lines changed: 107 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1+
"""Document level docstring."""
12
#!/usr/bin/env python
23

34
from bitlib import *
45

56
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
1315

1416
def __init__(self, device, channel):
17+
"""Initialise channel objects.
1518
19+
:type device: int
20+
:param device: device id
21+
:type channel: int
22+
:param channel: channel id
23+
"""
1624
self.device = device
1725
self.id = channel
1826
# device is seleted from previous Device class
@@ -23,6 +31,10 @@ def __init__(self, device, channel):
2331
self.analog_range_count = BL_Count(BL_COUNT_RANGE)
2432

2533
def select(self):
34+
"""Request the selection of a current channel.
35+
36+
:return: current selection of channel is returned.
37+
"""
2638
# check if the corresponding device is already selected
2739
if self.device != BL_Select(BL_SELECT_DEVICE,BL_ASK):
2840
# select the corresponding device first
@@ -35,13 +47,24 @@ def select(self):
3547
# print "Selected Device : {} , Channel : {}".format(self.device,self.id)
3648

3749
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+
"""
3856
if type in [BL_COUNT_ANALOG,BL_COUNT_LOGIC,BL_COUNT_RANGE]:
3957
return BL_Count(type)
4058
else:
4159
print "Invalid Count Type"
4260
return 0
4361

4462
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+
"""
4568
self.select()
4669

4770
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):
5073
self.source = type
5174

5275
# 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+
"""
5486
self.select()
5587
# set offset
5688
BL_Offset(offset)
5789

5890
# 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+
"""
60101
self.select()
61102
# 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)
64105

65106
# set coupling
66107
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+
"""
67116
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)
70119

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.
72123
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+
73134
self.select()
74135
if source in [BL_SOURCE_POD, BL_SOURCE_BNC, BL_SOURCE_X10, BL_SOURCE_X20, BL_SOURCE_X50, BL_SOURCE_ALT, BL_SOURCE_GND]:
75136
# 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
79140
# set offset
80141
BL_Offset(offset)
81142
# 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)
84145
# set coupling
85146
if coupling in [BL_COUPLING_AC,BL_COUPLING_DC,BL_COUPLING_RF]:
86147
BL_Coupling(coupling)
87-
148+
88149
# enable channel
89150
def enable(self):
151+
"""Assign enable status E (boolean) on the selected channel.
152+
153+
:return: true if successful or false otherwise.
154+
"""
90155
self.select()
91156
BL_Enable(1)
92157
print "Enabled Device : {} , Channel : {}".format(self.device,self.id)
93-
158+
94159
# disable channel
95160
def disable(self):
161+
"""Assign diasble status E (boolean) on the selected channel.
162+
163+
:return: true if successful or false otherwise.
164+
"""
96165
self.select()
97166
BL_Enable(0)
98167
print "Disabled Device : {} , Channel : {}".format(self.device,self.id)
99-
168+
100169
# set index before reading the data
101170
# assign the buffer offset (for dumps)
102171
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+
"""
103180
self.select()
104-
BL_Index(offset)
105-
181+
return BL_Index(offset)
182+
106183
# acquire data from channel
107184
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+
"""
108193
self.select()
109194
print "Acquiring Data from Device : {} , Channel : {}".format(self.device,self.id)
110-
return BL_Acquire()
111-
112-
195+
return BL_Acquire()

bitscope/device.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,52 @@
44
from bitscope.channel import Channel
55

66
class Device:
7-
8-
name = ""
9-
id = ""
10-
mode = ""
11-
version = ""
12-
channels = []
7+
"""Device class to select and configure devices that are open."""
8+
name = None
9+
id = None
10+
mode = None
11+
version = None
12+
channels = None
1313

1414
def __init__(self,device):
15+
"""Initialise the Device Object.
16+
17+
:type device: int
18+
:param device: device id to be initialised
19+
"""
1520
self.id = device
1621
BL_Select(BL_SELECT_DEVICE,device)
1722
self.name = BL_Name()
1823
self.version = BL_Version(BL_VERSION_DEVICE)
1924
# Find number of channels in each device and create Channel object for each and append in devices.channels
25+
self.channels = []
2026
for channel in range(0,BL_Count(BL_COUNT_ANALOG)):
2127
self.channels.append(Channel(self.id, channel))
2228
for channel in range(0,BL_Count(BL_COUNT_LOGIC)):
2329
self.channels.append(Channel(self.id, channel))
2430

2531
def select(self):
32+
"""Request the selection of a current device.
33+
34+
:return: current selection is returned.
35+
"""
2636
# check if the required device is selected
2737
if self.id != BL_Select(BL_SELECT_DEVICE,BL_ASK):
2838
# select the corresponding device first
29-
BL_Select(BL_SELECT_DEVICE,self.id)
39+
return BL_Select(BL_SELECT_DEVICE,self.id)
3040
# print "Selected Device : {}".format(self.id)
3141

3242
def mode(self, mode):
43+
"""Assign mode to the selected device and return the mode if
44+
successful.
45+
46+
:type mode: int
47+
:param mode: Assign mode (BL_MODE_FAST=>SCOPE, BL_MODE_DUAL=>CHOP, BL_MODE_MIXED=>MIXED, BL_MODE_LOGIC=>LOGIC, BL_MODE_STREAM=>STREAM) to the selected device
48+
:return: return the mode if successful
49+
"""
3350
self.select()
3451
if mode in [BL_MODE_FAST, BL_MODE_DUAL, BL_MODE_MIXED, BL_MODE_LOGIC, BL_MODE_STREAM]:
3552
# select the mode
3653
BL_Mode(mode)
3754
self.mode = mode
38-
print "Device : {} set to Mode : {}".format(self.id,self.mode)
55+
print "Device : {} set to Mode : {}".format(self.id,self.mode)

bitscope/trace.py

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,110 @@
33
from bitlib import *
44

55
class Trace:
6-
"""
7-
"""
6+
"""Trace Class to handle trace related functionalities."""
87

98
def trace(self, time_out, sync):
9+
"""Commence capture subject to timeout T (seconds) and block until the
10+
trace completes unless A is true in which case return now and capture
11+
asynchronously. In the latter use BL_State() to determine the state of
12+
capture. Returns OK true if the trace commenced successfully, false
13+
otherwise. If T is zero or omitted, perform a forced trigger trace
14+
immediately. If T is negative, do the trace with infinite timeout but
15+
do it execute aysnchronously.
16+
17+
:type time_out: double
18+
:param time_out: specify the time out for trace
19+
:type sync: BL_SYNC, BL_ASYNC
20+
:param sync: specify trace modes
21+
:return: boolean
22+
"""
1023
return BL_Trace(time_out,sync)
1124

1225
def rate(self,rate=None):
26+
"""sets rate for trace.
27+
28+
:type rate: int
29+
:param rate: rate to perform the trace
30+
:return: current rate
31+
"""
1332
if rate is None:
1433
return BL_Rate()
1534
else:
1635
return BL_Rate(rate); # optional, default BL_MAX_RATE
1736

1837
def size(self, size=None):
38+
"""sets size for trace.
39+
40+
:type size: int
41+
:param size: size to perform the trace
42+
:return: current size
43+
"""
1944
if size is None:
2045
return BL_Size()
2146
else:
2247
return BL_Size(size); # optional default BL_MAX_SIZE
2348

2449
def pre_capture(self, pre_capture=BL_ZERO):
50+
"""sets pre_capture time for trace.
51+
52+
:type pre_capture: int
53+
:param pre_capture: time to start capture before performing the trace
54+
:return: current pre_capture time
55+
"""
2556
return BL_Intro(pre_capture); #How many seconds to capture before the trigger event- 0 by default
2657

2758
def post_capture(self, post_capture=BL_ZERO):
59+
"""sets post_capture time for trace.
60+
61+
:type post_capture: int
62+
:param post_capture: time to stop capture after performing the trace
63+
:return: current post_capture time
64+
"""
2865
return BL_Delay(post_capture); #How many seconds to capture after the trigger event- 0 by default
2966

3067
def time(self, t=None):
68+
"""sets time for trace.
69+
70+
:type t: double
71+
:param t: time to trace
72+
:return: current time
73+
"""
3174
if t is None:
3275
return BL_Time()
3376
else:
3477
return BL_Time(t)
3578

3679
def trigger(self, volt, kind):
80+
"""sets tigger for trace.
81+
82+
:type volt: double
83+
:param volt: voltage level for trigger
84+
:type kind: BL_TRIG_RISE, BL_TRIG_FALL, BL_TRIG_HIGH, BL_TRIG_LOW, BL_TRIG_NONE
85+
:param kind: specify trigger type
86+
:return: cuurent trigger setting
87+
"""
3788
if kind in [BL_TRIG_RISE, BL_TRIG_FALL, BL_TRIG_HIGH, BL_TRIG_LOW, BL_TRIG_NONE]:
3889
return BL_Trigger(volt,kind)
3990

4091
def state(self):
92+
"""returns current state of the machine.
93+
94+
:return: current state of machine
95+
"""
4196
return BL_State()
4297

4398
def configure(self,rate=BL_MAX_RATE, size=BL_MAX_SIZE, pre_capture=BL_ZERO, post_capture=BL_ZERO):
99+
"""configure the trace settings.
100+
101+
:type rate: int
102+
:param rate: rate to perform the trace
103+
:type size: int
104+
:param size: size to perform the trace
105+
:type pre_capture: int
106+
:param pre_capture: time to start capture before performing the trace
107+
:type post_capture: int
108+
:param post_capture: time to stop capture after performing the trace
109+
"""
44110
#Setup channel-nonspecific parameters for capture.
45111
BL_Rate(rate); # optional, default BL_MAX_RATE
46112
BL_Size(size); # optional default BL_MAX_SIZE

0 commit comments

Comments
 (0)