Discussion:
[Tutor] Connecting Py 2.7 with visa
Wilson, Pete
2015-05-15 22:12:35 UTC
Permalink
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?

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?

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"

try:
ki2100 = rm.open_resource('USB0::0x05E6::0x2100::1148525::INSTR')
device_id = ki2100.query("*IDN?")
except:
exe_check = "FAIL"

try:
dut_current_amps = (float(ki2100.query("MEASure:CURRent:DC?")))
dut_current_ma = dut_current_amps * 1000.0
current_1_ma = "%6G" % dut_current_ma
except:
exe_check = "FAIL"

new_line = "Litepoint_Data_Format" + "\r\n"
dut_data.write(new_line)
new_line = "CURRENT_1_MA=" + current_1_ma + "\r\n"
dut_data.write(new_line)
new_line = "EXE_CHECK=" + exe_check + "\r\n"
dut_data.write(new_line)

dut_data.close()

return


if __name__ == "__main__":

update_current()

print "Dumping dut_data.txt"

with open('dut_data.txt') as dut_data:

for line in dut_data:
print line,
if 'str' in line:
break

dut_data.close()

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Mark Lawrence
2015-05-16 02:14:55 UTC
Permalink
Post by Wilson, Pete
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
Post by Wilson, Pete
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.
Post by Wilson, Pete
import visa
rm = visa.ResourceManager()
rm.list_resources()
current_1_ma = ""
exe_check = "PASS"
dut_data = open("dut_data.txt", "w")
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

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Wilson, Pete
2015-05-19 05:25:48 UTC
Permalink
Pip-for-windows worked great! Bob's your uncle! Case closed.

Pete
-----Original Message-----
Behalf Of Mark Lawrence
Sent: Friday, May 15, 2015 7:15 PM
Subject: Re: [Tutor] Connecting Py 2.7 with visa
Post by Wilson, Pete
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
Post by Wilson, Pete
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.
Post by Wilson, Pete
import visa
rm = visa.ResourceManager()
rm.list_resources()
current_1_ma = ""
exe_check = "PASS"
dut_data = open("dut_data.txt", "w")
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
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Continue reading on narkive:
Loading...