I am working with- GitHub - vasoto/pycaenhv: Pure Python bindings for CAEN HV Wrapper .
The errors are written in errors.py inside pycaenhv/src. It gets errors from the machine, in errors.py it translates it to python. The functions are inside wrappers.py. whenever I call init_system it opens the machine. in my code I call it once but use the output multiple times and it is fine but in the streamlit app it gives âDevice already openâ. I think the problem is between my code and the app. how does streamlit executes the code? maybe it calls init_system again?
Adding my code if it will help.
Thank you for responding!
import streamlit as st
import pandas as pd
from ctypes import byref, c_int, c_char_p, POINTER, c_void_p
from _lib import load_lib
from _export_func import export_func
from constants import MAX_CH_NAME
from errors import check_function_output
from typing import List, Union, Any, Optional, Dict
from enums import CAENHV_SYSTEM_TYPE, LinkType
P = POINTER
c_int_p = POINTER(c_int)
lib = load_lib()
NamesArrayType = P(c_char_p * MAX_CH_NAME)
CAENHV_InitSystem = export_func(
lib, âCAENHV_InitSystemâ, c_int,
[c_int, c_int, c_void_p, c_char_p, c_char_p, c_int_p],
âInitialize HV systemâ)
def init_system(system_type: Union[CAENHV_SYSTEM_TYPE, int],
link_type: Union[LinkType, int],
argument: Any,
username: str = ââ,
password: str = ââ) â int:
ââ" Initialize the system and returns the handle
ââ"
_handle = c_int()
_system = int(system_type)
link = int(link_type)
arg = argument
if isinstance(arg, str):
arg = arg.encode()
err = CAENHV_InitSystem(_system, link, arg, username.encode(),
password.encode(), byref(_handle))
print(âerrâ , err)
check_function_output(err)
return _handle.value
st.title(âCAEN appâ)
h = int(init_system(2, 0, â192.168.168.5â, âadminâ, âadminâ)) #this is where it gets stuck