SCPI -Standard Commands for Programmable Instruments
First released in 1990
Defines a standard for syntax and commands to use in controlling programmable test and measurement devices, such as automatic test equipment and electronic test equipment.
SCPI commands are ASCII textual strings, which are sent to the instrument over the physical layer (e.g., IEEE-488.1)
It introduced generic commands (such as CONFigure and MEASure) that could be used with any instrument
Jupyter Notebooks Structure
Analog Input
For a detailed explanation watch the video in the end.
importsysimporttimeimportredpitaya_scpiasscpirp_s=scpi.scpi(sys.argv[1])led1=0led2=1print("Toggling LED["+str(led1)+"] and LED["+str(led2)+"]")period=1# secondswhile1:time.sleep(period/2.0)rp_s.tx_txt('DIG:PIN LED'+str(led1)+','+str(1))rp_s.tx_txt('DIG:PIN LED'+str(led2)+','+str(0))time.sleep(period/2.0)rp_s.tx_txt('DIG:PIN LED'+str(led1)+','+str(0))rp_s.tx_txt('DIG:PIN LED'+str(led2)+','+str(1))
clear_led
Python
Clear LED
importsysimporttimeimportredpitaya_scpiasscpirp_s=scpi.scpi(sys.argv[1])led1=0led2=1print("Clearing LED["+str(led1)+"] and LED["+str(led2)+"]")rp_s.tx_txt('DIG:PIN LED'+str(led1)+','+str(0))rp_s.tx_txt('DIG:PIN LED'+str(led2)+','+str(0))
analog_input
Python
Analog Input
importsysimporttimeimportredpitaya_scpiasscpirp_s=scpi.scpi(sys.argv[1])period=1# secondswhile1:rp_s.tx_txt('ANALOG:PIN? AIN'+str(3))value=float(rp_s.rx_txt())print("Measured voltage on AI["+str(3)+"] = "+str(value)+"V")time.sleep(period/2.0)
redpitaya_scpi
Python
Python Module for RP SCPI
"""SCPI access to Red Pitaya."""importsocket__author__="Luka Golinar, Iztok Jeras"__copyright__="Copyright 2015, Red Pitaya"classscpi(object):"""SCPI class used to access Red Pitaya over an IP network."""delimiter='\r\n'def__init__(self,host,timeout=None,port=5000):"""Initialize object and open IP connection. Host IP should be a string in parentheses, like '192.168.1.100'. """self.host=hostself.port=portself.timeout=timeouttry:self._socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)iftimeoutisnotNone:self._socket.settimeout(timeout)self._socket.connect((host,port))exceptsocket.errorase:print('SCPI >> connect({:s}:{:d}) failed: {:s}'.format(host,port,e))def__del__(self):ifself._socketisnotNone:self._socket.close()self._socket=Nonedefclose(self):"""Close IP connection."""self.__del__()defrx_txt(self,chunksize=4096):"""Receive text string and return it after removing the delimiter."""msg=''while1:chunk=self._socket.recv(chunksize+len(self.delimiter)).decode('utf-8')# Receive chunk size of 2^n preferablymsg+=chunkif(len(chunk)andchunk[-2:]==self.delimiter):breakreturnmsg[:-2]defrx_arb(self):numOfBytes=0""" Recieve binary data from scpi server"""str=''while(len(str)!=1):str=(self._socket.recv(1))ifnot(str=='#'):returnFalsestr=''while(len(str)!=1):str=(self._socket.recv(1))numOfNumBytes=int(str)ifnot(numOfNumBytes>0):returnFalsestr=''while(len(str)!=numOfNumBytes):str+=(self._socket.recv(1))numOfBytes=int(str)str=''while(len(str)!=numOfBytes):str+=(self._socket.recv(1))returnstrdeftx_txt(self,msg):"""Send text string ending and append delimiter."""returnself._socket.send((msg+self.delimiter).encode('utf-8'))deftxrx_txt(self,msg):"""Send/receive text string."""self.tx_txt(msg)returnself.rx_txt()# IEEE Mandated Commandsdefcls(self):"""Clear Status Command"""returnself.tx_txt('*CLS')defese(self,value:int):"""Standard Event Status Enable Command"""returnself.tx_txt('*ESE {}'.format(value))defese_q(self):"""Standard Event Status Enable Query"""returnself.txrx_txt('*ESE?')defesr_q(self):"""Standard Event Status Register Query"""returnself.txrx_txt('*ESR?')defidn_q(self):"""Identification Query"""returnself.txrx_txt('*IDN?')defopc(self):"""Operation Complete Command"""returnself.tx_txt('*OPC')defopc_q(self):"""Operation Complete Query"""returnself.txrx_txt('*OPC?')defrst(self):"""Reset Command"""returnself.tx_txt('*RST')defsre(self):"""Service Request Enable Command"""returnself.tx_txt('*SRE')defsre_q(self):"""Service Request Enable Query"""returnself.txrx_txt('*SRE?')defstb_q(self):"""Read Status Byte Query"""returnself.txrx_txt('*STB?')# :SYSTemdeferr_c(self):"""Error count."""returnrp.txrx_txt('SYST:ERR:COUN?')deferr_c(self):"""Error next."""returnrp.txrx_txt('SYST:ERR:NEXT?')
Comments
Please log in or sign up to comment.