Commit 8a48e593 authored by Simon Sebastian Humpohl's avatar Simon Sebastian Humpohl
Browse files

-applied 2to3

-setup script
-detect pyvisa>1.6
parent e6849053
from distutils.core import setup
setup(
name='pyte',
version='',
packages=['pyte'],
package_dir={'pyte': 'src'},
url='',
license='',
author='Tabor electronics',
author_email='',
description='',
install_requires=['numpy', 'pyvisa']
)
from pyvisa import __version__ as pyvisa_version
from distutils.version import StrictVersion
if StrictVersion(pyvisa_version) >= StrictVersion('1.6'):
from .pyte16 import *
__all__ = pyte16.__all__
else:
raise ImportError('Unsopported pyvisa version: {} (should be an "easy" fix)'.format(pyvisa_version))
......@@ -7,9 +7,14 @@ import struct
import math
import warnings
import numpy as np
import visa
from pyvisa import ResourceManager
import pyvisa.constants as vc
#from pyvisa.errors import (VisaIOError, VisaIOWarning)
__all__ = ['open_session', 'prompt_msg','make_bin_dat_header', 'get_visa_err_desc', 'write_raw_string',
'write_raw_bin_dat', 'send_cmd', 'build_sine_wave', 'build_triangle_wave', 'build_square_wave',
'download_binary_data', 'download_binary_file', 'download_arbcon_wav_file', 'download_segment_lengths',
'download_sequencer_table', 'download_adv_seq_table', 'download_fast_pattern_table',
'download_linear_pattern_table', 'make_combined_wave']
def _list_udp_awg_instruments():
'''
......@@ -90,7 +95,7 @@ def _select_visa_rsc_name(rsc_manager=None, title=None, interface_name=None):
"""
if rsc_manager is None:
rsc_manager = visa.ResourceManager()
rsc_manager = ResourceManager()
selected_rsc_name = None
......@@ -113,34 +118,34 @@ def _select_visa_rsc_name(rsc_manager=None, title=None, interface_name=None):
choice = intf_nb
else:
if title is not None:
print
print title
print '=' * len(title)
print
print "Select VISA Interface type:"
print " 1. TCPIP"
print " 2. USB"
print " 3. GPIB"
print " 4. VXI"
print " 5. ASRL"
print " 6. LXI"
print " 7. Enter VISA Resource-Name"
print " 8. Quit"
print()
print(title)
print('=' * len(title))
print()
print("Select VISA Interface type:")
print(" 1. TCPIP")
print(" 2. USB")
print(" 3. GPIB")
print(" 4. VXI")
print(" 5. ASRL")
print(" 6. LXI")
print(" 7. Enter VISA Resource-Name")
print(" 8. Quit")
choice = prompt_msg("Please enter your choice [1:7]: ", "123467")
try:
choice = int(choice)
except:
choice = -1
print
print()
if choice == 1:
print
print()
ip_str = prompt_msg("Enter IP-Address, or press[Enter] to search: ",)
print
print()
if len(ip_str) == 0:
print 'Searching AWG-Instruments ... '
print('Searching AWG-Instruments ... ')
rsc_names, rsc_descs = _list_udp_awg_instruments()
print
print()
else:
try:
packed_ip = socket.inet_aton(ip_str)
......@@ -148,9 +153,9 @@ def _select_visa_rsc_name(rsc_manager=None, title=None, interface_name=None):
selected_rsc_name = "TCPIP::{0}::5025::SOCKET".format(ip_str)
break
except:
print
print "Invalid IP-Address"
print
print()
print("Invalid IP-Address")
print()
continue
elif choice == 2:
rsc_names = rsc_manager.list_resources(query="?*USB?*INSTR")
......@@ -167,22 +172,22 @@ def _select_visa_rsc_name(rsc_manager=None, title=None, interface_name=None):
break
elif choice == 7:
resource_name = prompt_msg('Please enter VISA Resurce-Name: ')
print
print()
if len(resource_name) > 0:
selected_rsc_name = resource_name
break
elif choice == 8:
break
else:
print
print "Invalid choice"
print
print()
print("Invalid choice")
print()
continue
num_rscs = len(rsc_names)
if num_rscs == 0:
print
print 'No VISA Resource was found!'
print()
print('No VISA Resource was found!')
yes_no = prompt_msg("Do you want to retry [y/n]: ", "yYnN")
if yes_no in "yY":
continue
......@@ -195,7 +200,7 @@ def _select_visa_rsc_name(rsc_manager=None, title=None, interface_name=None):
if len(rsc_descs) != num_rscs:
rsc_descs = ["" for n in range(num_rscs)]
# get resources descriptions:
for n, name in zip(range(num_rscs), rsc_names):
for n, name in zip(list(range(num_rscs)), rsc_names):
vi = None
try:
vi =rsc_manager.open_resource(name)
......@@ -212,10 +217,10 @@ def _select_visa_rsc_name(rsc_manager=None, title=None, interface_name=None):
except:
pass
print "Please choose one of the available devices:"
for n, name, desc in zip(range(num_rscs), rsc_names, rsc_descs):
print " {0:d}. {1} ({2})".format(n+1, desc, name)
print " {0:d}. Back to main menu".format(num_rscs+1)
print("Please choose one of the available devices:")
for n, name, desc in zip(list(range(num_rscs)), rsc_names, rsc_descs):
print(" {0:d}. {1} ({2})".format(n+1, desc, name))
print(" {0:d}. Back to main menu".format(num_rscs+1))
msg = "Please enter your choice [{0:d}:{1:d}]: ".format(1, num_rscs+1)
valid_answers = [str(i+1) for i in range(num_rscs+1)]
choice = prompt_msg(msg, valid_answers)
......@@ -298,7 +303,7 @@ def open_session(resource_name = None, title_msg = None, vi_rsc_mgr = None, extr
try:
if vi_rsc_mgr is None:
vi_rsc_mgr = visa.ResourceManager()
vi_rsc_mgr = ResourceManager()
if resource_name is None:
resource_name = _select_visa_rsc_name(vi_rsc_mgr, title_msg)
......@@ -320,18 +325,18 @@ def open_session(resource_name = None, title_msg = None, vi_rsc_mgr = None, extr
if extra_init and vi is not None:
_init_vi_inst(vi)
except:
print 'Failed to open "{0}"\n{1}'.format(resource_name, sys.exc_info())
print('Failed to open "{0}"\n{1}'.format(resource_name, sys.exc_info()))
return vi
def prompt_msg(msg, valid_answers = None):
"""Prompt message and return user's answer."""
ans = raw_input(msg)
ans = input(msg)
if valid_answers is not None:
count = 0
while ans not in valid_answers:
count += 1
ans = raw_input(msg)
ans = input(msg)
if count == 5:
break;
return ans
......@@ -374,7 +379,7 @@ def write_raw_string(vi, wr_str):
'''
ret_count = 0
count = 0L
count = 0
try:
ret_count = len(wr_str)
p_dat = ctypes.cast(wr_str, ctypes.POINTER(ctypes.c_byte))
......@@ -409,7 +414,7 @@ def write_raw_bin_dat(vi, bin_dat, dat_size, max_chunk_size = 1024):
ret_count = 0
err_code = 0
wr_offs = 0
count = 0L
count = 0
try:
if isinstance(bin_dat, np.ndarray):
p_dat = bin_dat.ctypes.data_as(ctypes.POINTER(ctypes.c_byte))
......@@ -843,7 +848,7 @@ def download_sequencer_table(vi, seq_table, pref=':SEQ:DATA', paranoia_level=1):
m = np.empty(s_size * tbl_len, dtype='uint8')
for n in range(tbl_len):
repeats, seg_nb, jump_flag = seq_table[n]
s.pack_into(m, n * s_size, long(repeats), int(seg_nb), int(jump_flag))
s.pack_into(m, n * s_size, int(repeats), int(seg_nb), int(jump_flag))
return download_binary_data(vi, pref, m, m.nbytes, paranoia_level=paranoia_level)
......@@ -876,7 +881,7 @@ def download_adv_seq_table(vi, adv_seq_table, pref=':ASEQ:DATA', paranoia_level=
m = np.empty(s_size * tbl_len, dtype='uint8')
for n in range(tbl_len):
repeats, seq_nb, jump_flag = adv_seq_table[n]
s.pack_into(m, n * s_size, long(repeats), int(seq_nb), int(jump_flag))
s.pack_into(m, n * s_size, int(repeats), int(seq_nb), int(jump_flag))
return download_binary_data(vi, pref, m, m.nbytes, paranoia_level=paranoia_level)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment