How can I control a GPIB device's parameters from GUI?

6 views (last 30 days)
Hi,
I wrote a GUI to get the trace from an optical spectrum analyzer (OSA) Ando AQ6317 and to do some processing on that spectrum. My GUI is based on this awesome code: https://www.mathworks.com/matlabcentral/fileexchange/32721-getosatrace.
Anyway, everything works, with a pushbutton I can get the spectrum, analyze it and plot whatever I need. Now I want not only to do this, but also to control the OSA parameters (central wavelength, span, etc.) from my GUI. The communication between the laptop and the OSA is done via a GPIB interface, and obviously the OSA has its commands / program codes for that. For example, the command to change the central wavelength is "CTRWL****.**", so in the Matlab command window I can just write
"query(g1,'CTRWL800')"
and it will do the job. Now the problem is that if I want to change this parameter from my GUI, I need to create an Edit Text and tag it with let's say CWL. So I thought that the command line in the relevant m-file would have been
"query(g1,'CTRWL handles.CWL')"
but unfortunately this is not working. The symbols **.** after CTRWL should be numbers.
Do you think it is possible to solve this problem?

Accepted Answer

dpb
dpb on 30 Nov 2016
Sure, just build a command string to send...but in
query(g1,'CTRWL handles.CWL')
the 'CTRWL handles.CWL' is a literal string, not the result of the control appended to the other string.
cmd=['CTRWL' handles.CWL.String]; % retrieve value; append to command string
query(g1,cmd)
Do you want query to set a control parameter? (Don't know, haven't done GPIB w/ Matlab, only directly w/ NI Fortran libraries so don't know the toolbox)
  1 Comment
zeytun
zeytun on 1 Dec 2016
Edited: zeytun on 1 Dec 2016
Thank you very much! I made just one correction and it worked perfectly. The correction was "cmd = ['CTRWL' num2str(handles.CWL)];" instead of "cmd = ['CTRWL' handles.CWL.String];"
In the latter case it was giving the following error: "Struct contents reference from a non-struct array object." Not sure what this means :) Thanks again!

Sign in to comment.

More Answers (0)

Categories

Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!