代码分了两个模块 UI 部分 和 数据传送部分
UI部分大部分有图形化的帮助 比较好操作 需要参考的建议直接用源文件看(代码详解有时间补上) 主要调用了appdesigner里的UI插件比如开关,指示灯之列的
其实大部分内容都不须要你自己去写 都是app designer 自动生成的
classdef main < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
GridLayout matlab.ui.container.GridLayout
LeftPanel matlab.ui.container.Panel
connectorEditFieldLabel matlab.ui.control.Label
connectorEditField matlab.ui.control.EditField
connectButton matlab.ui.control.Button
disconnectButton matlab.ui.control.Button
IfTemp matlab.ui.control.CheckBox
IfHumi matlab.ui.control.CheckBox
TemperatureGaugeLabel matlab.ui.control.Label
TemperatureGauge matlab.ui.control.LinearGauge
HumidityGaugeLabel matlab.ui.control.Label
HumidityGauge matlab.ui.control.LinearGauge
ButtonGroup matlab.ui.container.ButtonGroup
TempC matlab.ui.control.RadioButton
TempF matlab.ui.control.RadioButton
STARTButton matlab.ui.control.Button
STOPButton matlab.ui.control.Button
Label matlab.ui.control.Label
showT matlab.ui.control.NumericEditField
Label_2 matlab.ui.control.Label
showF matlab.ui.control.NumericEditField
PlotLabel matlab.ui.control.Label
CLabel matlab.ui.control.Label
Label_3 matlab.ui.control.Label
RightPanel matlab.ui.container.Panel
UIAxes matlab.ui.control.UIAxes
UITable matlab.ui.control.Table
StatisticsLabel matlab.ui.control.Label
statusLampLabel matlab.ui.control.Label
statusLamp matlab.ui.control.Lamp
FileoperationLabel matlab.ui.control.Label
SaveDataButton matlab.ui.control.Button
LoadDataButton matlab.ui.control.Button
TempIndicatorLampLabel matlab.ui.control.Label
TempIndicatorLamp matlab.ui.control.Lamp
HumiIndicatorLampLabel matlab.ui.control.Label
HumiIndicatorLamp matlab.ui.control.Lamp
HEditFieldLabel matlab.ui.control.Label
HEditField matlab.ui.control.NumericEditField
TEditFieldLabel matlab.ui.control.Label
TEditField matlab.ui.control.NumericEditField
Label_4 matlab.ui.control.Label
CFLabel matlab.ui.control.Label
end
% Properties that correspond to apps with auto-reflow
properties (Access = private)
onePanelWidth = 576;
end
methods (Access = public)
function UIconnected(app)
app.disconnectButton.Enable = 'on';
app.connectButton.Enable = 'off';
app.connectorEditField.Enable = 'off';
app.TempC.Enable = 'on';
app.TempF.Enable = 'on';
app.STARTButton.Enable = 'on';
app.STOPButton.Enable = 'off';
app.IfTemp.Enable = 'on';
app.IfHumi.Enable = 'on';
app.TemperatureGauge.Enable = 'on';
app.HumidityGauge.Enable = 'on';
app.UITable.Enable = 'on';
app.statusLamp.Color = [1.00,0.00,0.00];
end
end
methods (Access = private)
function UIdisconnected(app)
app.disconnectButton.Enable = 'off';
app.connectButton.Enable = 'on';
app.connectorEditField.Enable = 'on';
app.TempC.Enable = 'off';
app.TempF.Enable = 'off';
app.STARTButton.Enable = 'off';
app.STOPButton.Enable = 'off';
app.IfTemp.Enable = 'off';
app.IfHumi.Enable = 'off';
app.TemperatureGauge.Enable = 'off';
app.HumidityGauge.Enable = 'off';
app.UITable.Enable = 'off';
app.statusLamp.Color = [0.50,0.50,0.50];
app.HumiIndicatorLamp.Color = [0.50,0.50,0.50];
app.TempIndicatorLamp.Color = [0.50,0.50,0.50];
app.SaveDataButton.Enable = 'off';
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.connectorEditField.Value = 'COM5';
UIdisconnected(app);
global IsinF;
IsinF = false;
app.UITable.Data = {0,0,0,0;0,0,0,0};
end
% Button pushed function: connectButton
func