Skip to content

Commit 6d85fa7

Browse files
committed
some polishing of comments and help texts
1 parent d80913d commit 6d85fa7

File tree

2 files changed

+43
-42
lines changed

2 files changed

+43
-42
lines changed

csvexport.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -405,64 +405,64 @@ def channel_type(value):
405405
command_group.add_argument(metavar='csv_path', dest='csv_path', nargs='?',
406406
type=str, default=None,
407407
help='Exports measured data to the given file in CSV format.'
408-
" If filename ends with '.xz' the content is compress using lzma/xz."
409-
" This reduces the filesize to ~ 1/12 compered to the uncompressed format."
410-
" Those files can be decompressed using 'xz -dk <filename>")
408+
" If the filename ends with '.xz' the content is compressed using lzma/xz."
409+
" This reduces the file size to ~ 1/12 compared to the uncompressed format."
410+
" Those files can be decompressed using 'xz -dk <filename>'.")
411411
command_group.add_argument('--calibrate', metavar=('calibrationfile_path', 'channels_at_once'), nargs=2,
412412
type=str, default=None,
413413
help='If set, calibrate the device by measuring given voltages and write'
414414
' calibration values to given file.'
415-
' Multiple channels (1, 2, 4 or all 8) can get calibrated at the same time'
415+
' Multiple channels (1, 2, 4 or all 8) can be calibrated at the same time'
416416
' if supplied with the same voltage. Ignores all other arguments.')
417417
parser.add_argument('-s', '--channels', metavar='channel', nargs='+',
418418
type=channel_type, default=list(range(1, 9)),
419-
help="Select channels that are of interest")
419+
help="Selects channels of interest.")
420420
parser.add_argument('-l', '--loglevel', dest='log_level', nargs='?',
421421
type=str, default="info", choices=str_to_log_level.keys(),
422-
help='Set the loglevel to debug')
422+
help='Sets the log level for debugging.')
423423
parser.add_argument('-v', '--vscale', metavar='scale', nargs="+",
424424
type=float, default=[1.0], choices=Hantek1008.valid_vscale_factors(),
425-
help='Set the pre scale in the hardware, must be 1, 0.125, or 0.02. If one value is given, all '
426-
'selected channels will use that vscale, otherwise there must be one value per selected'
427-
'channel')
425+
help='Sets the pre scale in the hardware, must be 1, 0.125, or 0.02. If a single value is '
426+
'given, all selected channels will use that vscale, otherwise there must be one value '
427+
'per selected channel.')
428428
parser.add_argument('-c', '--calibrationfile', dest="calibration_file_path", metavar='calibrationfile_path',
429429
type=str, default=None,
430-
help="Use the content of the given calibration file to correct the measured samples")
430+
help="Use the content of the given calibration file to correct the measured samples.")
431431
parser.add_argument('-r', '--raw', dest="raw_or_volt",
432432
type=str, default="volt", const="raw", nargs='?', choices=["raw", "volt", "volt+raw"],
433-
help="Specifies whether the sample values return from the device should be transformed"
434-
" to volts (eventually using calibration data) or not. If flag is not set, it defaults"
435-
" to 'volt'. If flag is set without a parameter 'raw' is used")
433+
help="Specifies whether the sample values returned from the device should be transformed "
434+
"to volts (using calibration data if specified) or not. If not set, the default "
435+
"value is 'volt'. If the flag is set without a parameter, 'raw' is used.")
436436
parser.add_argument('-z', '--zoscompensation', dest="zos_compensation", metavar='x',
437437
type=str, default=None, nargs='*',
438438
help=
439-
"""Compensate the zero offset shift that obscures over longer timescales.
439+
"""Compensates the zero offset shift that occurs over longer timescales.
440440
There are two possible ways of compensating that:
441-
(A) Compute shift out of an unused channels: Needs at least one unused channel, make sure
442-
that no voltage is applied to the given channel.
443-
(B) Compute shift with the help of a given function. Such a function computes a correction-factor
444-
based on the time past since start.
445-
Defaults to no compensation. If used without an argument method A is used on channel 8.
446-
If one integer argument is given method A is used on that channel. Otherwise Method B is used.
447-
It awaits a path to a file with a python function
441+
(A) Computing the shift out of an unused channel: Needs at least one unused channel, make sure
442+
that no external voltage is applied to the given channel.
443+
(B) Computing the shift with the help of a given function. Such a function computes a
444+
correction-factor based on the time passed since start.
445+
Defaults to no compensation. If used without an argument, method A is used on channel 8.
446+
If an integer argument is given, method A is used on that channel. Otherwise, method B is used,
447+
which expects a path to a python file with containing a function
448448
(calc_zos(ch: int, vscale: float, dtime: float)->float) in it
449449
and as a second argument a time offset (how long the device is already running in sec).
450450
""")
451451
parser.add_argument('-f', '--samplingrate', dest='sampling_rate',
452452
type=float, default=440, choices=Hantek1008.valid_roll_sampling_rates(),
453-
help='Set the sampling rate (in Hz) the device should use (default:440)')
453+
help='Sets the sampling rate (in Hz) the device should use (default:440).')
454454
parser.add_argument('-m', '--measuresamplingrate', dest='do_sampling_rate_measure', action="store_const",
455455
default=False, const=True,
456-
help='Measure the exact samplingrate the device achieves by using the computer internal clock.'
457-
'Increases startup duration by ~10 sec')
456+
help='Measures the exact sampling rate the device achieves by using the computer internal '
457+
'clock. Increases startup duration by ~10 sec.')
458458
parser.add_argument('-t', '--timestampstyle', dest="timestamp_style",
459459
type=str, default="own_row", nargs='?', choices=["own_row", "first_column"],
460-
help="Specifies the style the timestamps of the values are included in the CSV output. There"
460+
help="Specifies the style of the timestamps included in the CSV output. There"
461461
" are two options: When the 'own_row' style is used, every time the device sends a bunch"
462-
" of measured samples, these are writen to the CSV output followed by one row with the"
462+
" of measured samples, these are written to the CSV output followed by one row with the"
463463
" timestamp."
464-
" Use the 'first_column' option to let the first column have interpolated timestamps."
465-
" Default is 'own_row'.")
464+
" Use the 'first_column' option to let the first column of each line have an interpolated"
465+
" timestamp. Default is 'own_row'.")
466466

467467
args = parser.parse_args()
468468

hantek1008.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import copy
1111
import sys
1212

13-
# marking a child classes method with overrides makes sure the method overrides a parent class method
14-
# this check is only needed during development so its no problem if this package is not installed
15-
# to avoid errors we need to define a dummy decorator
13+
# marking a child class method with overrides makes sure the method overrides a parent class method.
14+
# this check is only needed during development so its no problem if this package is not installed.
15+
# to avoid errors, we need to define a dummy decorator.
1616
try:
1717
from overrides import overrides
1818
except ImportError:
@@ -35,7 +35,7 @@ class Hantek1008Raw:
3535
"""
3636
This class communicates to a Hantek1008 device via USB.
3737
It supports configuring the device (set vertical scale, sampling frequency, waveform generator,..)
38-
and measure samples with it. Either in continuous (rolling) mode or in windows (normal/burst) mode.
38+
and measuring samples with it. Either in continuous (rolling) mode or in windows (normal/burst) mode.
3939
"""
4040
# channel_id/channel_index are zero based
4141
# channel names are one based
@@ -52,20 +52,20 @@ def __init__(self, ns_per_div: int = 500_000,
5252
vertical_scale_factor: Union[float, List[float]] = 1.0) -> None:
5353
"""
5454
:param ns_per_div:
55-
:param vertical_scale_factor: must be an array of length 8 with a float scale value for each channel.
56-
Or a single float, than all channel will have that scale factor. The float must be 1.0, 0.2 or 0.02.
55+
:param vertical_scale_factor: must be an array of length 8 with a float scale value for each channel
56+
or a single float scale factor applied to all channels. The float must be either 1.0, 0.2 or 0.02.
5757
"""
5858

5959
assert isinstance(vertical_scale_factor, float) or len(vertical_scale_factor) == Hantek1008Raw.channel_count()
6060

61-
self.__ns_per_div: int = ns_per_div # on value for all channels
61+
self.__ns_per_div: int = ns_per_div # one value for all channels
6262

6363
# one vertical scale factor (float) per channel
6464
self.__vertical_scale_factors: List[float] = [vertical_scale_factor] * Hantek1008Raw.channel_count() \
6565
if isinstance(vertical_scale_factor, float) \
6666
else copy.deepcopy(vertical_scale_factor) # scale factor per channel
6767

68-
# dict of list of shorts, outer dict is of size 3 and contains values
68+
# dict of list of floats, outer dict is of size 3 and contains values
6969
# for every vertical scale factor, inner list contains an zero offset per channel
7070
self._zero_offsets: Dict[float, List[float]] = None
7171

@@ -79,7 +79,7 @@ def __init__(self, ns_per_div: int = 500_000,
7979
self.__cancel_pause_thread: bool = False
8080

8181
def connect(self):
82-
"""Find a plugged hantek 1008c device and set up the connection to it"""
82+
"""Find a plugged in hantek 1008c device and set up the connection to it"""
8383

8484
self._dev = usb.core.find(idVendor=0x0783, idProduct=0x5725)
8585

@@ -91,15 +91,16 @@ def connect(self):
9191
# configuration will be the active one
9292
self._dev.set_configuration()
9393

94-
# get an endpoint instance
9594
self._cfg = self._dev.get_active_configuration()
9695
self._intf = self._cfg[(0, 0)]
9796

97+
# get an output endpoint instance
9898
self.__out = usb.util.find_descriptor(
9999
self._intf,
100100
# match the first OUT endpoint
101101
custom_match=lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
102102

103+
# get an input endpoint instance
103104
self.__in = usb.util.find_descriptor(
104105
self._intf,
105106
# match the first IN endpoint
@@ -110,7 +111,7 @@ def connect(self):
110111

111112
def __write_and_receive(self, message: bytes, response_length: int,
112113
sec_till_response_request: float = 0.002, sec_till_start: float = 0.002) -> bytes:
113-
"""write and read from the device"""
114+
"""write to and read from the device"""
114115
start_time = time.time()
115116

116117
assert isinstance(message, bytes)
@@ -152,8 +153,8 @@ def __send_cmd(self, cmd_id: int, parameter: Union[bytes, List[int], str] = b'',
152153
return response
153154

154155
def __send_c6_a6_command(self, parameter: int) -> bytes:
155-
"""send the c602 or c603 command, then parse the response as sample_length. then follow CEIL(sample_length/64)
156-
a602 or a603 request. The responses are concatenated and finally returned trimmed to the fit the sample_length.
156+
"""send the c602 or c603 command, then parse the response as sample_length. then CEIL(sample_length/64)
157+
a602 or a603 requests follow. The responses are concatenated and finally returned trimmed to fit the sample_length.
157158
"""
158159
assert parameter in [2, 3]
159160
response = self.__send_cmd(0xc6, parameter=[parameter], response_length=2, echo_expected=False)
@@ -507,7 +508,7 @@ def compute_pulse_length(speed_in_rpm: int, bits_per_wave: int = 8) -> int:
507508

508509
def set_generator_waveform(self, waveform: List[int]) -> None:
509510
"""
510-
Every Byte in the waveform list contains information vor every of the 8 digital ouputs to be on or of.
511+
Every Byte in the waveform list contains information for every of the 8 digital ouputs to be on or of.
511512
The bit number i in one of those bytes tells if output i should be on or off in that part of the wave.
512513
:param waveform:
513514
:return:

0 commit comments

Comments
 (0)