Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change repeated capabilities #718

Merged
merged 66 commits into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
3dc54c9
Add repeated_capabilities key in config for all drivers
texasaggie97-zz Jan 4, 2018
ad95cba
Update tests for new method of accessing repeated capabilities
texasaggie97-zz Jan 4, 2018
10eade5
Change how repeated capabilities are handled
texasaggie97-zz Jan 4, 2018
3860ec6
Update generated files
texasaggie97-zz Jan 4, 2018
a89cd1f
Update changelog
texasaggie97-zz Jan 4, 2018
bf49be6
Add function example in changelog
texasaggie97-zz Jan 4, 2018
ea96d19
Case insensitive check
texasaggie97-zz Jan 4, 2018
8458488
Missed a channel reference
texasaggie97-zz Jan 4, 2018
b6c1330
Update generated files
texasaggie97-zz Jan 4, 2018
0467916
Fix parent/child instance variables
texasaggie97-zz Jan 4, 2018
339908b
Update generated files
texasaggie97-zz Jan 4, 2018
8ba8760
Fix up channel based tip admonition for new syntax
texasaggie97-zz Jan 5, 2018
fe0b7a1
Update generated files
texasaggie97-zz Jan 5, 2018
a5ee751
Change channel rep cap class to plural - channels
texasaggie97-zz Jan 8, 2018
5e51689
Add Marker and Script Trigger repeated capabilities to FGen
texasaggie97-zz Jan 8, 2018
cb97f7f
Fix typo in names
texasaggie97-zz Jan 8, 2018
186dd6c
Update tests for plural channels
texasaggie97-zz Jan 8, 2018
e4152b9
Use duck typing insted of checking for list
texasaggie97-zz Jan 8, 2018
c764db6
Fix tests
texasaggie97-zz Jan 8, 2018
86c220a
Update generated files
texasaggie97-zz Jan 8, 2018
5790fb3
Fix tests to use range() instead of driver channel list format
texasaggie97-zz Jan 8, 2018
2832f66
Add example to show using range() as a rep cap list
texasaggie97-zz Jan 8, 2018
ae065a2
Fix range usage
texasaggie97-zz Jan 8, 2018
6588ecf
Fix range usage
texasaggie97-zz Jan 9, 2018
798ba75
Merge branch 'master' into api/rep_caps
texasaggie97-zz Jan 10, 2018
e5c2322
Merge branch 'master' into api/rep_caps
texasaggie97-zz Jan 10, 2018
d84fc00
Missed channel string
texasaggie97-zz Jan 10, 2018
558bded
Merge branch 'master' into api/rep_caps
texasaggie97-zz Jan 15, 2018
94696e1
Merge branch 'master' into api/rep_caps
texasaggie97-zz Jan 16, 2018
188832d
Merge branch 'master' into api/rep_caps
texasaggie97-zz Jan 17, 2018
2916d4a
Have to use timedelta for all timeouts
texasaggie97-zz Jan 17, 2018
1b0d10d
Rename _RepeatedCapabilites to _SessionBase
texasaggie97-zz Jan 18, 2018
5b2fd0f
Add support for slices
texasaggie97-zz Jan 18, 2018
d3a91b4
Update generated files
texasaggie97-zz Jan 18, 2018
c8df30b
Merge branch 'master' into api/rep_caps
texasaggie97-zz Jan 23, 2018
747368d
Merge master
texasaggie97-zz Jan 23, 2018
e61b621
Merge branch 'master' into api/rep_caps
texasaggie97-zz Jan 25, 2018
18c489f
Make formatting consisten with other branches
texasaggie97-zz Jan 25, 2018
c572c70
Merge branch 'master' into api/rep_caps
texasaggie97-zz Jan 31, 2018
3dda354
Merge branch 'master' into api/rep_caps
texasaggie97-zz Feb 2, 2018
d9443dd
Change logic for finding lists
texasaggie97-zz Feb 2, 2018
4f13ed8
Add test cases for all supported formats for repeated capabilities
texasaggie97-zz Feb 2, 2018
80dfc2f
Update generated files
texasaggie97-zz Feb 2, 2018
01aab4f
Move more complete information into readme
texasaggie97-zz Feb 5, 2018
32cc605
Use python names
texasaggie97-zz Feb 5, 2018
3e5ab43
Mention issue in readme
texasaggie97-zz Feb 5, 2018
83e059d
Move repeated caps login into _converters and test
texasaggie97-zz Feb 5, 2018
049ccfc
Update generated files
texasaggie97-zz Feb 5, 2018
6eab9b4
Test int and string
texasaggie97-zz Feb 5, 2018
7337b8e
Remove now redundant tests
texasaggie97-zz Feb 5, 2018
24b67f7
Update generated files
texasaggie97-zz Feb 5, 2018
d08ea33
Only define one class and instantiate multiple times
texasaggie97-zz Feb 5, 2018
ff3dfb3
Spaces matter
texasaggie97-zz Feb 5, 2018
603e9ac
Update generated files
texasaggie97-zz Feb 5, 2018
61c7d2f
Add comments in __init__
texasaggie97-zz Feb 5, 2018
0b43ad4
Initialize _RepeatedCapabilities with Session instead of individual i…
texasaggie97-zz Feb 5, 2018
e9891b7
Update generated files
texasaggie97-zz Feb 5, 2018
ff9213b
Remove p2p mentions.
texasaggie97-zz Feb 7, 2018
fe9e2c0
Use auto numbering for the enum
texasaggie97-zz Feb 8, 2018
ed34c39
Fix readme
texasaggie97-zz Feb 8, 2018
7fa18ce
Once we have a list, we just call ourselves with it
texasaggie97-zz Feb 8, 2018
2026eb0
No default parameters on _SessionBase __init__, pass None in explicitly
texasaggie97-zz Feb 8, 2018
d7ae7d6
Update generated files
texasaggie97-zz Feb 8, 2018
951f5f9
Change logic for getting repeated capability string
texasaggie97-zz Feb 8, 2018
d7f89d2
Don't show using prefix
texasaggie97-zz Feb 8, 2018
b2c8bbb
Update generated files
texasaggie97-zz Feb 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ commands.log
.vscode/launch.json
.vscode/settings.json


.pytest_cache/
21 changes: 15 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

* [Unreleased](#unreleased)
* [0.5.0](#060---2017-12-20)
* [0.6.0](#060---2017-12-20)
* [0.5.0](#050---2017-11-27)
* [0.4.0](#040---2017-11-07)
* [0.3.0](#030---2017-10-13)
Expand All @@ -14,12 +14,13 @@ All notable changes to this project will be documented in this file.
* ### ALL
* #### Added
* #### Changed
* Repeated capabilities are handled differently. See #737 for discussion
* #### Removed
* ### NI-DMM
* #### Added
* #### Changed
* `nidmm.Session()` no longer takes id_query parameter
* #### Removed
* `nidmm.Session()` no longer takes id_query parameter
* Removed these enums and disconnected them from the associated attribute
* `DCBias` - `DC_BIAS`
* `OffsetCompensatedOhms` - `OFFSET_COMP_OHMS`
Expand All @@ -34,6 +35,16 @@ All notable changes to this project will be documented in this file.
* #### Removed
* ### NI-DCPower
* #### Added
* `channel` repeated capability - See #737 for discussion
* #### Changed
* Metadata updated to NI-DCPower 17.6.1
* #### Removed
* ### NI-FGEN
* #### Added
* Repeated capablilites - See #737 for discussion:
* `channel` repeated capability
* `markers` repeated capability
* `script_triggers` repeated capability
* #### Changed
* Metadata updated to NI-DCPower 17.6.1
* #### Removed
Expand All @@ -42,12 +53,10 @@ All notable changes to this project will be documented in this file.
* `CurrentLevelAutorange` - `CURRENT_LEVEL_AUTORANGE`
* `VoltageLevelAutorange` - `VOLTAGE_LEVEL_AUTORANGE`
* `VoltageLimitAutorange` - `VOLTAGE_LIMIT_AUTORANGE`
* ### NI-FGEN
* #### Added
* #### Changed
* #### Removed
* ### NI-SCOPE
* #### Added
* Repeated capablilites - See #737 for discussion:
* `channel` repeated capability
* #### Changed
* `niscope.Session()` no longer takes id_query parameter
* #### Removed
Expand Down
28 changes: 28 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ The following is a basic example of using the **nidmm** module to open a session
session.configureMeasurementDigits(nidmm.Function.DC_VOLTS, 10, 5.5)
print("Measurement: " + str(session.read()))

Repeated capabilities
---------------------

* Repeated capabilities are accessed using a repeated capabilies object for each type of repeated capability that the driver supports. Some drivers do not use repeated capabilities.
* The repeated capabilities object can take integers or strings, a single item or a list, or a slice.
* The repeated capabilities object knows the proper prefix and will add it if needed.
* The following are all legal

.. code-block:: python

import nifgen
session = nifgen.Session('PXI1Slot2')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come you didn't use with? If you'd still rather not, then maybe show how you close the session?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't trying to show how to write an actual useful program. Added session.close()


# Channel repeated capabilities
session.channels['0'].channel_enabled = True
session.channels[0].channel_enabled = True
session.channels[[0, 1, 3]].channel_enabled = True
session.channels[range(8)].channel_enabled = True # channels 0, 1, 2, 3, 4, 5, 6, 7
session.channels[:8].channel_enabled = True # channels 0, 1, 2, 3, 4, 5, 6, 7
wfm = session.channels[[0, 1, 3]].fetch(5000)

# ScriptTrigger repeated capabilities
i = session.script_triggers['0'].script_triggers_count
i = session.script_triggers[0].script_triggers_count
i = session.script_triggers[[0, 1, 3]].script_triggers_count

session.close()

Additional examples for each driver are located in src/<driver>/examples/ directory.

.. _support-section:
Expand Down
8 changes: 8 additions & 0 deletions build/helper/codegen_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
'skip_self': False,
'name_to_use': 'python_name_with_default',
}
_parameterUsageOptionsSnippet[ParameterUsageOptions.SESSION_INIT_DECLARATION] = {
'skip_self': False,
'name_to_use': 'python_name_with_default',
}
_parameterUsageOptionsSnippet[ParameterUsageOptions.SESSION_NUMPY_INTO_METHOD_DECLARATION] = {
'skip_self': False,
'name_to_use': 'python_name_with_default',
Expand All @@ -22,6 +26,10 @@
'skip_self': True,
'name_to_use': 'python_name',
}
_parameterUsageOptionsSnippet[ParameterUsageOptions.SESSION_INIT_CALL] = {
'skip_self': True,
'name_to_use': 'python_name_or_default_for_init',
}
_parameterUsageOptionsSnippet[ParameterUsageOptions.DOCUMENTATION_SESSION_METHOD] = {
'skip_self': True,
'name_to_use': 'python_name_with_doc_default',
Expand Down
7 changes: 7 additions & 0 deletions build/helper/metadata_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
'mechanism': 'fixed, passed-in, len',
'python_api_list': True,
}
# Only difference is we want to skip parameters not in api
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the DRYness factor of this, but for consistency maybe just copy/paste?
(don't feel strongly, small preference because it's just two of many where things are different)

_parameterUsageOptionsFiltering[ParameterUsageOptions.SESSION_INIT_DECLARATION] = _parameterUsageOptionsFiltering[ParameterUsageOptions.SESSION_METHOD_DECLARATION].copy()
_parameterUsageOptionsFiltering[ParameterUsageOptions.SESSION_INIT_DECLARATION]['python_api_list'] = False

_parameterUsageOptionsFiltering[ParameterUsageOptions.SESSION_NUMPY_INTO_METHOD_DECLARATION] = {
'skip_session_handle': True,
'skip_input_parameters': False,
Expand All @@ -46,6 +50,9 @@
'mechanism': 'fixed, passed-in',
'python_api_list': True,
}
# Only difference is we want to skip parameters not in api
_parameterUsageOptionsFiltering[ParameterUsageOptions.SESSION_INIT_CALL] = _parameterUsageOptionsFiltering[ParameterUsageOptions.SESSION_METHOD_CALL].copy()

_parameterUsageOptionsFiltering[ParameterUsageOptions.DOCUMENTATION_SESSION_METHOD] = {
'skip_session_handle': True,
'skip_input_parameters': False,
Expand Down
46 changes: 29 additions & 17 deletions build/helper/parameter_usage_options.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
from enum import Enum


class ParameterUsageOptions(Enum):
class AutoNumber(Enum):
def __new__(cls):
value = len(cls.__members__) + 1
obj = object.__new__(cls)
obj._value_ = value
return obj


class ParameterUsageOptions(AutoNumber):
'''Different usage options for parameter lists.'''

SESSION_METHOD_DECLARATION = 1
'''For declaring a method in Session'''
SESSION_NUMPY_INTO_METHOD_DECLARATION = 2
SESSION_METHOD_DECLARATION = ()
'''For declaring a regular method in Session'''
SESSION_INIT_DECLARATION = ()
'''For declaring an init method in Session'''
SESSION_NUMPY_INTO_METHOD_DECLARATION = ()
'''For calling into a Session method that uses numpy arrays.'''
SESSION_METHOD_CALL = 3
'''For calling into a Session method.'''
DOCUMENTATION_SESSION_METHOD = 4
SESSION_METHOD_CALL = ()
'''For calling into a regular Session method.'''
SESSION_INIT_CALL = ()
'''For calling into an init Session method.'''
DOCUMENTATION_SESSION_METHOD = ()
'''For documentation (rst) of Session methods'''
CTYPES_CALL = 5
CTYPES_CALL = ()
'''For Library implementation calling into the DLL via ctypes'''
LIBRARY_METHOD_CALL = 6
LIBRARY_METHOD_CALL = ()
'''For calling into a method in Library.'''
CTYPES_ARGTYPES = 7
CTYPES_ARGTYPES = ()
'''For setting up the ctypes argument types'''
LIBRARY_METHOD_DECLARATION = 8
LIBRARY_METHOD_DECLARATION = ()
'''For declaring a method in Library'''
INPUT_PARAMETERS = 9
INPUT_PARAMETERS = ()
'''Get all input parameters, other than self, rep caps, and size'''
OUTPUT_PARAMETERS = 10
OUTPUT_PARAMETERS = ()
'''Get all output parameters, other than ivi-dance'''
IVI_DANCE_PARAMETER = 11
IVI_DANCE_PARAMETER = ()
'''Get the ivi-dance parameter'''
NUMPY_PARAMETERS = 12
NUMPY_PARAMETERS = ()
'''Get all buffer parameters that support numpy.array in the Python API'''
LEN_PARAMETER = 13
LEN_PARAMETER = ()
'''Get the len parameter'''
INPUT_ENUM_PARAMETERS = 14
INPUT_ENUM_PARAMETERS = ()
'''Get any input parameters whose type is enum'''


Expand Down
80 changes: 79 additions & 1 deletion build/templates/_converters.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@
from ${module_name} import visatype

import datetime
import six


def convert_repeated_capabilities(repeated_capability, prefix=''):
# First look for a string
if isinstance(repeated_capability, six.text_type) or isinstance(repeated_capability, six.string_types):
rep_cap_list = [repeated_capability if repeated_capability.lower().startswith(prefix.lower()) else prefix + repeated_capability]
else:
# if not a string, try it as an iterable
try:
rep_cap_list = [str(r) if str(r).lower().startswith(prefix.lower()) else prefix + str(r) for r in repeated_capability]
except TypeError:
# If that doesn't work, then try it as a slice
try:
def ifnone(a, b):
return b if a is None else a
# Turn the slice into a list so we can iterate over it
rep_cap_list = list(range(ifnone(repeated_capability.start, 0), repeated_capability.stop, ifnone(repeated_capability.step, 1)))
# Now it is a list, so we call ourselves
return convert_repeated_capabilities(rep_cap_list, prefix)
# Otherwise it must be a single item that is not a string
except (TypeError, AttributeError):
rep_cap_list = [str(repeated_capability) if str(repeated_capability).lower().startswith(prefix.lower()) else prefix + str(repeated_capability)]

return ','.join(rep_cap_list)


def _convert_timedelta(value, library_type, scaling):
Expand All @@ -29,7 +54,7 @@ def convert_timedelta_to_microseconds(value, library_type):
return _convert_timedelta(value, library_type, 1000000)


# Tests
# Tests - time
def test_convert_timedelta_to_seconds_double():
test_result = convert_timedelta_to_seconds(datetime.timedelta(seconds=10), visatype.ViReal64)
assert test_result.value == 10.0
Expand Down Expand Up @@ -66,4 +91,57 @@ def test_convert_timedelta_to_microseconds_int():
assert isinstance(test_result, visatype.ViInt32)


# Tests - repeated capabilities
def test_repeated_capabilies_string_channel():
test_result = convert_repeated_capabilities('0')
assert test_result == '0'
test_result = convert_repeated_capabilities('0,1')
assert test_result == '0,1'


def test_repeated_capabilies_string_prefix():
test_result = convert_repeated_capabilities('0', prefix='ScriptTrigger')
assert test_result == 'ScriptTrigger0'


def test_repeated_capabilies_list_channel():
test_result = convert_repeated_capabilities(['0'])
assert test_result == '0'
test_result = convert_repeated_capabilities(['0,1'])
assert test_result == '0,1'
test_result = convert_repeated_capabilities(['0', '1'])
assert test_result == '0,1'
test_result = convert_repeated_capabilities([0, 1])
assert test_result == '0,1'
test_result = convert_repeated_capabilities([0, 1, '3'])
assert test_result == '0,1,3'


def test_repeated_capabilies_list_prefix():
test_result = convert_repeated_capabilities(['ScriptTrigger0,ScriptTrigger1'], prefix='ScriptTrigger')
assert test_result == 'ScriptTrigger0,ScriptTrigger1'
test_result = convert_repeated_capabilities(['0'], prefix='ScriptTrigger')
assert test_result == 'ScriptTrigger0'
test_result = convert_repeated_capabilities(['0', '1'], prefix='ScriptTrigger')
assert test_result == 'ScriptTrigger0,ScriptTrigger1'
test_result = convert_repeated_capabilities([0, 1], prefix='ScriptTrigger')
assert test_result == 'ScriptTrigger0,ScriptTrigger1'


def test_repeated_capabilies_slice_channel():
test_result = convert_repeated_capabilities(slice(0, 1))
assert test_result == '0'
test_result = convert_repeated_capabilities(slice(0, 2))
assert test_result == '0,1'
test_result = convert_repeated_capabilities(slice(None, 2))
assert test_result == '0,1'


def test_repeated_capabilies_slice_prefix():
test_result = convert_repeated_capabilities(slice(0, 1), prefix='ScriptTrigger')
assert test_result == 'ScriptTrigger0'
test_result = convert_repeated_capabilities(slice(0, 2), prefix='ScriptTrigger')
assert test_result == 'ScriptTrigger0,ScriptTrigger1'
test_result = convert_repeated_capabilities(slice(None, 2), prefix='ScriptTrigger')
assert test_result == 'ScriptTrigger0,ScriptTrigger1'

Loading