whitequark / kicad-boardview

KiCAD to Boardview exporter reads KiCAD PCB layout files and writes ASCII Boardview files
BSD Zero Clause License
152 stars 23 forks source link

Generate `.obdata` file for use with FlexBV #16

Closed sabogalc closed 7 months ago

sabogalc commented 8 months ago

I updated the script to also output a .obdata file that shows component values in FlexBV. You can read more about the OpenBoardData Project below: https://openboarddata.org/

This saves me from having to jump between the boardview and schematic, and per the OpenBoardData GitHub page, Paul Daniels's fork of OpenBoardView is compatible with these files. Screenshot 2024-03-09 074103 Screenshot 2024-03-09 074236

whitequark commented 8 months ago

So looking more at openboarddata.org, I see:

Currently four (4) types of data being stored;

  • Diode values of nets
  • Resistance values of nets
  • Voltage values of nets
  • Diagnostic solutions

I don't think any of these include component values? Am I missing anything?

sabogalc commented 8 months ago

So looking more at openboarddata.org, I see:

Currently four (4) types of data being stored;

  • Diode values of nets
  • Resistance values of nets
  • Voltage values of nets
  • Diagnostic solutions

I don't think any of these include component values? Am I missing anything?

I omitted them because they would vary from board to board. The only ones I could think could be pulled from the .kicad_pcb file would be the resistance and voltage net values, but even then I would want to measure a real board I have to make sure. As for the diode mode readings, they are very common and useful in electronics repair, but essentially they need to be found out manually by probing the board.

UPDATE - I misunderstood your question. Yes I agree with you, I think the documentation is lacking in pointing out that component values are also viewable with .obdata, that or we both can't find it, but I feel like it should be front and center just like the other features.

whitequark commented 8 months ago

Yes, I realize this. What I'm confused about is that the list at openboarddata.org does not include component values at all. Is there a file format specification somewhere?

sabogalc commented 8 months ago

Is there a file format specification somewhere?

This is a great question, I'll ping the dev of .obdata for an answer on this @inflex.

In the meantime, I can give an example of a .obdata file for a MacBook found at the following link: https://openboarddata.org/?a=showboardsolutions&bpath=laptops/apple/820-01700

There is a section labeled "Component values" that has all of the same kinds of things I included in the .obdata files that I am generating with the updated script.

whitequark commented 8 months ago

Cool, I'll leave this PR open while we sort out the docs/format question.

inflex commented 8 months ago

Morning folks, my bad for not having kept the OBData file format specifications up to date.

Yes, component values / notes are in some OBData file though not all of course, only because it's a community generated database and as such does tend to have some holes in it.

Fundamentally, with component data, the section starts with COMPONENTS_DATA_START and each line represents one data item.

The only 'tricky' one is the status, when it's set to '-' it means the component is a no-stuff.

COMPONENTS_DATA_START
### Component Category Value Comment
### v = value, p = package, c = manufacturer code, r = rating, m = misc, s = status
###
C0890 r 6.3V
C0890 v 1UF
C0891 r 10V
C0891 v 0.1UF
C0892 r 10V
C0892 v 0.1UF
C0895 r 10V
C0895 v 0.1UF
C0899 r 6.3V
C0899 v 1UF
C1000 p 0402
C1000 r 4V
C1000 v 10UF
C1001 r 4V
C1001 v 10UF
C1002 r 4V
C1002 v 10UF
C1003 r 4V
C1003 s -
C1003 v 10UF
sabogalc commented 8 months ago

Thank you very much for your response. I have two questions about the different component properties, however.

  1. Would there ever be a case where s is anything other than -?
  2. What would an example of the manufacturer code flag be? Would this be for custom components like a CPU?
inflex commented 8 months ago

@sabogalc Currently nothing other than '-' has been defined for 's'. Manufacturer code most often would likely be left blank but the provision is there in case the MFG code is notably different to the typical part code (ie, you might have a 0805 10uF 6V3 X5R cap and the mfg code is (Kemet) C0805C106M9PACTU

For chips usually the MFG code would be redundant in many cases, ie, ISL6259 might be ISL6259HRZ, as such doesn't really get utilised much in that respect.

Certainly the data isn't intended to be pedantically correct; for the most part people are usually just going to be after value, package and maybe rating.

I added it because it does make it a bit quicker when working with the boardviews to have the data shown on one screen rather than having to search over on the schematic.

sabogalc commented 7 months ago

Quick question - if this PR gets merged should anything about it be included in the README?

whitequark commented 7 months ago

Quick question - if this PR gets merged should anything about it be included in the README?

I guess so--maybe a third paragraph briefly mentioning that FlexBV data files can also be written.

inflex commented 7 months ago

I thought also what might be an idea is that I can upload these obdata files directly to the openboarddata.org server, or, people can rename/copy the file to .obdq (in flexbv) and it'll then hopefully show up as a "data items ready to upload to server" block on the right-hand-side; assuming the logic board is present in the current OpenBoardData.org database

( I need to make it easier for people to submit new boards)

whitequark commented 7 months ago

@inflex If you'd like me to assist in integrating this project with your commercial product FlexBV please email me directly at whitequark@whitequark.org to discuss it.

sabogalc commented 7 months ago

@inflex I saw that you were listed as a member of OpenBoardView in their repo. Would it be possible to add OpenBoardData support to the main branch of OpenBoardView, or is it meant to stay as a feature of FlexBV?

sabogalc commented 7 months ago

Quick question - if this PR gets merged should anything about it be included in the README?

I guess so--maybe a third paragraph briefly mentioning that FlexBV data files can also be written.

Okay, I updated the README pretty extensively so please let me know if it's okay or if I should change it.

Update - I also tried running this script via CLI, but I was unsuccessful even trying to generate a .brd file and I received

Traceback (most recent call last):
  File "C:\Program Files\KiCad\8.0\share\kicad\scripting\plugins\pcbnew2boardview.py", line 7, in <module>
    import pcbnew
ModuleNotFoundError: No module named 'pcbnew'

As such, I could not update my README with instructions on how to generate the .obdata file via CLI.

sabogalc commented 7 months ago

Should this PR include an example.obdata file for Glasgow, or should it remain omitted to emphasize that the OpenBoardData file generation is optional?

whitequark commented 7 months ago

Should this PR include an example.obdata file for Glasgow, or should it remain omitted to emphasize that the OpenBoardData file generation is optional?

Happy to leave example.obdata in.

sabogalc commented 7 months ago

Should this PR include an example.obdata file for Glasgow, or should it remain omitted to emphasize that the OpenBoardData file generation is optional?

Happy to leave example.obdata in.

Okay! I think this PR is all good to go now but please let me know if there is anything else that should be taken care of.

sabogalc commented 7 months ago

Unfortunately I need a bit of guidance on how to use it in the command line, the last time I tried to the best of my ability was here and I was not successful.

Quick question - if this PR gets merged should anything about it be included in the README?

I guess so--maybe a third paragraph briefly mentioning that FlexBV data files can also be written.

Okay, I updated the README pretty extensively so please let me know if it's okay or if I should change it.

Update - I also tried running this script via CLI, but I was unsuccessful even trying to generate a .brd file and I received

Traceback (most recent call last):
  File "C:\Program Files\KiCad\8.0\share\kicad\scripting\plugins\pcbnew2boardview.py", line 7, in <module>
    import pcbnew
ModuleNotFoundError: No module named 'pcbnew'

As such, I could not update my README with instructions on how to generate the .obdata file via CLI.

sabogalc commented 7 months ago

I tried the command-line tool and got a different error this time.

  File "C:\Program Files\KiCad\8.0\share\kicad\scripting\plugins\pcbnew2boardview.py", line 155
    obdata.write(f"{ref} p {package}\n")
                                      ^
SyntaxError: invalid syntax

I commented these lines out, and once again received

Traceback (most recent call last):
  File "C:\Program Files\KiCad\8.0\share\kicad\scripting\plugins\pcbnew2boardview.py", line 7, in <module>
    import pcbnew
ImportError: No module named pcbnew

I will try the command on Linux to see if I get the same issues there.

whitequark commented 7 months ago

I tried the command-line tool and got a different error this time.

That looks like your Python is too old to support f-strings (f"..." syntax). You need at least Python 3.6 (which is ancient by this point...)

sabogalc commented 7 months ago

I tried the command-line tool and got a different error this time.

That looks like your Python is too old to support f-strings (f"..." syntax). You need at least Python 3.6 (which is ancient by this point...)

That would be right, I ran the command on a computer that isn't my usual one and it is purposefully kept on Python 2.7.12 due to https://stackoverflow.com/questions/43728431/relative-imports-modulenotfounderror-no-module-named-x. However, the "No module named pcbnew" happens across both computers so I'm still not sure what's wrong there (e.g. if I have to set the plugins path as a System path or something). When I try the command on Linux I will post my results here.

sabogalc commented 7 months ago

Edit - I realized I never specified my software versions. I am running Pop!_OS 22.04 LTS and KiCad 8.0.1

I got to trying the plugin on Linux. My first headache was that I have KiCad installed as a Flatpak so my plugin directory was super crazy - /home/user/.local/share/flatpak/app/org.kicad.KiCad/x86_64/stable/4340fad084d4a35accae84a567b8e3d84e4c2df5b493e3e701678251b2873259/files/share/kicad/scripting/plugins/ However, after putting the .py files there, I was able to run the script successfully through Tools > External Plugins in the PCB Editor.

Unfortunately, the CLI still wasn't working for me in Linux. I first tried the command as is and received

bash: ./pcbnew2boardview.py: Permission denied

so then I tried adding sudo to the front of the command and received

[sudo] password for user: 
sudo: ./pcbnew2boardview.py: command not found

At this point, I'm just assuming I'm doing something wrong, but I'm not sure what. I open a command line window at the directory of the Python files (with an example folder in it containing the PCB), and then I run the exact

./pcbnew2boardview.py example/example.kicad_pcb example/example.brd

command. Am I supposed to be doing this a different way?

whitequark commented 7 months ago
bash: ./pcbnew2boardview.py: Permission denied

That means the file is not executable. It's marked executable in the git repository, so if you didn't check out the repository but downloaded it from GitHub, you should chmod +x pcbnew2boardview.py it.

sabogalc commented 7 months ago

Thank you for that. I re-ran the script on Linux after running chmod +x pcbnew2boardview.py, but now I get

Traceback (most recent call last):
  File "/home/user/Downloads/kicad-boardview-main/./pcbnew2boardview.py", line 7, in <module>
    import pcbnew
ModuleNotFoundError: No module named 'pcbnew'

am I supposed to be placing this folder in a certain directory that is within KiCad's installation directory?

Update - Running it in the plugins directory also resulted in

Traceback (most recent call last):
  File "/home/user/.local/share/flatpak/app/org.kicad.KiCad/x86_64/stable/4340fad084d4a35accae84a567b8e3d84e4c2df5b493e3e701678251b2873259/files/share/kicad/scripting/plugins/./pcbnew2boardview.py", line 7, in <module>
    import pcbnew
ModuleNotFoundError: No module named 'pcbnew'

Further update - The error I am experiencing is similar to the original Python 2/Python 3 error I linked to, https://stackoverflow.com/questions/43728431/relative-imports-modulenotfounderror-no-module-named-x. Was this script originally written with Python 2?

whitequark commented 7 months ago

Was this script originally written with Python 2?

I don't remember.

am I supposed to be placing this folder in a certain directory that is within KiCad's installation directory?

You need to have KiCad on your PYTHONPATH. I don't remember exactly how to do this; consult KiCad's documentation please.

sabogalc commented 7 months ago

Alright I'm really at the point where I have no idea what I'm doing.

I found this KiCad forum post where someone facing a similar problem says they manually edited the PYTHONPATH in a .bashrc file, but I don't really know what that means. They did however mention that they were using the KiCad Scripting Console and not the Terminal like I was doing, so I tried that too. Unfortunately I could not get that working either (since I assume that's not how this script was originally intended to behave). image At this point, this PR can't be merged if I can't prove that the CLI version still runs as it did before, and I can't figure out how to do so. As such, I am okay with closing this PR and reopening it should I ever figure it out.

whitequark commented 7 months ago

I'm happy to keep it open in the meantime. Right now I'm extremely busy with other things and I haven't even opened KiCad in years, but if I ever find time for it I'll test it on my machine. It's in a good enough state for that.

The reason I asked you to test it is because if you can test it, then it'll get merged say "tomorrow" instead of "whenever I get around to it", not as a conceited way to reject it or something.

whitequark commented 7 months ago

Although, because you've used the branch main to submit your PR from, this means that if you add more changes to main this PR will become corrupted. (I'm guessing you haven't used Git/GitHub much before?)

whitequark commented 7 months ago

It looks like the last commit that's supposed to be in the PR is https://github.com/whitequark/kicad-boardview/tree/6b4258806caf1b45a909a03092cd1b60d86af49f, so that can be checked out for testing.

sabogalc commented 7 months ago

(I'm guessing you haven't used Git/GitHub much before?)

That would be correct, what I just spent the last half hour doing was trying to make my branch equivalent to the parent one using revert and such, but I was not successful. I should've read all this first.

whitequark commented 7 months ago

That destroyed the PR, I think (it can't be reopened anymore).

sabogalc commented 7 months ago

That destroyed the PR, I think (it can't be reopened anymore).

I'm really sorry for the mess. This PR is now twofold in fixing pad_sort_key as well since the code doesn't actually work as intended (I apologize for not doing full due diligence in testing the code change). You can see my comment on that here.

whitequark commented 7 months ago

I'm really sorry for the mess. This PR is now twofold in fixing pad_sort_key as well since the code doesn't actually work as intended

I won't merge this. I've been using "Squash and merge" because you spread changes over a very large number of commits with largely meaningless commit messages. My projects use one commit per logical change, and this way I would have to check the repo out myself, spend time grouping your changes, etc.