cc.scpi.generic_instrument
1import socket 2 3from cc.serializer import SocketSerializer 4 5class GenericInstrument: 6 """ 7 Generic instrument class. 8 """ 9 10 def __init__(self, ip_address, port=5025): 11 self._sock = None 12 self.ip_address = ip_address 13 self.port = port 14 15 def connect(self): 16 """ 17 Connect to the instrument. 18 """ 19 self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 20 21 addr = (self.ip_address, self.port) 22 try: 23 self._sock.connect(addr) 24 except socket.error as e: 25 print("failed to connect: ", addr) 26 print(e) 27 28 return self._sock 29 30 def close(self): 31 """ 32 Close the connection. 33 """ 34 self._sock.close() 35 36 def command(self, cmd: str): 37 """ 38 Send a command to the instrument. 39 40 Args: 41 cmd: the command to send 42 """ 43 ser = SocketSerializer(self._sock, buffered_transmit=True) 44 ser.transmit(cmd.encode()) 45 46 def query(self, cmd: str): 47 """ 48 Send a query to the instrument. 49 50 Args: 51 cmd: the command to send 52 53 Returns: 54 the response from the instrument 55 """ 56 ser = SocketSerializer(self._sock, buffered_transmit=True) 57 ser.transmit(cmd.encode()) 58 data = ser.receive() 59 return data.decode() 60 61 def get_idn(self): 62 """ 63 Get the instrument identification number 64 65 Returns: 66 the instrument identification 67 """ 68 return self.query("*IDN?") 69 70 def get_instrument_identification(self): 71 """ 72 Get the instrument identification number. This is an alias for `get_idn()`. 73 74 Returns: 75 the instrument identification 76 """ 77 return self.get_idn() 78
class
GenericInstrument:
6class GenericInstrument: 7 """ 8 Generic instrument class. 9 """ 10 11 def __init__(self, ip_address, port=5025): 12 self._sock = None 13 self.ip_address = ip_address 14 self.port = port 15 16 def connect(self): 17 """ 18 Connect to the instrument. 19 """ 20 self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 21 22 addr = (self.ip_address, self.port) 23 try: 24 self._sock.connect(addr) 25 except socket.error as e: 26 print("failed to connect: ", addr) 27 print(e) 28 29 return self._sock 30 31 def close(self): 32 """ 33 Close the connection. 34 """ 35 self._sock.close() 36 37 def command(self, cmd: str): 38 """ 39 Send a command to the instrument. 40 41 Args: 42 cmd: the command to send 43 """ 44 ser = SocketSerializer(self._sock, buffered_transmit=True) 45 ser.transmit(cmd.encode()) 46 47 def query(self, cmd: str): 48 """ 49 Send a query to the instrument. 50 51 Args: 52 cmd: the command to send 53 54 Returns: 55 the response from the instrument 56 """ 57 ser = SocketSerializer(self._sock, buffered_transmit=True) 58 ser.transmit(cmd.encode()) 59 data = ser.receive() 60 return data.decode() 61 62 def get_idn(self): 63 """ 64 Get the instrument identification number 65 66 Returns: 67 the instrument identification 68 """ 69 return self.query("*IDN?") 70 71 def get_instrument_identification(self): 72 """ 73 Get the instrument identification number. This is an alias for `get_idn()`. 74 75 Returns: 76 the instrument identification 77 """ 78 return self.get_idn()
Generic instrument class.
def
connect(self):
16 def connect(self): 17 """ 18 Connect to the instrument. 19 """ 20 self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 21 22 addr = (self.ip_address, self.port) 23 try: 24 self._sock.connect(addr) 25 except socket.error as e: 26 print("failed to connect: ", addr) 27 print(e) 28 29 return self._sock
Connect to the instrument.
def
command(self, cmd: str):
37 def command(self, cmd: str): 38 """ 39 Send a command to the instrument. 40 41 Args: 42 cmd: the command to send 43 """ 44 ser = SocketSerializer(self._sock, buffered_transmit=True) 45 ser.transmit(cmd.encode())
Send a command to the instrument.
Arguments:
- cmd: the command to send
def
query(self, cmd: str):
47 def query(self, cmd: str): 48 """ 49 Send a query to the instrument. 50 51 Args: 52 cmd: the command to send 53 54 Returns: 55 the response from the instrument 56 """ 57 ser = SocketSerializer(self._sock, buffered_transmit=True) 58 ser.transmit(cmd.encode()) 59 data = ser.receive() 60 return data.decode()
Send a query to the instrument.
Arguments:
- cmd: the command to send
Returns:
the response from the instrument
def
get_idn(self):
62 def get_idn(self): 63 """ 64 Get the instrument identification number 65 66 Returns: 67 the instrument identification 68 """ 69 return self.query("*IDN?")
Get the instrument identification number
Returns:
the instrument identification
def
get_instrument_identification(self):
71 def get_instrument_identification(self): 72 """ 73 Get the instrument identification number. This is an alias for `get_idn()`. 74 75 Returns: 76 the instrument identification 77 """ 78 return self.get_idn()
Get the instrument identification number. This is an alias for get_idn()
.
Returns:
the instrument identification