-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisaSubs.py~
executable file
·49 lines (36 loc) · 1008 Bytes
/
VisaSubs.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Sub programs for communication using PyVisa
author : Eoin O'Farrell
email : phyoec@nus.edu.sg
last edited : July 2013
Functions written:
InitializeGPIB
InitialIzeSerial
"""
import visa as visa
# initalize GPIB devices using PyVisa
def InitializeGPIB(address, board, **kwargs):
try:
GPIBVisa = visa.GpibInstrument(address,board)
for kw in kwargs.keys():
tmp = "".join(("GPIBVisa.",kw,"=\"",kwargs[kw],"\""))
exec(tmp)
print GPIBVisa.ask("*IDN?")
except Exception:
print "Failed opening GPIB address %d\n" % address
GPIBVisa = None
return GPIBVisa
# initialize Serial devices using PyVisa
def InitializeSerial(name,idn="*IDN?", **kwargs):
try:
SerialVisa = visa.SerialInstrument(name)
for kw in kwargs.keys():
tmp = "".join(("SerialVisa.",kw,"=\"",kwargs[kw],"\""))
exec(tmp)
print SerialVisa.ask(idn)
except Exception:
print "Failed opening serial port %s\n" % name
SerialVisa = None
return SerialVisa