aboutsummaryrefslogtreecommitdiff
path: root/lockin.py
blob: 0f54e79165c0ecf0842535147b35c6d0423ddd11 (plain)
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
"""
provide basic class to operate Lock-in
"""

import pyvisa

class SCPIinstr:
    """ Basic class which support SCPI commands """
    """     
    Do not instantiate directly, use
    rm = pyvisa.ResourceManager()
    SCPIinstr(rm.open_resource('TCPIP::192.168.0.2::INSTR'))
    """
    def __init__(self, resource):
        self.resource = resource
        
        # convenience pyvisa functions
        self.write = self.resource.write
        self.read = self.resource.read
        self.query = self.resource.query
        self.query_values = self.resource.query_values

    @property
    def idn(self):
        return self.query("*IDN?")

    def clear_status(self):
        self.write("*CLS")

    def set_event_status_enable(self):
        self.write("*ESE")
    
    def query_event_status_enable(self):
        self.query("*ESE?")

    def query_event_status_register(self):
        self.query("*ESR?")

    def set_wait_until_finished(self):
        self.query("*OPC")

    def wait_until_finished(self):
        self.query("*OPC?")

    def reset(self):
        self.write("*RST")
    
    def set_service_request_enable(self):
        self.write("*SRE")

    def query_service_request_enable(self):
        self.query("*SRE?")

    def query_status_byte(self):
        self.query("*STB?")
    
    def self_test_result(self):
        self.query("*TST?")
    
    def wait(self):
        self.write("*WAI")


class LockIn(SCPIinstr):
    """     
    Do not instantiate directly, use
    rm = pyvisa.ResourceManager()
    LockIn(rm.open_resource('TCPIP::192.168.0.2::INSTR'))
    """
    def __init__(self, resource):
        super().__init__(self, resource)
        

if __name__ == '__main__': 
    print("testing")
    rm = pyvisa.ResourceManager()
    print(rm.list_resources())    
    instr=rm.open_resource('TCPIP::192.168.0.51::INSTR')
    lckn = LockIn(instr)
    # lckn = LockIn(rm, 'TCPIP::192.168.0.51::INSTR')
    print(lckn.query('*idn?'))