ich habe die Matlab-Code für die Steuerung von Anlage geschrieben. Das Programm funktioniert. Die Aufgabe ist bei bestimmte Signale in Volt, die durch DAQ-System die Signale im Amper in SCPI-Befehl für Instrument sendet.
obj1 = instrfind('Type', 'serial', 'Port', 'COM3', 'Tag', '');
%s1=Serial('<COM1','baudrate',9600,'stopbits',1,'Terminator','
%Create the serial port object if it does not exist
%otherwise use the object that was found.
ifisempty(obj1)
obj1 = serial('COM3');
else fclose(obj1);
obj1 = obj1(1);
end
% Connect to instrument object, obj1. fopen(obj1);
Nächste Schritt ist GUI-Obelrfläche zu schreiben. Mein Code
Code:
functionvarargout = Zelle(varargin) % ZELLE MATLAB code for Zelle.fig % ZELLE, by itself, creates a new ZELLE or raises the existing % singleton*.
%
% H = ZELLE returns the handle to a new ZELLE or the handle to % the existing singleton*.
%
% ZELLE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in ZELLE.M with the given input arguments.
%
% ZELLE('Property','Value',...) creates a new ZELLE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Zelle_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Zelle_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Zelle
% Last Modified by GUIDE v2.5 27-Oct-2020 20:11:20
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Zelle_OpeningFcn, ...
'gui_OutputFcn', @Zelle_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before Zelle is made visible. function Zelle_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Zelle (see VARARGIN)
% Choose default command line output for Zelle
handles.output = hObject;
% UIWAIT makes Zelle wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Zelle_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on button press in Start. function Start_Callback(hObject, eventdata, handles) % hObject handle to Start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global obj1 strom spannung
% Connect to instrument object, obj1. fopen(obj1);
if ~isempty(obj1) set( handles.Labor,'ForegroundColor','green');
else set( handles.Labor,'ForegroundColor','red');
end
fprintf(obj1,'syst:lock on');
data=str2double(get(handles.Tabelle,'Data'));
% data=cell2mat(get(handles.Tabelle,'Data')); for i=1:length(data(:,1)) if ~isnan(data(i,1))
spannung(i)=data(i,1);
strom(i)=data(i,2);
end end
% --- Executes when entered data in editable cell(s) in Tabelle. function Tabelle_CellEditCallback(hObject, eventdata, handles) % hObject handle to Tabelle (see GCBO) % eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE) % Indices: row and column indices of the cell(s) edited % PreviousData: previous data for the cell(s) edited % EditData: string(s) entered by the user % NewData: EditData or its converted form set on the Data property. Empty if Data was not changed % Error: error string when failed to convert EditData to appropriate value for Data % handles structure with handles and user data (see GUIDATA)
hObject.ColumnEditable = [truetrue];
%set(hObject,'data',[0]);
function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
Hardware is reserved (possibly by an external application). Call release to unreserve the
hardware or exit the external application, and retry the operation.
Das Fehler kommt beim Befehl
s.Background();
Wo könnte das Problem sein?
Mit Grüß
kaktus
Einstellungen und Berechtigungen
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.