Skip to content

Commit 753c21f

Browse files
authored
US1198694: add nidcpower.Session.get_channel_names() (#1578)
* Ignore files generated during system test execution * Add get_channel_names test * get_channel_names implementation (plus some additional metadata changes that hadn't yet been codegen'd) * Update changelog * Address code review feedback (#1578) * Fix whitespace * Some additional code review feedback from Marcos * wait for a different PR to update .gitignore * Restore blank line * Take into account python_name parameter overrides when determining repeated capabilities * Address some additional feedback from Shreyas: 1. always create `python_name_override` and 2. avoid mixing camel-cased and snake-cased parameter names when comparing them * Add test for python_name override * Add tests for snake_case / camel_case conversions * Revert changes to _add_is_repeated_capability() based on code review feedback. I will fix the incorrect repeated capability for the parameter names later, by adding metadata is_repeated_capability tags to the get_channel_names parameters.
1 parent 661c2f3 commit 753c21f

File tree

11 files changed

+196
-20
lines changed

11 files changed

+196
-20
lines changed

CHANGELOG.md

+17-14
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,24 @@ All notable changes to this project will be documented in this file.
3333
* #### Removed
3434
* ### `nidcpower` (NI-DCPower)
3535
* #### Added
36+
* `get_channel_names` - [#1588](https://github.com/ni/nimi-python/issues/1588)
3637
* API parity with NI-DCPower 20.7.0 by adding Output Cutoff functionality.
37-
* Properties added:
38-
* `output_cutoff_current_change_limit_high`
39-
* `output_cutoff_current_change_limit_low`
40-
* `output_cutoff_current_measure_limit_high`
41-
* `output_cutoff_current_measure_limit_low`
42-
* `output_cutoff_current_overrange_enabled`
43-
* `output_cutoff_enabled`
44-
* `output_cutoff_voltage_change_limit_high`
45-
* `output_cutoff_voltage_change_limit_low`
46-
* `output_cutoff_voltage_output_limit_high`
47-
* `output_cutoff_voltage_output_limit_low`
48-
* Methods added:
49-
* `clear_latched_output_cutoff_state`
50-
* `query_latched_output_cutoff_state`
38+
* Properties added:
39+
* `output_cutoff_current_change_limit_high`
40+
* `output_cutoff_current_change_limit_low`
41+
* `output_cutoff_current_measure_limit_high`
42+
* `output_cutoff_current_measure_limit_low`
43+
* `output_cutoff_current_overrange_enabled`
44+
* `output_cutoff_enabled`
45+
* `output_cutoff_voltage_change_limit_high`
46+
* `output_cutoff_voltage_change_limit_low`
47+
* `output_cutoff_voltage_output_limit_high`
48+
* `output_cutoff_voltage_output_limit_low`
49+
* Methods added:
50+
* `clear_latched_output_cutoff_state`
51+
* `query_latched_output_cutoff_state`
52+
* #### Changed
53+
* #### Removed
5154
* #### Changed
5255
* #### Removed
5356
* ### `nidigital` (NI-Digital Pattern Driver)

build/helper/helper.py

-1
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,3 @@ def test_get_development_status():
233233
config['module_version'] = '19.9.9'
234234
assert get_development_status(config) == '5 - Production/Stable'
235235

236-

docs/nidcpower/class.rst

+44
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,50 @@ get_channel_name
858858
859859
860860
861+
get_channel_names
862+
-----------------
863+
864+
.. py:currentmodule:: nidcpower.Session
865+
866+
.. py:method:: get_channel_names(indices)
867+
868+
Returns a list of channel names for given channel indices.
869+
870+
871+
872+
873+
.. tip:: This method requires repeated capabilities. If called directly on the
874+
nidcpower.Session object, then the method will use all repeated capabilities in the session.
875+
You can specify a subset of repeated capabilities using the Python index notation on an
876+
nidcpower.Session repeated capabilities container, and calling this method on the result.
877+
878+
879+
:param indices:
880+
881+
882+
Index list for the channels in the session. Valid values are from zero to the total number of channels in the session minus one. The index string can be one of the following formats:
883+
884+
- A comma-separated listfor example, "0,2,3,1"
885+
- A range using a hyphen—for example, "0-3"
886+
- A range using a colon—for example, "0:3 "
887+
888+
You can combine comma-separated lists and ranges that use a hyphen or colon. Both out-of-order and repeated indices are supported ("2,3,0," "1,2,2,3"). White space characters, including spaces, tabs, feeds, and carriage returns, are allowed between characters. Ranges can be incrementing or decrementing.
889+
890+
891+
892+
893+
:type indices: basic sequence types or str or int
894+
895+
:rtype: list of str
896+
:return:
897+
898+
899+
The channel name(s) at the specified indices.
900+
901+
902+
903+
904+
861905
get_ext_cal_last_date_and_time
862906
------------------------------
863907

generated/nidcpower/nidcpower/_library.py

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, ctypes_library):
3737
self.niDCPower_GetAttributeViReal64_cfunc = None
3838
self.niDCPower_GetAttributeViString_cfunc = None
3939
self.niDCPower_GetChannelName_cfunc = None
40+
self.niDCPower_GetChannelNameFromString_cfunc = None
4041
self.niDCPower_GetError_cfunc = None
4142
self.niDCPower_GetExtCalLastDateAndTime_cfunc = None
4243
self.niDCPower_GetExtCalLastTemp_cfunc = None
@@ -225,6 +226,14 @@ def niDCPower_GetChannelName(self, vi, index, buffer_size, channel_name): # noq
225226
self.niDCPower_GetChannelName_cfunc.restype = ViStatus # noqa: F405
226227
return self.niDCPower_GetChannelName_cfunc(vi, index, buffer_size, channel_name)
227228

229+
def niDCPower_GetChannelNameFromString(self, vi, indices, buffer_size, names): # noqa: N802
230+
with self._func_lock:
231+
if self.niDCPower_GetChannelNameFromString_cfunc is None:
232+
self.niDCPower_GetChannelNameFromString_cfunc = self._get_library_function('niDCPower_GetChannelNameFromString')
233+
self.niDCPower_GetChannelNameFromString_cfunc.argtypes = [ViSession, ctypes.POINTER(ViChar), ViInt32, ctypes.POINTER(ViChar)] # noqa: F405
234+
self.niDCPower_GetChannelNameFromString_cfunc.restype = ViStatus # noqa: F405
235+
return self.niDCPower_GetChannelNameFromString_cfunc(vi, indices, buffer_size, names)
236+
228237
def niDCPower_GetError(self, vi, code, buffer_size, description): # noqa: N802
229238
with self._func_lock:
230239
if self.niDCPower_GetError_cfunc is None:

generated/nidcpower/nidcpower/session.py

+38
Original file line numberDiff line numberDiff line change
@@ -3692,6 +3692,44 @@ def _get_attribute_vi_string(self, attribute_id):
36923692
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
36933693
return attribute_value_ctype.value.decode(self._encoding)
36943694

3695+
@ivi_synchronized
3696+
def get_channel_names(self, indices):
3697+
r'''get_channel_names
3698+
3699+
Returns a list of channel names for given channel indices.
3700+
3701+
Tip:
3702+
This method requires repeated capabilities. If called directly on the
3703+
nidcpower.Session object, then the method will use all repeated capabilities in the session.
3704+
You can specify a subset of repeated capabilities using the Python index notation on an
3705+
nidcpower.Session repeated capabilities container, and calling this method on the result.
3706+
3707+
Args:
3708+
indices (basic sequence types or str or int): Index list for the channels in the session. Valid values are from zero to the total number of channels in the session minus one. The index string can be one of the following formats:
3709+
3710+
- A comma-separated list—for example, "0,2,3,1"
3711+
- A range using a hyphen—for example, "0-3"
3712+
- A range using a colon—for example, "0:3 "
3713+
3714+
You can combine comma-separated lists and ranges that use a hyphen or colon. Both out-of-order and repeated indices are supported ("2,3,0," "1,2,2,3"). White space characters, including spaces, tabs, feeds, and carriage returns, are allowed between characters. Ranges can be incrementing or decrementing.
3715+
3716+
3717+
Returns:
3718+
names (list of str): The channel name(s) at the specified indices.
3719+
3720+
'''
3721+
vi_ctype = _visatype.ViSession(self._vi) # case S110
3722+
indices_ctype = ctypes.create_string_buffer(_converters.convert_repeated_capabilities_without_prefix(indices).encode(self._encoding)) # case C040
3723+
buffer_size_ctype = _visatype.ViInt32() # case S170
3724+
names_ctype = None # case C050
3725+
error_code = self._library.niDCPower_GetChannelNameFromString(vi_ctype, indices_ctype, buffer_size_ctype, names_ctype)
3726+
errors.handle_error(self, error_code, ignore_warnings=True, is_error_handling=False)
3727+
buffer_size_ctype = _visatype.ViInt32(error_code) # case S180
3728+
names_ctype = (_visatype.ViChar * buffer_size_ctype.value)() # case C060
3729+
error_code = self._library.niDCPower_GetChannelNameFromString(vi_ctype, indices_ctype, buffer_size_ctype, names_ctype)
3730+
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=False)
3731+
return _converters.convert_comma_separated_string_to_list(names_ctype.value.decode(self._encoding))
3732+
36953733
def _get_error(self):
36963734
r'''_get_error
36973735

generated/nidcpower/nidcpower/unit_tests/_mock_helper.py

+15
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def __init__(self):
6363
self._defaults['GetChannelName'] = {}
6464
self._defaults['GetChannelName']['return'] = 0
6565
self._defaults['GetChannelName']['channelName'] = None
66+
self._defaults['GetChannelNameFromString'] = {}
67+
self._defaults['GetChannelNameFromString']['return'] = 0
68+
self._defaults['GetChannelNameFromString']['channelName'] = None
6669
self._defaults['GetError'] = {}
6770
self._defaults['GetError']['return'] = 0
6871
self._defaults['GetError']['code'] = None
@@ -342,6 +345,16 @@ def niDCPower_GetChannelName(self, vi, index, buffer_size, channel_name): # noq
342345
channel_name.value = self._defaults['GetChannelName']['channelName'].encode('ascii')
343346
return self._defaults['GetChannelName']['return']
344347

348+
def niDCPower_GetChannelNameFromString(self, vi, indices, buffer_size, names): # noqa: N802
349+
if self._defaults['GetChannelNameFromString']['return'] != 0:
350+
return self._defaults['GetChannelNameFromString']['return']
351+
if self._defaults['GetChannelNameFromString']['channelName'] is None:
352+
raise MockFunctionCallError("niDCPower_GetChannelNameFromString", param='channelName')
353+
if buffer_size.value == 0:
354+
return len(self._defaults['GetChannelNameFromString']['channelName'])
355+
names.value = self._defaults['GetChannelNameFromString']['channelName'].encode('ascii')
356+
return self._defaults['GetChannelNameFromString']['return']
357+
345358
def niDCPower_GetError(self, vi, code, buffer_size, description): # noqa: N802
346359
if self._defaults['GetError']['return'] != 0:
347360
return self._defaults['GetError']['return']
@@ -740,6 +753,8 @@ def set_side_effects_and_return_values(self, mock_library):
740753
mock_library.niDCPower_GetAttributeViString.return_value = 0
741754
mock_library.niDCPower_GetChannelName.side_effect = MockFunctionCallError("niDCPower_GetChannelName")
742755
mock_library.niDCPower_GetChannelName.return_value = 0
756+
mock_library.niDCPower_GetChannelNameFromString.side_effect = MockFunctionCallError("niDCPower_GetChannelNameFromString")
757+
mock_library.niDCPower_GetChannelNameFromString.return_value = 0
743758
mock_library.niDCPower_GetError.side_effect = MockFunctionCallError("niDCPower_GetError")
744759
mock_library.niDCPower_GetError.return_value = 0
745760
mock_library.niDCPower_GetExtCalLastDateAndTime.side_effect = MockFunctionCallError("niDCPower_GetExtCalLastDateAndTime")

src/nidcpower/metadata/attributes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# This file is generated from NI-DCPower API metadata version 21.0.0d52
2+
# This file is generated from NI-DCPower API metadata version 21.0.0d69
33
attributes = {
44
1050003: {
55
'access': 'read-write',

src/nidcpower/metadata/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
# This file is generated from NI-DCPower API metadata version 21.0.0d52
2+
# This file is generated from NI-DCPower API metadata version 21.0.0d69
33
config = {
4-
'api_version': '21.0.0d52',
4+
'api_version': '21.0.0d69',
55
'c_function_prefix': 'niDCPower_',
66
'close_function': 'close',
77
'context_manager_name': {

src/nidcpower/metadata/enums.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# This file is generated from NI-DCPower API metadata version 21.0.0d52
2+
# This file is generated from NI-DCPower API metadata version 21.0.0d69
33
enums = {
44
'ApertureTimeUnits': {
55
'values': [

src/nidcpower/metadata/functions.py

+52-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# This file is generated from NI-DCPower API metadata version 21.0.0d52
2+
# This file is generated from NI-DCPower API metadata version 21.0.0d69
33
functions = {
44
'AbortWithChannels': {
55
'documentation': {
@@ -1453,6 +1453,57 @@
14531453
],
14541454
'returns': 'ViStatus'
14551455
},
1456+
'GetChannelNameFromString': {
1457+
'documentation': {
1458+
'description': '\nReturns a list of channel names for given channel indices.'
1459+
},
1460+
'parameters': [
1461+
{
1462+
'direction': 'in',
1463+
'documentation': {
1464+
'description': '\nIdentifies a particular instrument session. **vi** is obtained from the\nniDCPower_InitializeWithChannels function.\n'
1465+
},
1466+
'name': 'vi',
1467+
'type': 'ViSession'
1468+
},
1469+
{
1470+
'direction': 'in',
1471+
'documentation': {
1472+
'description': '\nIndex list for the channels in the session. Valid values are from zero to the total number of channels in the session minus one. The index string can be one of the following formats:\n\n- A comma-separated list—for example, "0,2,3,1"\n- A range using a hyphen—for example, "0-3"\n- A range using a colon—for example, "0:3 "\n\nYou can combine comma-separated lists and ranges that use a hyphen or colon. Both out-of-order and repeated indices are supported ("2,3,0," "1,2,2,3"). White space characters, including spaces, tabs, feeds, and carriage returns, are allowed between characters. Ranges can be incrementing or decrementing.\n'
1473+
},
1474+
'name': 'index',
1475+
'python_api_converter_name': 'convert_repeated_capabilities_without_prefix',
1476+
'python_name': 'indices',
1477+
'type': 'ViConstString',
1478+
'type_in_documentation': 'basic sequence types or str or int'
1479+
},
1480+
{
1481+
'direction': 'in',
1482+
'documentation': {
1483+
'description': '\nThe number of elements in the ViChar array you specify for name.\n'
1484+
},
1485+
'name': 'bufferSize',
1486+
'type': 'ViInt32'
1487+
},
1488+
{
1489+
'direction': 'out',
1490+
'documentation': {
1491+
'description': 'The channel name(s) at the specified indices.'
1492+
},
1493+
'name': 'channelName',
1494+
'python_api_converter_name': 'convert_comma_separated_string_to_list',
1495+
'python_name': 'names',
1496+
'size': {
1497+
'mechanism': 'ivi-dance',
1498+
'value': 'bufferSize'
1499+
},
1500+
'type': 'ViChar[]',
1501+
'type_in_documentation': 'list of str'
1502+
}
1503+
],
1504+
'python_name': 'get_channel_names',
1505+
'returns': 'ViStatus'
1506+
},
14561507
'GetError': {
14571508
'codegen_method': 'private',
14581509
'documentation': {

src/nidcpower/system_tests/test_system_nidcpower.py

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ def session():
1111
yield simulated_session
1212

1313

14+
@pytest.fixture(scope='function')
15+
def multi_instrument_session():
16+
instruments = ['PXI1Slot2', 'PXI1Slot5']
17+
with nidcpower.Session(resource_name=','.join(instruments), options='Simulate=1, DriverSetup=Model:4162; BoardType:PXIe') as simulated_session:
18+
yield simulated_session
19+
20+
1421
@pytest.fixture(scope='function')
1522
def single_channel_session():
1623
with nidcpower.Session('4162', '0', False, 'Simulate=1, DriverSetup=Model:4162; BoardType:PXIe') as simulated_session:
@@ -36,6 +43,16 @@ def test_get_channel_name(session):
3643
assert name == '0'
3744

3845

46+
def test_get_channel_names(multi_instrument_session):
47+
# Once we have support for independent channels, we should update this test to include
48+
# the instrument names in the expected channel names -- or possibly add a separate test
49+
# expected_string = ['{0}/{1}'.format(instruments[0], x) for x in range(12)]
50+
# (Tracked on GitHub by #1582)
51+
expected_string = ['{0}'.format(x) for x in range(12)]
52+
channel_indices = ['0-1, 2, 3:4', 5, (6, 7), range(8, 10), slice(10, 12)]
53+
assert multi_instrument_session.get_channel_names(indices=channel_indices) == expected_string
54+
55+
3956
def test_get_attribute_string(session):
4057
model = session.instrument_model
4158
assert model == 'NI PXIe-4162'

0 commit comments

Comments
 (0)