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

4 次查看(过去 30 天)
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?

采纳的回答

dpb
dpb 2016-11-30
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 个评论
zeytun
zeytun 2016-12-1
编辑:zeytun 2016-12-1
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Instrument Control Toolbox Supported Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by