Can any one give me an example about "How to write an array of string values into the Simulation Item 'Bucket Brigade.ArrayOfString' of Matrikon OPC SImulation Server using Matlab and OPC Toolbox" ?

2 views (last 30 days)
I am trying to perform the OPC Write of certain signal values computed from the Simulink model running on a Target PC into the Simulation Items of Matrikon OPC Simulation Server through Matlab GUI.
Practical Scenario: Simulink model is build from Host PC (equipped with Matlab/Simulink, OPC Toolbox, xPC Target and MatrikonOPC Simulation Server) and kept running on the Target PC (equipped with an xPC Target real-time kernel) using the '.dlm' application file of the Simulink model.
The Build process behind the '.slx' Simulink model, Download of its respective '.dlm' application file onto the Target PC and Start of the application in the Target PC are being performed through Matlab GUI.
Until now, i had no difficulty in performing the OPC Write of certain signal (here signal data type is 'double') values and single string value into the Simulation items 'Bucket Brigade.Real4', 'Bucket Brigade.Real8' & 'Bucket Brigade.String' of Matrikon OPC Simulation Server through Matlab GUI.
Approach: The following is the Matlab GUI code where i am trying to perform the OPC Write of certain signal values and single string value into the Simulation items 'Bucket Brigade.Real4', 'Bucket Brigade.Real8' & 'Bucket Brigade.String' of Matrikon OPC Simulation Server
% --- Executes on button press in btStartApp.
function btStartApp_Callback(hObject, eventdata, handles)
% hObject handle to btStartApp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% cd(handles.options.guioptions.dlmpath);
writeToStatus('Status: Starting Application........', handles);
try
start(handles.tg); % Start application
%Set the stop time display
set(handles.tbStopTime,'String',['Stop Time: ' num2str(get(handles.tg,'StopTime'))]);
set(handles.btStopApp,'Enable','on'); % Enable the Stop push button
set(handles.btStartApp,'Enable','off'); % Disable the Start push buttonS
set(handles.btConnect,'Enable','off'); % Disable the Connect push button
set(handles.btDownload,'Enable','off'); % Disable the Download push button
% % OPC Initialisation
da = opcda('localhost','Matrikon.OPC.Simulation.1');%defines the Local Host as MatrikonOPC Server
connect(da);%connects to MatrikonOPC Server
opcregister('install', '-silent');%if not able to connect then silently install the opc
connect(da);%connects to MatrikonOPC Server
grp = addgroup(da, 'Group0'); %make a Group "Group0"
grpIDS = {'Bucket Brigade.Real8','Bucket Brigade.Real4','Bucket Brigade.ArrayOfString'}; %list out all dataIDS
grp_itm = additem(grp, grpIDS); %an itm object is created with listed items tags
set(grp,'UpdateRate',0.5);
% Store handles to connection and group in figure
setappdata(handles.tg, 'dahandle', da);
setappdata(handles.tg, 'grouphandle', grp);
cla (handles.axes1,'reset');
cla (handles.axes2,'reset');
cla (handles.axes18,'reset');
cla (handles.axes19,'reset');
writeToStatus('Status: Application Running', handles);
guidata(hObject,handles); % Update handles structure
start(handles.t) % Start Timer object
catch ME
writeToStatus(['Error: Application could not be started: ' ME.message], handles);
end
end
function xPC_UpdateStates(obj,event, hObject)
handles = guidata(hObject);
grp = getappdata(handles.tg, 'grouphandle');
try
if strcmp(get(handles.tg,'Status'),'stopped') % Check if application still running
btStopApp_Callback(hObject,event, handles);
end
%call event handler
err = do_check_events(handles);
if isobject(err)
btStopApp_Callback(hObject,event, handles);
stop(handles.tg);
throw(err);
end
catch ME
writeToStatus(['Error xPC_UpdateStates: Timer function execution error: ' ME.message], handles);
%errordlg(ME.message);
end
% Display Simulation Time
set(handles.tbExecTime,'String',['Execution Time1: ' num2str(get(handles.tg,'exectime'))]); drawnow; % Display execution time
id_sig1 = getsignalid(handles.tg,'Sine Wave');
id_sig2 = getsignalid(handles.tg,'Sine Wave1');
%
% Display Amplitude of Sine Wave
set(handles.tbAmpSine,'String',['Amplitude: ' num2str(getsignal(handles.tg,id_sig1))]); drawnow; % Display sine wave amplitude
% Get signal values
num_p = [getsignal(handles.tg,id_sig1) getsignal(handles.tg,id_sig2)];
cell_p = num2cell(num_p);
% Get string values
ch1_p = strcat({get(handles.btMC_text,'String')},{get(handles.btMacCut,'String')});
str_p = cellstr(ch1_p);
ct_ = cat(2,cell_p,str_p);
end
I get the following warning when i am trying to perform the OPC Write of an array of string values into the Simulation Item 'Bucket Brigade.ArrayOfString':
Warning: One or more items could not be written.
Bucket Brigade.ArrayOfString returned 'Type mismatch.'
Has anyone tried to perform the OPC Write of an array of string values into the Simulation Item 'Bucket Brigade.ArrayOfString', please give me your invaluable input!
Additional Info:
Host PC: Equipped with Matlab R2012b Win 32-bit, OPC Toolbox 3.1.2, xPC Target 5.3, MatrikonOPC Simulation Server
Target PC: Equipped with a xPC Target Real-time kernel
Pre-Requisties Performed: Host-Target TCP/IP communication was established successfully
BR,
Sriniwas
  1 Comment
Suneesh
Suneesh on 29 Jul 2014
This seems like more of an OPC issue. To debug I recommend:
  1. Step through the code and identify where the warning is being issued.
  2. Then get rid of the dependency on the xPC Target and try to use sample strings.
  3. If the above works then see why there is a TYPE mismatch for the data returned from the target.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!