Skip to main content

An easy library for controlling SCPI instruments.

Reason this release was yanked:

Bug in query logic creating regression.

Project description

Easy SCPI

A simple and robust library making communication with SCPI (Standard Control of Programmbale Instruments) instruments easy. After creating an instrument object that connects to an actual instrument, commands are sent to the instrument using a property-like format. This class is useful for inheritance when creating a controller for a specific instrument. Communication with instruments is done with PyVISA.

Install with

python -m pip install easy-scpi

API

SCPI Commands

Generic SCPI commands can be executed by transforming the SCPI code in to attributes via the hierarchy relationship, then calling it. Instrument properties can be queried by passing no arguments to the call (or specifying query=True). Commands with no arguments are run by passing an empty string to the call.

Examples

# import package
import easy_scpi as scpi 

# Connect to an instrument
inst = scpi.Instrument( <port> )

# Read the voltage [MEASure:VOLTage:DC?]
inst.measure.voltage.dc()
# or
inst.meas.volt.dc()

# Passing args to a query [MEASure:VOLTage:DC? MIN]
inst.measure.voltage.dc("MIN", query=True)

# Set the voltage to 1 V [MEASure:VOLTage:DC 1]
inst.measure.voltage.dc( 1 )
# or
inst.source.voltage( '1' )

# Execute a command to take a reading [SYSTem:ZCORrect:ACQuire]
inst.syst.zcor.aqc( '' )

Methods

Instrument( <port>, backend = '', **resource_params ): Creates an instance of a SCPI instrument. The backend is used to create the VISA Resource Manager. Upon connection, the resource_params are passed to the VISA resource.

connect(): Connects the object instance to the actual instrument on the specified port.

disconnect(): Disconnects the instrument from the program, closing the port.

write( <msg> ): Sends msg to the instrument.

read(): Gets the most recent response from the instrument.

query( <msg> ): Sends msg to the instrument and returns its response.

reset(): Sets the instrument to its default state.

init(): Initializes the instrument for a measurement.

Properties

backend: Returns the name of the VISA backend used. [Read Only]

inst: Returns the resource used by the instance. [Read Only]

port: The communication port.

handshake: Handshake mode of the device. If a string is provided a handshake message will be read after every command or query. If the message matches the string, nothing occurs, otherwise an error is raised. If True a default message of 'OK' is used. If False no message is read. [Default: False]

rid: The resource id associated with the instrument. [Read Only]

resource_params: Returns the resource parameters passed on creation. [Read Only]

timeout: The communication timeout of the instrument. [Read Only]

id: The manufacturer id of the instrument. [Read Only]

value: The current value of the instrument. [Read Only]

connected: Whether the instrument is connected or not. [Read Only]

is_connected: Alias for connected.

Full Example

For use with Tektronix PWS4305

# scpi controller
import easy_scpi as scpi

class PowerSupply( scpi.Instrument ):
    
    def __init__( self ):
        super().__init__( 
            port = None, 
            timeout = 5,
            read_termination = '\n', 
            write_termination = '\n' 
        )

        # other initialization code...

        
    #--- public methods ---

    
    @property        
    def voltage( self ):
        """
        Returns the voltage setting
        """
        return self.source.volt.level()
    
    
    @voltage.setter
    def voltage( self, volts ):
        """
        Sets the voltage of the instrument
        """
        self.source.volt.level( volts )
        
    
    @property
    def current( self ):
        """
        Returns the current setting in Amps
        """
        return self.source.current.level()
        
        
    @current.setter
    def current( self, amps ):
        """
        Set the current of the instrument
        """
        self.source.current.level( amps )
        
    
    def on( self ):
        """
        Turns the output on
        """
        self.output.state( 'on' )
        
        
    def off( self):
        """
        Turns the output off
        """
        self.output.state( 'off' )
        

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easy_scpi-0.1.6.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

easy_scpi-0.1.6-py2.py3-none-any.whl (13.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file easy_scpi-0.1.6.tar.gz.

File metadata

  • Download URL: easy_scpi-0.1.6.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for easy_scpi-0.1.6.tar.gz
Algorithm Hash digest
SHA256 5461289bbad05703e909143157346cdd071a3feddc4897886691f2ccc7a69f29
MD5 e6e60f64a90cef3b15d6860ae520efa7
BLAKE2b-256 12e6c3aafeb2fd8912262c4c2b7d151be774c89f59e715c58835b0c0a24794b0

See more details on using hashes here.

File details

Details for the file easy_scpi-0.1.6-py2.py3-none-any.whl.

File metadata

  • Download URL: easy_scpi-0.1.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for easy_scpi-0.1.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f52796c8ab94060a1c0680875d96c52aef33c9a6fcd6e7a99e81f2fde5175eac
MD5 33d9357e3158c1f5938507f69bdda604
BLAKE2b-256 b993dbe975e3cfe8406764c5a08008216d79b531d5d2cd0c7961054840084f38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page