Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

best way to work with many channels in a gui #13

Open
Aemornion opened this issue Jul 10, 2019 · 0 comments
Open

best way to work with many channels in a gui #13

Aemornion opened this issue Jul 10, 2019 · 0 comments

Comments

@Aemornion
Copy link

Hello,
I apologize if this question is a little scattered, i trying to muddle my way threw using this in conjunction with guide to make a GUI which will control some canberra NIM modules. I am certainly not the best at coding.

The code works perfectly when its just one function or script, but when i have multiple functions in one file or callbacks from gui elements, i run into trouble.

I had assumed i could create a function that utilized just the

channel = Channels.create(context, ChannelDescriptor('double', 'ARIDI-PCT:CURRENT'));
channel.get()

portion of the code with the rest in the opening function, but in practice that did not work. I assume it has something to do with the
import ch.psi.jcae.*
not being passed into the callbacks.

My work around was to write a function that simply repeated the various commands, using variable string to control which channel i accessed.

function answer = EPICS_READ(PV,type)
if not(exist('java_classpath_set'))
    javaaddpath('ca_matlab-1.0.0.jar')
    java_classpath_set = 1;
end
import ch.psi.jcae.*
properties = java.util.Properties();
context = Context(properties);'
channel = Channels.create(context, ChannelDescriptor(type, PV));
answer = channel.get()
channel.close();
context.close();

I can then call this one function from any of my callbacks and easily pass the various PV's and parameters back and forth.

My question is... is this the best way?
It seems like I am calling the same code repeatedly, which takes time and is slowing down the gui.

Is there a way to achieve my desired outcome, Were the bulk of the code, loading the java, etc.
is run once, and then the actual channel creation and closure is all i need to worry about within a callback or subfunction.

something like this

function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);

if not(exist('java_classpath_set'))
    javaaddpath('ca_matlab-1.0.0.jar')
    java_classpath_set = 1;
end
import ch.psi.jcae.*
properties = java.util.Properties();
context = Context(properties);

function edit1_Callback(hObject, eventdata, handles)
channel = Channels.create(context, ChannelDescriptor(type, PV));
answer = channel.get()
channel.close();

another question, is it important to close the whole context, after creating and using one channel?
context.close();

or is there a way to create the context once, then just leave it open for as long as my gui is open and running passing it like handles and hObject or something?
somehow passing the context and java import into my various callbacks

Does my question even make sense... i barely understand it myself...

-Jay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant