17 Replies Latest reply on Aug 27, 2019 6:37 PM by angellxp

    Py-Visa

    angellxp

      Should Py-Visa be usable as is on a BBB?  I'll be attempting to install it tonight.

        • Re: Py-Visa
          lui_gough

          I suspect it should be usable on most platforms which have access to Python. By default, PyVISA relies on the National Instruments VISA installation if it is available, but can also fallback to using pyvisa-py which is implemented in pure Python. See https://pyvisa.readthedocs.io/en/master/configuring.html

           

          - Gough

          4 of 4 people found this helpful
            • Re: Py-Visa
              angellxp

              I now have PyVisa and PyVisa-Py installed.  are there any other things I should consider installing for my instrument control?  I will have limited network access to this BBB so I'd like to do it in one go.

               

              Thanks

                • Re: Py-Visa
                  lui_gough

                  It really depends what you want to do ...

                   

                  In the instance that you're setting something up with limited access, I think it's probably best to first prototype or design the whole set-up first and get it working before "locking it down" or even migrating to a more "limited" platform such as an SBC. Defining your project aims/goals/functions/deliverables is vitally important if you ever want to "finish" the project. You could (in theory) smatter a few packages which might be useful (e.g. an editor of sorts, maybe a version control system, some remote access abilities on a protocol you'd like, perhaps an HTTP or SMB file-sharing if necessary), but installing too many bloats your installation, slows down upgrades in the future and potentially opens security holes in bugs, exploits or misconfiguration.

                   

                  As a result, I'd probably suggest you have a good hard think of what you'd want to do, actually make something working on something less restrictive and then port that over knowing exactly your dependencies as it varies from project to project and also depending on how you choose to code your project and the libraries you choose to use.

                   

                  - Gough

                  3 of 3 people found this helpful
              • Re: Py-Visa
                angellxp

                When I try to load the following into cloud9, I get the following error.  How do I get the dang module to load?

                 

                # Import libraries
                import visa
                import os
                import time
                
                
                # Open a VISA resource manager pointing to the installation folder for the Keysight Visa libraries. 
                rm = visa.ResourceManager() 
                  
                # ALTER LINE BELOW - Update the VISA resource string to match your specific VNA
                myFF = rm.open_resource("TCPIP0::192.168.7.20::inst0::INSTR") 
                myFF.write(':FORMat:DATA %s,%d' % ('ASCii', 0))  
                

                 

                 

                Traceback (most recent call last):
                  File "/var/lib/cloud9/PILOT_Test/FFtransfer.py", line 8, in <module>
                    import visa
                ImportError: No module named visa
                
                  • Re: Py-Visa
                    lui_gough

                    This implies your Python installation doesn't have pyvisa installed because it fails in import visa.Try installing it again?

                    • pip install -U pyvisa
                    • pip install -U pyvisa-py

                     

                    - Gough

                      • Re: Py-Visa
                        angellxp

                        Trying to log in from either the serial connection or the terminal on the BBB desktop, It errors saying pip is not valid/installed

                          • Re: Py-Visa
                            lui_gough

                            Then its likely you have a very outdated version of Python. Try updating all the packages on your OS. If not, perhaps you can install pip - https://www.makeuseof.com/tag/install-pip-for-python/

                            1 of 1 people found this helpful
                              • Re: Py-Visa
                                angellxp

                                I am typing these commands directly into my BBB...  I am using the latest BBB image to boot from

                                  • Re: Py-Visa
                                    lui_gough

                                    The latest image doesn't necessarily mean it has the latest packages installed. Likewise, I don't use BBB at present, but its easier to update packages and install pip as I mentioned above. I don't know but I suspect BBB uses pacman instead of apt.

                                     

                                    - Gough

                                    1 of 1 people found this helpful
                                      • Re: Py-Visa
                                        mp2100

                                        The BBB does use apt, not pacman.  JonA says he's using "latest" images, so it will be debian, which uses apt.  Gough's link to make-use-of has clear instructions for installation and updating, just in case pip is an old version.

                                         

                                        I just did a:

                                        $ sudo apt-get install python3-pip

                                         

                                        on my debian (ubuntu) laptop, and the version command returns this:

                                         

                                        t440-ubuntu:~$ pip3 --version

                                        pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

                                         

                                        JonA, did you check/confirm whether you're using python 2 (2.7), or python 3.x?  After the above, I installed python-pip (pip2) and get the following:

                                        t440-ubuntu:~$ pip --version

                                        pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

                                        2 of 2 people found this helpful
                                          • Re: Py-Visa
                                            angellxp

                                            Is there a universal command to update all?

                                             

                                              • Re: Py-Visa
                                                lui_gough

                                                It looks like you don't have python-pip installed but you do have python3-pip installed. If you're intending to use Python 3, then you can use that.

                                                 

                                                I didn't realize BBB is Debian based, this makes it veryvsimilarsto the RPi.

                                                 

                                                 

                                                I'd suggest you do something like:

                                                sudo apt-get update

                                                sudo apt-get upgrade

                                                sudo apt-get install python-pip

                                                 

                                                Then run the pip commands as listed before to install pyvisa.

                                                 

                                                - Gough

                                                2 of 2 people found this helpful
                                                  • Re: Py-Visa
                                                    angellxp

                                                    I personally don't care which python I use.  The code was originally coded in py2.7 apparently as that is what is on my PC.

                                                     

                                                    I just need to get the BBB to load my code and at present it is not loading/recognizing my visa module.

                                                     

                                                    1 of 1 people found this helpful
                                                      • Re: Py-Visa
                                                        lui_gough

                                                        You may not care, but the computer might! There are subtle differences in the syntax between Python 2.x and 3.x which means they are not always interchangeable. The most glaring example is print - in 2.x, you could write print 'Hello', whereas 3.x requires print('Hello').

                                                         

                                                        If your code is not impacted by the changes, you could try installing pyvisa on Python 3.x with pip3 rather than pip and run python3 scriptname.py rather than python scriptname.py

                                                         

                                                        Regardless, did you run the commands in the last post that I suggested? That should upgrade all packages and install pip for Python 2.x so you can then run the commands to install pyvisa for Python 2.x as well.

                                                         

                                                        - Gough

                                                        1 of 1 people found this helpful
                                                        • Re: Py-Visa
                                                          angellxp

                                                          Agreed.  I know there are definitely differences.  What I mean is that I'll code it either way, I just want it to work... 

                                                           

                                                          It is not the PC I have issues with, the code runs fine on the PC but I cannot get it to load on the BBB.  The visa module is the only error it throws when I try to run/compile it.

                                                            • Re: Py-Visa
                                                              lui_gough

                                                              I understand what you are saying, but the root of your issue is that your BBB environment doesn't match that of your development PC.

                                                               

                                                              By way of analogy, imagine if you wrote a text in English (your Python program that depends on pyvisa) and gave it to a friend next door (a Python interpreter on your PC) to read. As they can understand English (the pyvisa package is installed), this is no problem. Send the same text to a friend (another Python interpreter on your BBB) who is a native Chinese in China (does not have the pyvisa package installed yet) and they won't understand (program won't run as dependency is not met). They need to learn English (install the pyvisa package on the BBB), but in order to do that, they need to go to school (consult a package manager - pip). But their rural town has no school, so they must build one first (install pip from the OS package repository on the BBB).

                                                               

                                                              Your BBB doesn't have pip installed so you can install pyvisa on the BBB. You can't just migrate your python script between environments and expect them to work unless all dependent modules are installed.

                                                               

                                                              So as I said before and I will reiterate - update your packages on the BBB, install python2-pip package to get pip functionality, then use pip to install pyvisa on the BBB. If you get errors doing this, post them as that is the easiest way to help diagnose your issue.

                                                               

                                                              - Gough

                                                              3 of 3 people found this helpful
                                        • Re: Py-Visa
                                          angellxp

                                          It has been a long road but I finally have everything working.  VERY long story short, I now have python3 updated and running with visa, pyvisa, and pyvisa-py all properly installed and up to date.  Everything is running from the BBB now with no laptop interaction required.  There is still room for improvement but were not there yet... 

                                          Thanks for all the help.


                                          1 of 1 people found this helpful