-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtektronix_fca3103_drv.py
More file actions
123 lines (98 loc) · 4.23 KB
/
tektronix_fca3103_drv.py
File metadata and controls
123 lines (98 loc) · 4.23 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#! /usr/bin/env python3
# -*- coding: utf-8 -*
'''
Driver for the Tektronix FCA 3103 Timer/Counter/Analyzer
@file
@date Created on Apr. 20, 2015
@author Felipe Torres (torresfelipex1<AT>gmail.com)
@copyright LGPL v2.1
@ingroup measurement
'''
#------------------------------------------------------------------------------|
# GNU LESSER GENERAL PUBLIC LICENSE |
# ------------------------------------ |
# This source file is free software; you can redistribute it and/or modify it |
# under the terms of the GNU Lesser General Public License as published by the |
# Free Software Foundation; either version 2.1 of the License, or (at your |
# option) any later version. This source is distributed in the hope that it |
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warrant |
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
# General Public License for more details. You should have received a copy of |
# the GNU Lesser General Public License along with this source; if not, |
# download it from http://www.gnu.org/licenses/lgpl-2.1.html |
#------------------------------------------------------------------------------|
#-------------------------------------------------------------------------------
# Import --
#-------------------------------------------------------------------------------
# Import system modules
import time
# User modules
from gen_usbtmc import *
class FCA3103_drv() :
'''
Tektronix FCA 3103 driver.
'''
def __init__(self, port,full_support=False) :
'''
Constructor
Args:
port (int) : Port index of usbtmc device (from 0 to 16)
full_support (boolean) : Indicates if custom usbtmc driver is loaded
'''
self.driver = Gen_usbtmc(port,full_support)
if full_support :
devices = self.driver.listDevices()
lines = devices.splitlines()
self.manufacturer = lines[port].split('\t')[1]
self.device = lines[port].split('\t')[2]
self.serial = lines[port].split('\t')[3]
else :
info = self.query("*IDN?")
self.manufacturer = info.split(",")[0]
self.device = info.split(",")[1]
self.serial = info.split(",")[2]
# ------------------------------------------------------------------------ #
def deviceInfo(self) :
'''
Method to retrieve device information.
Returns:
A string with manufacturer, device name and serial number.
'''
return ("%s %s (s/n : %s)" % (self.manufacturer, self.device, self.serial))
# ------------------------------------------------------------------------ #
def query(self, cmd, length=100) :
'''
Method to write a command and read the result.
Args:
cmd (str) : A SCPI valid command for the device.
length (int) : Length of the input read. Default : 100.
Returns:
Command "cmd" response.
'''
self.driver.write(str.encode(cmd))
time.sleep(1)
ret = self.driver.read(length)[:-1]
return bytes.decode(ret)
# ------------------------------------------------------------------------ #
def read(self, length=1) :
'''
Method to read from output buffer of the instrument
Args:
length (int) : Number of bytes to read. Default : 1.
'''
ret = self.driver.read(length)[:-1]
return bytes.decode(ret)
# ------------------------------------------------------------------------ #
def write(self, cmd, check=False) :
'''
Method for writing to input buffer of the instrument.
Args:
cmd (str) : A SCPI valid command for the device.
check (boolean) : When true the driver will ask for errors in previous command.
Returns:
If check=True it returns a tuple (error code,error message).
'''
self.driver.write(str.encode(cmd))
time.sleep(1)
if check :
return self.query("syst:err?")