PyVISA-Based Resource Command Execution Function

  • Share this:

Code introduction


This function uses the PyVISA library to open a resource (device), execute a command, and return the response of the command. Then it closes the resource.


Technology Stack : PyVISA

Code Type : Function function

Code Difficulty : Intermediate


                
                    
import random
import visa

def random_visa_function(resource_name, command_string):
    rm = visa.ResourceManager()
    instrument = rm.open_resource(resource_name)
    response = instrument.query(command_string)
    instrument.close()
    return response                
              
Tags: