VirtualBench

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple readings with pyvirtualbench

Hello,

This is my first post, so... sorry for any mistakes.

I'm working with virtualbench and developing a project that involves multiple readings using pyvirtualbench.
This is done with an HTML menu that passes voltage values.

 
#! /usr/bin/env python3

# The MIT License (MIT)
#
# Copyright (c) 2016 Charles Armstrap <charles@armstrap.org>
# If you like this library, consider donating to: https://bit.ly/armstrap-opensource-dev
# Anything helps.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import os, sys

# Caminho para o diretório ctrl_hardware
ctrl_hardware_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'ctrl_hardware'))
# Adiciona o diretório ao sys.path
sys.path.append(ctrl_hardware_path)

from pyvirtualbench import PyVirtualBench, PyVirtualBenchException, DmmFunction

# You will probably need to replace "myVirtualBench" with the name of your device.
# By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
# You can see the device's name in the VirtualBench Application under File->About
virtualbench = PyVirtualBench('VB8012-30A210F')

#from shift_register import SRoutput

# This examples demonstrates how to make measurements using the Power
    
def config_VB_DMM (Vcc:int, configMeasure:str):
    #Vcc = int(Vcc) # É passado o parâmetro em forma de string mas é necessária a conversão para int
    #Resistence = int(Resistence)

    #############################
    # Power Supply Configuration
    #############################
    ps = virtualbench.acquire_power_supply()
    channel = "ps/+25V"
    voltage_level = Vcc
    current_limit = 0.5
    ps.configure_voltage_output(channel, voltage_level, current_limit)
    ps.enable_all_outputs(True)
    print(Vcc)
    
    dmm = virtualbench.acquire_digital_multimeter()

    if configMeasure == "voltage":
        dmm.configure_measurement(DmmFunction.DC_VOLTS, True, 10)
    elif configMeasure == "current":
        dmm.configure_measurement(DmmFunction.DC_CURRENT, True, 1) # Verificar Manual Range = 10.0
    
    measurement_result = dmm.read()
    print("MeasurementCONFIG: %f V" % (measurement_result))
    ps.release()
    dmm.release()
    virtualbench.release()
    return measurement_result
 
This script is intended to be called several time to make a voltage measure. However... most of the times the first measure is OK but then I can't do anymore measure. Or because the resource is busy... or whetever
Mensagem enviada com sucesso.
1
MeasurementCONFIG: 0.967100 V
MeAsure: 0.967100484999414
127.0.0.1 - - [02/Apr/2024 13:57:07] "GET /config_VirtualBench?parameter=voltage&Vcc=1&R=1 HTTP/1.1" 200 -
measure_parameter: voltage
Mensagem enviada com sucesso.
127.0.0.1 - - [02/Apr/2024 13:57:13] "GET /config_VirtualBench?parameter=voltage&Vcc=2&R=1 HTTP/1.1" 500 -
Traceback (most recent call last):
  File "C:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\.venv\Lib\site-packages\flask\app.py", line 1488, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\.venv\Lib\site-packages\flask\app.py", line 1466, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\.venv\Lib\site-packages\flask\app.py", line 1463, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\.venv\Lib\site-packages\flask\app.py", line 872, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\.venv\Lib\site-packages\flask\app.py", line 870, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\.venv\Lib\site-packages\flask\app.py", line 855, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\.venv\Lib\site-packages\flask_login\utils.py", line 290, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\webserver\website\views.py", line 41, in config_VirtualBench
    measurement_result = configVB.config_VB_DMM(Vcc, measure_parameter)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\ctrl_hardware\configVB.py", line 52, in config_VB_DMM
    ps = virtualbench.acquire_power_supply()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\.venv\Lib\site-packages\pyvirtualbench\pyvirtualbench.py", line 1945, in acquire_power_supply
    return self.PowerSupply(self, device_name, reset)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\edumm\OneDrive - Instituto Superior de Engenharia do Porto\ISEP\github\Unnamed-Thesis\.venv\Lib\site-packages\pyvirtualbench\pyvirtualbench.py", line 1955, in __init__
    raise PyVirtualBenchException(status, self.nilcicapi, self.library_handle)
pyvirtualbench.pyvirtualbench.PyVirtualBenchException:​

As you can see, the first lines show one correct measure, then I tried to make the second one.... 
Any help?

Thank You!
 
0 Kudos
Message 1 of 1
(103 Views)