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

Bug1070/nidigital remove redundant size param #1104

Merged
merged 7 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ All notable changes to this project will be documented in this file.
* #### Added
* #### Changed
* Fix get/set properties - [#1062](https://github.com/ni/nimi-python/issues/1062)
* Removed array-size parameter from apply_tdr_offsets() and write_source_waveform_broadcast_u32() methods - [#1070](https://github.com/ni/nimi-python/issues/1070)
* #### Removed
* ### NI-TClk
* #### Added
Expand Down
20 changes: 3 additions & 17 deletions docs/nidigital/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ apply_tdr_offsets

.. py:currentmodule:: nidigital.Session

.. py:method:: apply_tdr_offsets(num_offsets, offsets)
.. py:method:: apply_tdr_offsets(offsets)

TBD

Expand All @@ -176,16 +176,9 @@ apply_tdr_offsets

.. code:: python

session.channels[0,1].apply_tdr_offsets(num_offsets, offsets)
session.channels[0,1].apply_tdr_offsets(offsets)


:param num_offsets:





:type num_offsets: int
:param offsets:


Expand Down Expand Up @@ -3277,7 +3270,7 @@ write_source_waveform_broadcast_u32

.. py:currentmodule:: nidigital.Session

.. py:method:: write_source_waveform_broadcast_u32(waveform_name, waveform_size, waveform_data)
.. py:method:: write_source_waveform_broadcast_u32(waveform_name, waveform_data)
sbethur marked this conversation as resolved.
Show resolved Hide resolved

TBD

Expand All @@ -3292,13 +3285,6 @@ write_source_waveform_broadcast_u32


:type waveform_name: str
:param waveform_size:





:type waveform_size: int
:param waveform_data:


Expand Down
10 changes: 3 additions & 7 deletions generated/nidigital/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def _get_error_description(self, error_code):
''' These are code-generated '''

@ivi_synchronized
def apply_tdr_offsets(self, num_offsets, offsets):
def apply_tdr_offsets(self, offsets):
r'''apply_tdr_offsets

TBD
Expand All @@ -664,11 +664,9 @@ def apply_tdr_offsets(self, num_offsets, offsets):
You can specify a subset of repeated capabilities using the Python index notation on an
nidigital.Session repeated capabilities container, and calling this method on the result.:

session.channels[0,1].apply_tdr_offsets(num_offsets, offsets)
session.channels[0,1].apply_tdr_offsets(offsets)
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty confused why this is only a documentation change.
If you look at the old code to teh left, on line 677:

        num_offsets_ctype = _visatype.ViInt32(0 if offsets is None else len(offsets))  # case S160		

is the same as the right hand side.

Why was parameter num_offsets not being used?
Was the generator generating valid yet "incorrect" code?
Or more likely, should the generator have caught a mistake in metadata and broken at codegen time?

@texasaggie97

Copy link
Contributor Author

Choose a reason for hiding this comment

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

{
    'direction': 'in',
    'name': 'offsets',
    'size': {
        'mechanism': 'passed-in',
        'value': 'numOffsets'
    },
    'type': 'ViReal64[]'
}

This is how metadata looked like before my fix, which was to change mechanism to len. Generated code used passed in list to figure out the size that needs to be passed to C DLL, but also added numOffsets as API method parameter.

Copy link
Member

Choose a reason for hiding this comment

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

The public method has a parameter num_offsets.
Metadata says 'size': {'mechanism': 'passed-in', 'value': 'numOffsets'}
But the generated code never uses numOffsets. In line 677 (left), variable num_offsets_ctype is initialized with the length of offsets.


Args:
num_offsets (int):

offsets (list of float):

'''
Expand Down Expand Up @@ -3574,16 +3572,14 @@ def write_sequencer_register(self, reg, value):
return

@ivi_synchronized
def write_source_waveform_broadcast_u32(self, waveform_name, waveform_size, waveform_data):
def write_source_waveform_broadcast_u32(self, waveform_name, waveform_data):
r'''write_source_waveform_broadcast_u32

TBD

Args:
waveform_name (str):

waveform_size (int):

waveform_data (list of int):

'''
Expand Down
4 changes: 2 additions & 2 deletions src/nidigital/metadata/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
'direction': 'in',
'name': 'offsets',
'size': {
'mechanism': 'passed-in',
'mechanism': 'len',
sbethur marked this conversation as resolved.
Show resolved Hide resolved
'value': 'numOffsets'
},
'type': 'ViReal64[]'
Expand Down Expand Up @@ -3672,7 +3672,7 @@
'direction': 'in',
'name': 'waveformData',
'size': {
'mechanism': 'passed-in',
'mechanism': 'len',
'value': 'waveformSize'
},
'type': 'ViUInt32[]'
Expand Down
Binary file not shown.
14 changes: 14 additions & 0 deletions src/nidigital/system_tests/test_files/pin_levels.digilevels
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
sbethur marked this conversation as resolved.
Show resolved Hide resolved
<PinLevelsFile xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="1.0" xmlns="http://www.ni.com/Semiconductor/PinLevels">
<PinLevelsSheet>
<DigitalPinLevelSets>
<DigitalPinLevelSet pin="AllPins">
<Vil>1 V</Vil>
<Vih>5 V</Vih>
<Vol>2 V</Vol>
<Voh>4 V</Voh>
<TerminationMode>HighZ</TerminationMode>
</DigitalPinLevelSet>
</DigitalPinLevelSets>
</PinLevelsSheet>
</PinLevelsFile>
43 changes: 43 additions & 0 deletions src/nidigital/system_tests/test_files/pin_map.pinmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<PinMap xmlns="http://www.ni.com/TestStand/SemiconductorModule/PinMap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="1.5">
<Instruments>
<NIDigitalPatternInstrument name="PXI1Slot2" numberOfChannels="32" group="Digital" />
<NIDigitalPatternInstrument name="PXI1Slot5" numberOfChannels="32" group="Digital" />
</Instruments>
<Pins>
<DUTPin name="LO0" />
<DUTPin name="HI0" />
<DUTPin name="LO1" />
<DUTPin name="HI1" />
</Pins>
<PinGroups>
<PinGroup name="AllPins">
<PinReference pin="LO0" />
<PinReference pin="HI0" />
<PinReference pin="LO1" />
<PinReference pin="HI1" />
</PinGroup>
<PinGroup name="LowPins">
<PinReference pin="LO0" />
<PinReference pin="LO1" />
</PinGroup>
<PinGroup name="HighPins">
<PinReference pin="HI0" />
<PinReference pin="HI1" />
</PinGroup>
</PinGroups>
<Sites>
<Site siteNumber="0" />
<Site siteNumber="1" />
</Sites>
<Connections>
<Connection pin="HI0" siteNumber="0" instrument="PXI1Slot5" channel="0" />
<Connection pin="HI0" siteNumber="1" instrument="PXI1Slot5" channel="1" />
<Connection pin="HI1" siteNumber="0" instrument="PXI1Slot5" channel="2" />
<Connection pin="HI1" siteNumber="1" instrument="PXI1Slot5" channel="3" />
<Connection pin="LO0" siteNumber="0" instrument="PXI1Slot2" channel="16" />
<Connection pin="LO0" siteNumber="1" instrument="PXI1Slot2" channel="17" />
<Connection pin="LO1" siteNumber="0" instrument="PXI1Slot2" channel="18" />
<Connection pin="LO1" siteNumber="1" instrument="PXI1Slot2" channel="19" />
</Connections>
</PinMap>
8 changes: 8 additions & 0 deletions src/nidigital/system_tests/test_files/specifications.specs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Specifications xmlns:f="http://www.ni.com/schemas/Semiconductor/Formula.xsd" schemaVersion="1.0" xmlns="http://www.ni.com/schemas/Semiconductor/Specifications.xsd">
<Section name="AC">
<f:Formula symbol="Period">
<f:Definition>10 µ</f:Definition>
</f:Formula>
</Section>
</Specifications>
24 changes: 24 additions & 0 deletions src/nidigital/system_tests/test_files/timing.digitiming
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<TimingFile xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="1.0" xmlns="http://www.ni.com/Semiconductor/Timing">
<TimingSheet>
<TimeSets>
<TimeSet name="t0">
<Period>AC.Period</Period>
<PinEdges>
<PinEdge pin="AllPins">
<ReturnToLow>
<On>AC.Period * 0.1</On>
<Data>AC.Period * 0.2</Data>
<Return>AC.Period * 0.8</Return>
<Off>AC.Period * 0.9</Off>
</ReturnToLow>
<CompareStrobe>
<Strobe>AC.Period * 0.5</Strobe>
</CompareStrobe>
<DataSource>Pattern</DataSource>
</PinEdge>
</PinEdges>
</TimeSet>
</TimeSets>
</TimingSheet>
</TimingFile>
65 changes: 65 additions & 0 deletions src/nidigital/system_tests/test_system_nidigital.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nidigital
import os
import pytest

instr = ['PXI1Slot2', 'PXI1Slot5']
Expand Down Expand Up @@ -33,3 +34,67 @@ def test_property_real64(multi_instrument_session):
def test_property_string(multi_instrument_session):
multi_instrument_session.start_label = 'foo'
assert multi_instrument_session.start_label == 'foo'


def test_tdr_all_channels(multi_instrument_session):
applied_offsets = multi_instrument_session.tdr(apply_offsets=False)
assert len(applied_offsets) == multi_instrument_session.channel_count

multi_instrument_session.apply_tdr_offsets(applied_offsets)

channels = [multi_instrument_session.get_channel_name(i) for i in range(1, multi_instrument_session.channel_count + 1)]
fetched_offsets = [multi_instrument_session.channels[i].tdr_offset for i in channels]
assert fetched_offsets == applied_offsets


def test_tdr_some_channels(multi_instrument_session):
channels = [multi_instrument_session.get_channel_name(i) for i in [64, 1, 50, 25]]
applied_offsets = multi_instrument_session.channels[channels].tdr(apply_offsets=False)
assert len(applied_offsets) == len(channels)

multi_instrument_session.channels[channels].apply_tdr_offsets(applied_offsets)

fetched_offsets = [multi_instrument_session.channels[i].tdr_offset for i in channels]
assert fetched_offsets == applied_offsets


def test_source_waveform_parallel_broadcast(multi_instrument_session):
configure_session(multi_instrument_session)

multi_instrument_session.create_source_waveform_parallel(
pin_list='LowPins',
waveform_name='new_waveform',
data_mapping=2600)

multi_instrument_session.write_source_waveform_broadcast_u32(
waveform_name='new_waveform',
waveform_data=[i for i in range(4)])

multi_instrument_session.burst_pattern(
site_list='',
start_label='new_pattern',
select_digital_function=False,
wait_until_done=True,
timeout=5)

pass_fail = multi_instrument_session.get_site_pass_fail(site_list='')
assert pass_fail == [True, True]


def configure_session(session):
test_files_dir = os.path.join(os.getcwd(), 'src\\nidigital\\system_tests\\test_files')
sbethur marked this conversation as resolved.
Show resolved Hide resolved

session.load_pin_map(os.path.join(test_files_dir, 'pin_map.pinmap'))

session.load_specifications(os.path.join(test_files_dir, 'specifications.specs'))
session.load_levels(os.path.join(test_files_dir, 'pin_levels.digilevels'))
session.load_timing(os.path.join(test_files_dir, 'timing.digitiming'))
session.apply_levels_and_timing(
site_list='',
levels_sheet='pin_levels',
timing_sheet='timing',
initial_state_high_pins='',
initial_state_low_pins='',
initial_state_tristate_pins='')

session.load_pattern(os.path.join(test_files_dir, 'pattern.digipat'))