Skip to content

Commit

Permalink
Enable driver support for nitclk (#1054)
Browse files Browse the repository at this point in the history
* Add initial metadata

* Create nitclk.mak

* Remove numpy restriction

Bug fixed

* Upgrade pip

* Remove specific version of flake8

'\' in comments now need to be escaped

* Add basepython section

* Try using pypy3.5

* Go back to pypy3 and remove basepython block

* Don't need to run build_test for all builds - only 3.6

* Remove warning from coverage

* Undo previous change

* Try disabling faulthandler

* Remove --no-faulthandler

* pypy needs an older version of pytest

See pytest-dev/pytest#5807

* Use platform_python_implementation since implementation_name is not defined on Python2

* Try to get back to the initial coverage

* Do the same thing for build_test

* Remove redundant pip

* Add codecov file to try to control limits for passing

* Enable nitclk build

* There are some files we will need to skip for now

* Add generated nitclk files

* Update generated files

* Can't skip README.rst

* Update templates

* Add new cases for buffers with a converter

* Need to handle ' []' to normalize everything

* Get the session handle name from config instead of hardcoding 'vi'

* Temp commit

* Fix syntax error

* Test new cases

* Force change

* Update generated files

* Update generated files

* Add different target for pr (project) and commit (patch)

* threshold should be number

* Renumber scaler cases to be in order used in the code

* Update generated files

* Renumber buffer cases to match order used in code

* Move and rename test to match case (C020)

* Update generated files

* Add nitclk specific session template

* No longer need to skip generating session.py

* Add new session.py

* Add placeholder nitclk example

* Enable example documentation build

* Add generated examples.rst

* Add TClk to static files

* Add tclk to index

* Add tclk top level file

* Update generated files

* Add VIUInt32 matcher

* Add ViSession buffer matcher

* We want to look at all of nitclk since there are differences in some of the generarted files

* Run unit tests on nitclk

* Add initial test and setup

* Update generated files

* Correct wrong exception

* Rename test

* Add return (helps editor auto formatting)

* Update generated files

* Few more tests

* Add new filter type

Needed for API functions in nitclk

* Don't try to use a singleton any more - didn't work

* Use new filter type

* All API functions tested

This covers both the api function and the helper class

* Update generated files

* Fix metadata for GetAttributeViString

* More tests!

* Correct type is ViSession

* Need to say it isn't the session handle

* Test class for testing session number converter

* Additional tests

* Update generated files

* We don't need to measure anything from nitclk or nimodinst other than session.py

* Fix class names to work with pytest

* Use correct name

* Don't codegen ViBoolean functions since they aren't actually used

* Update generated files

* Handle not having an 'init_function' in config

* Remove InitForDocumentation

* Add tclk specific class.rst template

* Updates

* Build using nitclk specific class.rst template

* Add type in documentation

* Fix output path

* Documentation updates

* We need to be able to use method or function, default is method

* Links need to be different for nitclk

* Clean up nitclk class documentation

* Put functions first (properties are an advanced feature)
* Do a better job with headers that show up in the TOC
* Basic documentation for Public API and SessionReference

* Update generated files

* Update generated files

* Use the session name from config - doesn't always match the parameter name

* Update converter name

* Need a reperated capabilities for get/set attribute

* Function is now private

* Update generated files

* Update

* Remove extraneous comment

* Only add properties section if there are actually properties

* Update to match latest format in master

* Update generated files

* Use the entire navigation depth

* Add 'supports_nitclk' with default of False

* Install latest built nitclk wheel for testing nifake

* Add dependency on nitclk when it is supported

* Import and use nitclk when it is supported

* Set nitclk supported

* test that session.tclk is of type nitclk.SessionReference

* Update generated files

* Install local nitclk wheel before system_tests

* Add section for nitclk support

* Update generated files

* Remove unused parameter

* Update docstring per review

* Since the type is ViSession, need to say not the session handle

* Update comments per review

* Update docstring per review

* Update class name per review

* Update generated files

* Add nitclk to CHANGELOG.md

* Remove blank line

* Update generated files

* Explicitly say doesn't support nitclk per review

* Don't need to patch entire nitclk DLL, only _library_singleton.get()

* Rely on default of False for 'supports_nitclk'

* Update generated files
  • Loading branch information
texasaggie97-zz authored and marcoskirsch committed Oct 21, 2019
1 parent 23a13f1 commit ce3a320
Show file tree
Hide file tree
Showing 33 changed files with 123 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ All notable changes to this project will be documented in this file.
`get_number_of_vectors()`, `get_pattern_file_path()`, `get_pin_type()`, `get_time_set_compare_edges()`, `get_time_set_drive_edges()`,
`is_pattern_file_modified_since_load()`, `load_levels_internal()`, `load_pattern_internal()`, `load_timing_internal()`, `uncommit()`
* Need to determine how to generate this function - `fetch_capture_waveform_u32()`
* ### NI-TClk
* #### Added
* Initial support
* #### Changed
* #### Removed


## 1.1.2 - 2019-06-06
Expand Down Expand Up @@ -794,6 +799,10 @@ and this project adheres to [Python Versioning](http://legacy.python.org/dev/pep
* #### Added
* #### Changed
* #### Removed
* ### NI-TClk
* #### Added
* #### Changed
* #### Removed
-->


4 changes: 4 additions & 0 deletions build/helper/metadata_add_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ def add_all_config_metadata(config):
if 'use_locking' not in config:
config['use_locking'] = True

if 'supports_nitclk' not in config:
config['supports_nitclk'] = False

return config


Expand Down Expand Up @@ -1262,6 +1265,7 @@ def _compare_dicts(actual, expected):
'modules': {
'metadata.enums_addon': {}
},
'supports_nitclk': False
}


Expand Down
11 changes: 11 additions & 0 deletions build/templates/class.rst.mako
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ desc = helper.get_documentation_for_node_rst(a, config, indent=0)
% endfor
% endif

% if config['supports_nitclk']:
${helper.get_rst_header_snippet('NI-TClk Support', '=')}

.. py:attribute:: tclk

This is used to get and set NI-TClk attributes on the session.

.. seealso:: See :py:attr:`nitclk.SessionReference` for a complete list of attributes.


% endif
.. contents:: Session


8 changes: 8 additions & 0 deletions build/templates/session.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import ${module_name}.errors as errors
import ${module_name}.${c['file_name']} as ${c['file_name']} # noqa: F401
% endfor

% if config['supports_nitclk']:
import nitclk
% endif

# Used for __repr__
import pprint
pp = pprint.PrettyPrinter(indent=4)
Expand Down Expand Up @@ -259,6 +263,10 @@ class Session(_SessionBase):
self.${rep_cap['python_name']} = _RepeatedCapabilities(self, '${rep_cap["prefix"]}')
% endfor

% if config['supports_nitclk']:
self.tclk = nitclk.SessionReference(self._${config['session_handle_parameter_name']})

% endif
# Store the parameter list for later printing in __repr__
param_list = []
% for param in constructor_params:
Expand Down
3 changes: 3 additions & 0 deletions build/templates/setup.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ setup(
'enum34;python_version<"3.4"',
'singledispatch;python_version<"3.4"',
'six',
% if config['supports_nitclk']:
'nitclk',
% endif
],
setup_requires=['pytest-runner', ],
tests_require=['pytest'],
Expand Down
10 changes: 10 additions & 0 deletions docs/nidigital/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6454,6 +6454,16 @@ vterm
- C Attribute: **NIDIGITAL_ATTR_VTERM**


NI-TClk Support
===============

.. py:attribute:: tclk
This is used to get and set NI-TClk attributes on the session.

.. seealso:: See :py:attr:`nitclk.SessionReference` for a complete list of attributes.


.. contents:: Session


10 changes: 10 additions & 0 deletions docs/nifgen/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5955,6 +5955,16 @@ waveform_quantum
- C Attribute: **NIFGEN_ATTR_WAVEFORM_QUANTUM**


NI-TClk Support
===============

.. py:attribute:: tclk
This is used to get and set NI-TClk attributes on the session.

.. seealso:: See :py:attr:`nitclk.SessionReference` for a complete list of attributes.


.. contents:: Session


10 changes: 10 additions & 0 deletions docs/niscope/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5861,6 +5861,16 @@ width_polarity
- C Attribute: **NISCOPE_ATTR_WIDTH_POLARITY**
NI-TClk Support
===============
.. py:attribute:: tclk
This is used to get and set NI-TClk attributes on the session.
.. seealso:: See :py:attr:`nitclk.SessionReference` for a complete list of attributes.
.. contents:: Session
1 change: 1 addition & 0 deletions generated/nidcpower/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import nidcpower.enums as enums
import nidcpower.errors as errors


# Used for __repr__
import pprint
pp = pprint.PrettyPrinter(indent=4)
Expand Down
4 changes: 4 additions & 0 deletions generated/nidigital/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import nidigital.enums as enums
import nidigital.errors as errors

import nitclk

# Used for __repr__
import pprint
pp = pprint.PrettyPrinter(indent=4)
Expand Down Expand Up @@ -1926,6 +1928,8 @@ def __init__(self, resource_name, id_query=False, reset_device=False, options={}
# Instantiate any repeated capability objects
self.channels = _RepeatedCapabilities(self, '')

self.tclk = nitclk.SessionReference(self._vi)

# Store the parameter list for later printing in __repr__
param_list = []
param_list.append("resource_name=" + pp.pformat(resource_name))
Expand Down
1 change: 1 addition & 0 deletions generated/nidigital/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def read_contents(file_to_read):
'enum34;python_version<"3.4"',
'singledispatch;python_version<"3.4"',
'six',
'nitclk',
],
setup_requires=['pytest-runner', ],
tests_require=['pytest'],
Expand Down
1 change: 1 addition & 0 deletions generated/nidmm/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import nidmm.enums as enums
import nidmm.errors as errors


# Used for __repr__
import pprint
pp = pprint.PrettyPrinter(indent=4)
Expand Down
4 changes: 4 additions & 0 deletions generated/nifake/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import nifake.custom_struct as custom_struct # noqa: F401

import nitclk

# Used for __repr__
import pprint
pp = pprint.PrettyPrinter(indent=4)
Expand Down Expand Up @@ -713,6 +715,8 @@ def __init__(self, resource_name, options={}, id_query=False, reset_device=False
# Instantiate any repeated capability objects
self.channels = _RepeatedCapabilities(self, '')

self.tclk = nitclk.SessionReference(self._vi)

# Store the parameter list for later printing in __repr__
param_list = []
param_list.append("resource_name=" + pp.pformat(resource_name))
Expand Down
1 change: 1 addition & 0 deletions generated/nifake/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def read_contents(file_to_read):
'enum34;python_version<"3.4"',
'singledispatch;python_version<"3.4"',
'six',
'nitclk',
],
setup_requires=['pytest-runner', ],
tests_require=['pytest'],
Expand Down
9 changes: 9 additions & 0 deletions generated/nifake/unit_tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def setup_method(self, method):
self.patched_library_singleton_get = patch('nifake.session._library_singleton.get', return_value=self.patched_library)
self.patched_library_singleton_get.start()

# We don't actually call into the nitclk DLL, but we do need to mock the function since it is called
self.tclk_patched_library_singleton_get = patch('nitclk.session._library_singleton.get', return_value=None)
self.tclk_patched_library_singleton_get.start()

self.side_effects_helper = _mock_helper.SideEffectsHelper()
self.side_effects_helper.set_side_effects_and_return_values(self.patched_library)
self.patched_library.niFake_InitWithOptions.side_effect = self.side_effects_helper.niFake_InitWithOptions
Expand All @@ -50,6 +54,7 @@ def setup_method(self, method):
def teardown_method(self, method):
self.patched_library_singleton_get.stop()
self.patched_library_patcher.stop()
self.tclk_patched_library_singleton_get.stop()

def niFake_read_warning(self, vi, maximum_time, reading): # noqa: N802
reading.contents.value = self.reading
Expand Down Expand Up @@ -1275,6 +1280,10 @@ def test_buffer_converter(self):
session.double_all_the_nums(nums)
self.patched_library.niFake_DoubleAllTheNums.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViInt32Matcher(len(nums)), _matchers.ViReal64BufferMatcher(nums_x2))

def test_nitclk_integration(self):
with nifake.Session('dev1') as session:
assert str(type(session.tclk)) == "<class 'nitclk.session.SessionReference'>"


# not session tests per se
def test_diagnostic_information():
Expand Down
4 changes: 4 additions & 0 deletions generated/nifgen/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import nifgen.enums as enums
import nifgen.errors as errors

import nitclk

# Used for __repr__
import pprint
pp = pprint.PrettyPrinter(indent=4)
Expand Down Expand Up @@ -3136,6 +3138,8 @@ def __init__(self, resource_name, channel_name=None, reset_device=False, options
self.script_triggers = _RepeatedCapabilities(self, 'ScriptTrigger')
self.markers = _RepeatedCapabilities(self, 'Marker')

self.tclk = nitclk.SessionReference(self._vi)

# Store the parameter list for later printing in __repr__
param_list = []
param_list.append("resource_name=" + pp.pformat(resource_name))
Expand Down
1 change: 1 addition & 0 deletions generated/nifgen/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def read_contents(file_to_read):
'enum34;python_version<"3.4"',
'singledispatch;python_version<"3.4"',
'six',
'nitclk',
],
setup_requires=['pytest-runner', ],
tests_require=['pytest'],
Expand Down
4 changes: 4 additions & 0 deletions generated/niscope/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import niscope.waveform_info as waveform_info # noqa: F401

import nitclk

# Used for __repr__
import pprint
pp = pprint.PrettyPrinter(indent=4)
Expand Down Expand Up @@ -4054,6 +4056,8 @@ def __init__(self, resource_name, id_query=False, reset_device=False, options={}
# Instantiate any repeated capability objects
self.channels = _RepeatedCapabilities(self, '')

self.tclk = nitclk.SessionReference(self._vi)

# Store the parameter list for later printing in __repr__
param_list = []
param_list.append("resource_name=" + pp.pformat(resource_name))
Expand Down
1 change: 1 addition & 0 deletions generated/niscope/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def read_contents(file_to_read):
'enum34;python_version<"3.4"',
'singledispatch;python_version<"3.4"',
'six',
'nitclk',
],
setup_requires=['pytest-runner', ],
tests_require=['pytest'],
Expand Down
1 change: 1 addition & 0 deletions generated/nise/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import nise.enums as enums
import nise.errors as errors


# Used for __repr__
import pprint
pp = pprint.PrettyPrinter(indent=4)
Expand Down
1 change: 1 addition & 0 deletions generated/niswitch/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import niswitch.enums as enums
import niswitch.errors as errors


# Used for __repr__
import pprint
pp = pprint.PrettyPrinter(indent=4)
Expand Down
2 changes: 1 addition & 1 deletion src/nidcpower/metadata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
}
],
'session_class_description': 'An NI-DCPower session to a National Instruments Programmable Power Supply or Source Measure Unit.',
'session_handle_parameter_name': 'vi'
'session_handle_parameter_name': 'vi',
}
3 changes: 2 additions & 1 deletion src/nidigital/metadata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
}
],
'session_class_description': 'An NI-Digital session',
'session_handle_parameter_name': 'vi'
'session_handle_parameter_name': 'vi',
'supports_nitclk': True,
}
2 changes: 1 addition & 1 deletion src/nidmm/metadata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
'repeated_capabilities': [
],
'session_class_description': 'An NI-DMM session to a National Instruments Digital Multimeter',
'session_handle_parameter_name': 'vi'
'session_handle_parameter_name': 'vi',
}
3 changes: 2 additions & 1 deletion src/nifake/metadata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
}
],
'session_class_description': 'An NI-FAKE session to a fake MI driver whose sole purpose is to test nimi-python code generation',
'session_handle_parameter_name': 'vi'
'session_handle_parameter_name': 'vi',
'supports_nitclk': True,
}
9 changes: 9 additions & 0 deletions src/nifake/unit_tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def setup_method(self, method):
self.patched_library_singleton_get = patch('nifake.session._library_singleton.get', return_value=self.patched_library)
self.patched_library_singleton_get.start()

# We don't actually call into the nitclk DLL, but we do need to mock the function since it is called
self.tclk_patched_library_singleton_get = patch('nitclk.session._library_singleton.get', return_value=None)
self.tclk_patched_library_singleton_get.start()

self.side_effects_helper = _mock_helper.SideEffectsHelper()
self.side_effects_helper.set_side_effects_and_return_values(self.patched_library)
self.patched_library.niFake_InitWithOptions.side_effect = self.side_effects_helper.niFake_InitWithOptions
Expand All @@ -50,6 +54,7 @@ def setup_method(self, method):
def teardown_method(self, method):
self.patched_library_singleton_get.stop()
self.patched_library_patcher.stop()
self.tclk_patched_library_singleton_get.stop()

def niFake_read_warning(self, vi, maximum_time, reading): # noqa: N802
reading.contents.value = self.reading
Expand Down Expand Up @@ -1275,6 +1280,10 @@ def test_buffer_converter(self):
session.double_all_the_nums(nums)
self.patched_library.niFake_DoubleAllTheNums.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViInt32Matcher(len(nums)), _matchers.ViReal64BufferMatcher(nums_x2))

def test_nitclk_integration(self):
with nifake.Session('dev1') as session:
assert str(type(session.tclk)) == "<class 'nitclk.session.SessionReference'>"


# not session tests per se
def test_diagnostic_information():
Expand Down
3 changes: 2 additions & 1 deletion src/nifgen/metadata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
}
],
'session_class_description': 'An NI-FGEN session to a National Instruments Signal Generator.',
'session_handle_parameter_name': 'vi'
'session_handle_parameter_name': 'vi',
'supports_nitclk': True,
}
2 changes: 1 addition & 1 deletion src/nimodinst/metadata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
'repeated_capabilities': [
],
'session_class_description': 'A NI-ModInst session to get device information',
'session_handle_parameter_name': 'handle'
'session_handle_parameter_name': 'handle',
}
3 changes: 2 additions & 1 deletion src/niscope/metadata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
}
],
'session_class_description': 'An NI-SCOPE session to a National Instruments Digitizer.',
'session_handle_parameter_name': 'vi'
'session_handle_parameter_name': 'vi',
'supports_nitclk': True,
}
2 changes: 1 addition & 1 deletion src/nise/metadata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
],
'session_class_description': 'An NI Switch Executive session',
'session_handle_parameter_name': 'vi',
'use_locking': False
'use_locking': False,
}

0 comments on commit ce3a320

Please sign in to comment.