Repository navigation
Adding Create Pin Map Example in NI-Digital #2256
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
Closed
divakar-selvam07
wants to merge
12
commits into
ni:master
from
NI-velmurugan:users/diva/add-nidigital-create-pinmap-example
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4eb8624
Add @Avinash2Suresh as a code owner
NI-velmurugan 79d0b7e
Merge branch 'master' of https://github.com/NI-velmurugan/nimi-python
divakar-selvam07 8305ba2
Remove @Avinash2Suresh from CODEOWNERS
divakar-selvam07 edb1a2c
Merge branch 'master' of https://github.com/NI-velmurugan/nimi-python
divakar-selvam07 001e834
Merge branch 'master' of https://github.com/NI-velmurugan/nimi-python
divakar-selvam07 322f69f
Merge branch 'master' of https://github.com/NI-velmurugan/nimi-python
divakar-selvam07 a8f2416
Merge branch 'master' of https://github.com/NI-velmurugan/nimi-python
divakar-selvam07 9e9647f
Merge branch 'master' of https://github.com/NI-velmurugan/nimi-python
divakar-selvam07 3d7dbe2
Add Create Pin Map example in NI-Digital
divakar-selvam07 03c2504
removing self explainatory comments
divakar-selvam07 e48cf53
Update resource-name argument description
divakar-selvam07 c7a7563
Define system pins and pin connections in variables
divakar-selvam07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
src/nidigital/examples/create_pin_map/PinLevels.digilevels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
37
src/nidigital/examples/create_pin_map/create_pin_map.digiproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
107
src/nidigital/examples/create_pin_map/nidigital_create_pin_map.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): | ||
| 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') | ||
|
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() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.