Skip to main content

An easy library for controlling SCPI instruments

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 very useful for inheritance when creating a controller for a specific instrument.

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. Commands with no arguments are run by passing an empty string to the call.

Examples

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

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

# 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>, <timeout>, read_terminator = None, write_terminator = None, backend = '' ): Creates an instance of an instrument

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

port: The communication port

rid: The resource id associated with the instrument [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]

Full Example

For use with Tektronix PWS4305

#standard imports
import os
import sys

#SCPI imports
import usb
import visa

#instrument controller
import instrument_controller as ic


class PowerSupply( ic.Instrument ):

    def __init__( self, timeout = 10, rid = None ):
        ic.Instrument.__init__( self, None, timeout, '\n', '\n' )
        self.rid = '<default resource id>' if ( rid is None ) else rid

    #--- 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.0.2.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

easy_scpi-0.0.2-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file easy-scpi-0.0.2.tar.gz.

File metadata

  • Download URL: easy-scpi-0.0.2.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for easy-scpi-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6af032fcfe50bd216447a1fe09519bfa749283bf1b66d4c5e72125b524eed6c6
MD5 e9a5af1c459193d89416738bce902d05
BLAKE2b-256 91e2fecc0953fa67a5186be5e68e93d4d9f293ab572fbccd358bc1fc8e2d8aff

See more details on using hashes here.

File details

Details for the file easy_scpi-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: easy_scpi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for easy_scpi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 861d9611f8605e841dce3a12483eb802742e66d1a07a7d266a378bcc8a18eec1
MD5 39fdccddc69b24eb469480cf104909b6
BLAKE2b-256 3ec01390ce7c156c8e76b830be6a1d615ab055f7c5e94c161cf06ae1e7f71764

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