Skip to content

Commit f2601a9

Browse files
committed
Solidify hardware channel specification to 'doX'.
This allows for correct auto widget creation. It also move specification out of hex to to decimal, matching the labeling of the GPIO pins.
1 parent 4b81e70 commit f2601a9

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

docs/source/devices/prawndo.rst

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ Usage
4545

4646
The pinout for the PrawnDO is as follows:
4747

48-
* Outputs 0-15 (labelled by default in hex 0-F): GPIO pins 0-15, respectively.
48+
* Outputs 0-15: GPIO pins 0-15, respectively.
4949
* External Trigger input: GPIO 16
5050
* External Clock input: GPIO 20
5151

5252
Note that signal cables should be connected to the Pico digital grounds for proper operation.
5353

5454
The PrawnDO can provide up to 16 digital outputs, which are accessed via `name.outputs`.
55-
Each channel is specified using the corresponding hex character (spanning 0-F for 0-15).
56-
The channel string must end with a single character between 0-F to be valid
57-
(i.e. `'flag 0'`, `'do 0'`, and `'0'` are all valid channel specifications for GPIO 0 of the PrawnDO).
55+
Each channel is specified using with a string of the form `'doD'`, where `'D'` is the GPIO number
56+
(i.e. `'do10'`, is the specification for GPIO 10 of the PrawnDO).
5857

5958
An example connection table that uses the PrawnBlaster and PrawnDO:
6059

@@ -69,9 +68,9 @@ An example connection table that uses the PrawnBlaster and PrawnDO:
6968
7069
PrawnDO(name='prawn_do', com_port='COM5', clock_line=prawn.clocklines[0])
7170
72-
DigitalOut('do0', prawn_do.outputs, 'flag 0')
73-
DigitalOut('do1', prawn_do.outputs, 'chan 1')
74-
DigitalOut('do10', prawn_do.outputs, 'flag C')
71+
DigitalOut('do0', prawn_do.outputs, 'do0')
72+
DigitalOut('do1', prawn_do.outputs, 'do1')
73+
DigitalOut('do12', prawn_do.outputs, 'do12')
7574
7675
if __name__ == "__main__":
7776
@@ -138,9 +137,9 @@ An example connection table using external clocks with the default frequency of
138137
PrawnDO(name='prawn_do', com_port='COM5', clock_line=prawn.clocklines[0],
139138
external_clock=True)
140139
141-
DigitalOut('do0', prawn_do.outputs, 'flag 0')
142-
DigitalOut('do1', prawn_do.outputs, 'chan 1')
143-
DigitalOut('do10', prawn_do.outputs, 'flag C')
140+
DigitalOut('do0', prawn_do.outputs, 'do0')
141+
DigitalOut('do1', prawn_do.outputs, 'do1')
142+
DigitalOut('do12', prawn_do.outputs, 'do12')
144143
145144
if __name__ == "__main__":
146145
@@ -172,7 +171,7 @@ the second instruction (`do0.go_low(t)`) must be at least 5 clock cycles after t
172171
.. code-block:: python
173172
174173
t = 0
175-
do.go_high(t)
174+
do0.go_high(t)
176175
t = 1e-3
177176
wait('my_wait', t)
178177
do0.go_low(t)

labscript_devices/PrawnDO/blacs_tabs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ class PrawnDOTab(DeviceTab):
1616
def initialise_GUI(self):
1717
do_prop = {}
1818
for i in range(0, 16):
19-
do_prop['0x{:01X}'.format(i)] = {}
19+
do_prop['do{:01d}'.format(i)] = {}
2020
self.create_digital_outputs(do_prop)
2121

22+
def sort(channel):
23+
return int(channel.split('do')[-1])
24+
2225
_, _, do_widgets = self.auto_create_widgets()
23-
self.auto_place_widgets(do_widgets)
26+
self.auto_place_widgets(('Digital Outputs', do_widgets, sort))
2427

2528
device = self.settings['connection_table'].find_by_name(self.device_name)
2629

labscript_devices/PrawnDO/blacs_workers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _dict_to_int(self, d):
173173
"""
174174
val = 0
175175
for conn, value in d.items():
176-
val |= value << int(conn, 16)
176+
val |= value << int(conn)
177177

178178
return val
179179

@@ -186,7 +186,7 @@ def _int_to_dict(self, val):
186186
Returns:
187187
dict: Dictonary with output channels as keys and values are boolean states
188188
"""
189-
return {f'0x{i:X}':((val >> i) & 1) for i in range(16)}
189+
return {f'do{i:d}':((val >> i) & 1) for i in range(16)}
190190

191191
def check_status(self):
192192
'''Checks operational status of the PrawnDO.

labscript_devices/PrawnDO/labscript_devices.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ def add_device(self, device):
5858
class _PrawnDigitalOutputs(IntermediateDevice):
5959
allowed_children = [DigitalOut]
6060

61-
allowed_channels = ('0', '1', '2', '3',
62-
'4', '5', '6', '7',
63-
'8', '9', 'A', 'B',
64-
'C', 'D', 'E', 'F')
61+
allowed_channels = tuple(range(16))
6562

6663
def __init__(self, name, parent_device,
6764
**kwargs):
@@ -88,7 +85,7 @@ def add_device(self, device):
8885
"""
8986

9087
conn = device.connection
91-
chan = conn.split(' ')[-1]
88+
chan = int(conn.split('do')[-1])
9289

9390
if chan not in self.allowed_channels:
9491
raise LabscriptError(f'Invalid channel specification: {conn}')
@@ -268,8 +265,8 @@ def generate_code(self, hdf5_file):
268265
# as the output word for the pins
269266
for output in outputs:
270267
output.make_timeseries(times)
271-
chan = output.connection.split(' ')[-1]
272-
bits[int(chan, 16)] = np.asarray(output.timeseries, dtype = np.uint16)
268+
chan = int(output.connection.split('do')[-1])
269+
bits[chan] = np.asarray(output.timeseries, dtype = np.uint16)
273270
# Merge list of lists into an array with a single 16 bit integer column
274271
bit_sets = np.array(bitfield(bits, dtype=np.uint16))
275272

0 commit comments

Comments
 (0)