Hello,
I am looking for a function to get the pin name (from the Libpart and pin number)
I did not find such function in kicad_netlist_reader.py library.
Any clue to find additional plugin library or to build my own function?
Thanks
Sebastien
Hello,
I am looking for a function to get the pin name (from the Libpart and pin number)
I did not find such function in kicad_netlist_reader.py library.
Any clue to find additional plugin library or to build my own function?
Thanks
Sebastien
The netlist is XML and this is a format that allows arbitrary tags. So you have to write your own Python code to digest the XML netlist to extract the info you want. Looking at one of my netlists, here is a <libpart> element representing a 74HC595 chip:
<libpart lib="74xx" part="74HC595">
<description>8-bit serial in/out Shift Register 3-State Outputs</description>
<docs>http://www.ti.com/lit/ds/symlink/sn74hc595.pdf</docs>
<footprints>
<fp>DIP*W7.62mm*</fp>
<fp>SOIC*3.9x9.9mm*P1.27mm*</fp>
<fp>TSSOP*4.4x5mm*P0.65mm*</fp>
<fp>SOIC*5.3x10.2mm*P1.27mm*</fp>
<fp>SOIC*7.5x10.3mm*P1.27mm*</fp>
</footprints>
<fields>
<field name="Reference">U</field>
<field name="Value">74HC595</field>
<field name="Datasheet">http://www.ti.com/lit/ds/symlink/sn74hc595.pdf</field>
</fields>
<pins>
<pin num="1" name="QB" type="tri_state"/>
<pin num="2" name="QC" type="tri_state"/>
<pin num="3" name="QD" type="tri_state"/>
<pin num="4" name="QE" type="tri_state"/>
<pin num="5" name="QF" type="tri_state"/>
<pin num="6" name="QG" type="tri_state"/>
<pin num="7" name="QH" type="tri_state"/>
<pin num="8" name="GND" type="power_in"/>
<pin num="9" name="QH'" type="output"/>
<pin num="10" name="~{SRCLR}" type="input"/>
<pin num="11" name="SRCLK" type="input"/>
<pin num="12" name="RCLK" type="input"/>
<pin num="13" name="~{OE}" type="input"/>
<pin num="14" name="SER" type="input"/>
<pin num="15" name="QA" type="tri_state"/>
<pin num="16" name="VCC" type="power_in"/>
</pins>
</libpart>
So from the relevant <libpart> element you have to find the <pins> element inside and get the number/name associations from the attributes of <pin>. You might want to look at the documentation for the Python xml module.
Thanks for the help. I was wondering if some libraries already exist (something like a fct getPinName(self, pinNb) in the LibPart class. But for sure as you propose I can make my own implementation.
Do you know were I can find the “documentation for the Python xml module” I am not familiar with Kicad Python xml module development, until know I only copy piece of code and directly use kicad_netlist_reader helper functions with not so much real coding.
Sebastien
There are actually many modules for handling XML in Python. This is a rabbit hole in itself:
https://wiki.python.org/moin/PythonXml
I would pick a combination that will deserialise the XML file into a Python data structure, so that you can access arbitrary elements in the tree.
Try it outside of KiCad by dumping the netlist and processing it with your script before you attempt to call it inside KiCad. This will allow you to debug in the console or the IDE you use.
Thanks a lot for the tips.
Sebastien
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.