[Tutor] Connecting Py 2.7 with visa
Mark Lawrence
breamoreboy at yahoo.co.uk
Sat May 16 04:14:55 CEST 2015
On 15/05/2015 23:12, Wilson, Pete wrote:
> Greetings I am trying to write a test executive program using python 2.7 on a windows 7 computer. I want to connect to a Keithley 2100 voltmeter using National Instruments VISA. I am having trouble installing pyvisa. All the documentation refers to using 'pip' and a command line "$ pip install pyvisa" . What interface or console is this? "$" prompt looks like a Linux command line. How do we do this with windows?
>
It's a Windows command line prompt. You can get this by hitting the
Windows logo key with 'R' and then entering cmd<return>. However the
simplest way for you I think is to download this
https://sites.google.com/site/pydatalog/python/pip-for-windows
> Do I have to do this? Or can I use the native visa module in Python 2.7? Using the help() and dir() features I can get some basic information about visa, but the functions have changed, like visa.ResourceManager.open_resource is not working. I really liked this function... Are there any examples of how to use this new visa? I have some working code below that uses pyvisa, can it be converted?
>
Please help us to help you. Stating "is not working" is less than
useless, please show us exactly what happens. Cut and paste any output,
don't rely on typing it as this often results in further errors that
just confuse the issue.
> def update_current():
> import visa
>
> rm = visa.ResourceManager()
> rm.list_resources()
>
> current_1_ma = ""
> exe_check = "PASS"
>
> try:
> dut_data = open("dut_data.txt", "w")
> except:
> exe_check = "FAIL"
Don't use bare excepts as it's asking for trouble. Much better to leave
out the error handling to start with and just let your programming
errors bubble up as stack traces. Then add in appropriate things to
catch. In the above FileNotFoundError amongst others seems suitable.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Tutor
mailing list