Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -558,6 +558,7 @@
#### [nidigital] Unreleased
- Added
- (Common) Added `nitlsconfig[grpc]>=1.0.0a2` to the optional gRPC dependencies.
- Added the `nidigital_create_pin_map.py` example.
- Changed
- Removed

Expand Down
9 changes: 9 additions & 0 deletions docs/nidigital/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ nidigital_configure_time_set_and_voltage_levels.py
:encoding: utf8
:caption: `(nidigital_configure_time_set_and_voltage_levels.py) <https://github.com/ni/nimi-python/blob/master/src/nidigital/examples/configure_time_set_and_voltage_levels/nidigital_configure_time_set_and_voltage_levels.py>`_

nidigital_create_pin_map.py
---------------------------

.. literalinclude:: ../../src/nidigital/examples/create_pin_map/nidigital_create_pin_map.py
:language: python
:linenos:
:encoding: utf8
:caption: `(nidigital_create_pin_map.py) <https://github.com/ni/nimi-python/blob/master/src/nidigital/examples/create_pin_map/nidigital_create_pin_map.py>`_

nidigital_ppmu_source_and_measure.py
------------------------------------

Expand Down
Binary file not shown.
15 changes: 15 additions & 0 deletions src/nidigital/examples/create_pin_map/PinLevels.digilevels
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<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="I2C_bus">
<Vil>0</Vil>
<Vih>3.3</Vih>
<Vol>0.8</Vol>
<Voh>2</Voh>
<Vterm>0</Vterm>
<TerminationMode>HighZ</TerminationMode>
</DigitalPinLevelSet>
</DigitalPinLevelSets>
</PinLevelsSheet>
</PinLevelsFile>
33 changes: 33 additions & 0 deletions src/nidigital/examples/create_pin_map/PinMap.pinmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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="PXI1Slot3" numberOfChannels="32" group="Digital" />
</Instruments>
<Pins>
<DUTPin name="SCL" />
<DUTPin name="SDA" />
<DUTPin name="CS" />
<SystemPin name="Vcc" />
</Pins>
<PinGroups>
<PinGroup name="I2C_bus">
<PinReference pin="Vcc" />
<PinReference pin="SCL" />
<PinReference pin="SDA" />
<PinReference pin="CS" />
</PinGroup>
</PinGroups>
<Sites>
<Site siteNumber="0" />
<Site siteNumber="1" />
</Sites>
<Connections>
<Connection pin="CS" siteNumber="0,1" instrument="PXI1Slot2" channel="30" />
<Connection pin="SCL" siteNumber="0" instrument="PXI1Slot2" channel="0" />
<Connection pin="SCL" siteNumber="1" instrument="PXI1Slot3" channel="0" />
<Connection pin="SDA" siteNumber="0" instrument="PXI1Slot2" channel="1" />
<Connection pin="SDA" siteNumber="1" instrument="PXI1Slot3" channel="1" />
<SystemConnection pin="Vcc" instrument="PXI1Slot2" channel="3" />
</Connections>
</PinMap>
23 changes: 23 additions & 0 deletions src/nidigital/examples/create_pin_map/Timing.digitiming
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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="tset0">
<Period>100 ns</Period>
<PinEdges>
<PinEdge pin="I2C_bus">
<DriveNonReturn>
<On>0 ns</On>
<Data>0 ns</Data>
<Off>100 ns</Off>
</DriveNonReturn>
<CompareStrobe>
<Strobe>50 ns</Strobe>
</CompareStrobe>
<DataSource>Pattern</DataSource>
</PinEdge>
</PinEdges>
</TimeSet>
</TimeSets>
</TimingSheet>
</TimingFile>
37 changes: 37 additions & 0 deletions src/nidigital/examples/create_pin_map/create_pin_map.digiproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<SourceFile Checksum="08502C60CD9B2A0CA231CFCC420A4993" xmlns="http://www.ni.com/PlatformFramework">
<SourceModelFeatureSet>
<ParsableNamespace AssemblyFileVersion="5.3.1.50584" FeatureSetName="Digital Pattern Editor" Name="http://www.ni.com/PatternBasedDigital" OldestCompatibleVersion="4.5.0.0" Version="4.6.0.49152" />
<ParsableNamespace AssemblyFileVersion="5.3.1.50584" FeatureSetName="Editor" Name="http://www.ni.com/PlatformFramework" OldestCompatibleVersion="5.2.0.49153" Version="5.2.0.49153" />
<ApplicationVersionInfo Build="5.3.1.50584" Name="Digital Pattern Editor" Version="19.0.0" />
</SourceModelFeatureSet>
<Project xmlns="http://www.ni.com/PlatformFramework">
<ProjectSettings Id="1" ModelDefinitionType="ProjectSettings" Name="ZProjectSettings" />
<EmbeddedDefinitionReference Id="2" ModelDefinitionType="NationalInstruments.ProjectExplorer.Modeling.ProjectDataManager" Name="ProjectExplorer">
<ProjectExplorer />
</EmbeddedDefinitionReference>
<NameScopingEnvoy Id="3" ModelDefinitionType="DefaultTarget" Name="DefaultTarget">
<DefaultTarget />
<FileReference Id="14" ModelDefinitionType="DigitalPatternEditor.PatternDefinition" Name="Pattern\.digipat" StoragePath="Pattern.digipat" />
<FileReference Id="16" ModelDefinitionType="TimingDefinition" Name="Timing\.digitiming" StoragePath="Timing.digitiming" p4:IsActive="True" xmlns:p4="http://www.ni.com/PatternBasedDigital" />
<FileReference Id="17" ModelDefinitionType="PinLevelsDefinition" Name="PinLevels\.digilevels" StoragePath="PinLevels.digilevels" p4:IsActive="True" xmlns:p4="http://www.ni.com/PatternBasedDigital" />
<EmbeddedDefinitionReference Id="18" ModelDefinitionType="{http://www.ni.com/PatternBasedDigital}CaptureResultsDefinition" Name="CaptureResults">
<CaptureResultsDefinition xmlns="http://www.ni.com/PatternBasedDigital" />
</EmbeddedDefinitionReference>
<EmbeddedDefinitionReference Id="20" ModelDefinitionType="{http://www.ni.com/PatternBasedDigital}BurstResultsDefinition" Name="BurstResults">
<BurstResultsDefinition xmlns="http://www.ni.com/PatternBasedDigital" />
</EmbeddedDefinitionReference>
<EmbeddedDefinitionReference Id="22" ModelDefinitionType="{http://www.ni.com/PatternBasedDigital}SystemInfoDefinition" Name="SystemInfo">
<SystemInfoDefinition xmlns="http://www.ni.com/PatternBasedDigital" />
</EmbeddedDefinitionReference>
<EmbeddedDefinitionReference Id="23" ModelDefinitionType="{http://www.ni.com/PatternBasedDigital}DigitalScopeDefinition" Name="DigitalScope">
<DigitalScopeDefinition xmlns="http://www.ni.com/PatternBasedDigital" />
</EmbeddedDefinitionReference>
<FileReference Id="24" ModelDefinitionType="PinMap" Name="PinMap\.pinmap" StoragePath="PinMap.pinmap" p4:IsActive="True" xmlns:p4="http://www.ni.com/PatternBasedDigital" />
</NameScopingEnvoy>
<EmbeddedDefinitionReference Id="7" ModelDefinitionType="DigitalPatternEditor.ProjectPropertiesDefinition" Name="ProjectProperties">
<ProjectPropertiesDefinition xmlns="http://www.ni.com/PatternBasedDigital" />
</EmbeddedDefinitionReference>
</Project>
<ProjectInformation xmlns="http://www.ni.com/PlatformFramework" />
</SourceFile>
107 changes: 107 additions & 0 deletions src/nidigital/examples/create_pin_map/nidigital_create_pin_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/python

import argparse
import nidigital
import os
import sys
import tempfile
from xml.etree import ElementTree


def _create_pin_map(resource_name, file_path):
Comment thread
divakar-selvam07 marked this conversation as resolved.
Resolved
instruments = [name.strip() for name in resource_name.split(',')]
if len(instruments) != 2 or not all(instruments) or instruments[0] == instruments[1]:
raise ValueError('This example requires two distinct instrument resource names, for example PXI1Slot2,PXI1Slot3.')

# Python does not expose the LabVIEW pin/channel map creation APIs, so create an XML file for load_pin_map.
# The bundled PinMap.pinmap is the equivalent reference map for create_pin_map.digiproj.
pin_map = ElementTree.Element('PinMap', xmlns='http://www.ni.com/TestStand/SemiconductorModule/PinMap.xsd', schemaVersion='1.5')
instrument_list = ElementTree.SubElement(pin_map, 'Instruments')
for instrument in instruments:
ElementTree.SubElement(instrument_list, 'NIDigitalPatternInstrument', name=instrument, numberOfChannels='32', group='Digital')

# Pin and group names must match the bundled levels, timing, and pattern files.
dut_pins = ('SCL', 'SDA', 'CS')
system_pins = ('Vcc',)
dut_pin_connections = (('SCL', '0'), ('SDA', '1'))
shared_pin_connection = {'pin': 'CS', 'siteNumber': '0,1', 'instrument': instruments[0], 'channel': '30'}
system_pin_connections = (('Vcc', instruments[0], '3'),)

pins = ElementTree.SubElement(pin_map, 'Pins')
Comment thread
divakar-selvam07 marked this conversation as resolved.
Resolved
for pin in dut_pins:
ElementTree.SubElement(pins, 'DUTPin', name=pin)
for pin in system_pins:
ElementTree.SubElement(pins, 'SystemPin', name=pin)

pin_groups = ElementTree.SubElement(pin_map, 'PinGroups')
pin_group = ElementTree.SubElement(pin_groups, 'PinGroup', name='I2C_bus')
for pin in system_pins + dut_pins:
ElementTree.SubElement(pin_group, 'PinReference', pin=pin)

sites = ElementTree.SubElement(pin_map, 'Sites')
connections = ElementTree.SubElement(pin_map, 'Connections')
# Both sites share CS on the first instrument; Vcc is a system pin, not a per-site pin.
ElementTree.SubElement(connections, 'Connection', **shared_pin_connection)
for site, instrument in enumerate(instruments):
ElementTree.SubElement(sites, 'Site', siteNumber=str(site))
for pin, channel in dut_pin_connections:
ElementTree.SubElement(connections, 'Connection', pin=pin, siteNumber=str(site), instrument=instrument, channel=channel)
for pin, instrument, channel in system_pin_connections:
ElementTree.SubElement(connections, 'SystemConnection', pin=pin, instrument=instrument, channel=channel)

ElementTree.ElementTree(pin_map).write(file_path, encoding='utf-8', xml_declaration=True)


def example(resource_name, options):
# Keep the generated pin map outside the example directory and remove it after closing the session.
with tempfile.TemporaryDirectory() as temp_dir:
pin_map_filename = os.path.join(temp_dir, 'PinMap.pinmap')
_create_pin_map(resource_name, pin_map_filename)

with nidigital.Session(resource_name=resource_name, options=options) as session:
# Load the pin map created at runtime, rather than the bundled reference map.
session.load_pin_map(pin_map_filename)

dir = os.path.dirname(os.path.abspath(__file__))
levels_filename = os.path.join(dir, 'PinLevels.digilevels')
timing_filename = os.path.join(dir, 'Timing.digitiming')
session.load_specifications_levels_and_timing(levels_file_paths=levels_filename, timing_file_paths=timing_filename)

session.apply_levels_and_timing(levels_filename, timing_filename)

pattern_filename = os.path.join(dir, 'Pattern.digipat')
session.load_pattern(pattern_filename)

print('Start bursting pattern')
try:
session.burst_pattern(start_label='new_pattern')
finally:
session.selected_function = nidigital.SelectedFunction.DISCONNECT
print('Done bursting pattern')


def _main(argsv):
parser = argparse.ArgumentParser(description='Demonstrates how to create a pin map file, load levels and timing, and burst a pattern on the digital pattern instrument.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-n', '--resource-name', default='PXI1Slot2,PXI1Slot3', help='The specified resource name of a digital pattern instrument, for example, PXI1Slot3, where PXI1Slot3 is an instrument resource name. This example requires two distinct instrument resource names in site order.')
parser.add_argument('-s', '--simulate', default='True', choices=['True', 'False'], help='Whether to run on simulated hardware or real hardware')
args = parser.parse_args(argsv)
example(args.resource_name, 'Simulate=1, DriverSetup=Model:6571' if args.simulate == 'True' else '')


def main():
_main(sys.argv[1:])


def test_example():
resource_name = 'PXI1Slot2,PXI1Slot3'
options = {'simulate': True, 'driver_setup': {'Model': '6571'}, }
example(resource_name, options)


def test_main():
_main([])
_main(['--resource-name', 'PXI1Slot4,PXI1Slot5', '--simulate', 'True'])


if __name__ == '__main__':
main()
Loading