function varargout = com_serial(varargin)
%COM_SERIAL M-file for com_serial.fig
% COM_SERIAL, by itself, creates a new COM_SERIAL or raises the existing
% singleton*.
%
% H = COM_SERIAL returns the handle to a new COM_SERIAL or the handle to
% the existing singleton*.
%
% COM_SERIAL('Property','Value',...) creates a new COM_SERIAL using the
% given property value pairs. Unrecognized properties are passed via
% varargin to com_serial_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% COM_SERIAL('CALLBACK') and COM_SERIAL('CALLBACK',hObject,...) call the
% local function named CALLBACK in COM_SERIAL.M with the given input
% arguments.
%
% *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 com_serial
% Last Modified by GUIDE v2.5 14-Jul-2015 10:23:48
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @com_serial_OpeningFcn, ...
'gui_OutputFcn', @com_serial_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before com_serial is made visible.
function com_serial_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for com_serial
handles.output = hObject;
javaFrame = get(hObject, 'JavaFrame');
javaFrame.setFigureIcon(javax.swing.ImageIcon('com_serial.jpg'));
axes(handles.axes2);
% set(gca,'units','normalized','position',[0,0,1,1])
% image(imread('com_serial_bg.jpg'));%imshow('com_serial_bg.jpg');
set(gca,'handlevisibility','off','visible','off');%axis off; movegui(hObject,'center');
handles.sendbtns = [
handles.send01btn,handles.send02btn,handles.send03btn,handles.send04btn,handles.send05btn,...
handles.send06btn,handles.send07btn,handles.send08btn,handles.send09btn,handles.send10btn];
handles.sendedits = [
handles.send01edit,handles.send02edit,handles.send03edit,handles.send04edit,handles.send05edit,...
handles.send06edit,handles.send07edit,handles.send08edit,handles.send09edit,handles.send10edit];
handles.sendtexts = [
handles.send01text,handles.send02text,handles.send03text,handles.send04text,handles.send05text,...
handles.send06text,handles.send07text,handles.send08text,handles.send09text,handles.send10text];
handles.enable = 'On';
handles.autoSendEnable = 'On';
handles.sbuff = '';
axes(handles.axes3)
t = -pi:.1:pi;
handles.fig5 = fill(sin(t),cos(t),'k');%[236 233 216]/255
set(handles.fig5,'EdgeColor',[236 233 216]/255);
axis off
axes(handles.axes1);
handles.fig1 = plot(0,0,'r');hold on
handles.fig2 = plot(0,0,'b');hold on
handles.fig3 = plot(0,0,'m');hold on
handles.fig4 = plot(0,0,'k');hold on
% set(handles.fig1,'XData',[],'YData',[]);
% set(handles.fig2,'XData',[],'YData',[]);
% set(handles.fig3,'XData',[],'YData',[]);
% set(handles.fig4,'XData',[],'YData',[]);
% Update handles structure
guidata(hObject, handles);
if exist('com_serial.mat')
para = load('com_serial.mat');
set(handles.send01edit,'String',para.send01edit);
set(handles.send02edit,'String',para.send02edit);
set(handles.send03edit,'String',para.send03edit);
set(handles.send04edit,'String',para.send04edit);
set(handles.send05edit,'String',para.send05edit);
set(handles.send06edit,'String',para.send06edit);
set(handles.send07edit,'String',para.send07edit);
set(handles.send08edit,'String',para.send08edit);
set(handles.send09edit,'String',para.send09edit);
set(handles.send10edit,'String',para.send10edit);
set(handles.sendcharedit,'String',para.sendcharedit);
set(handles.bautpopup,'Value',para.baut);
set(handles.checkpopup,'Value',para.check);
set(handles.datapopup,'Value',para.data);
set(handles.stoppopup,'Value',para.stop);
set(handles.xmaxedit,'String',para.xmaxedit);
set(handles.yminedit,'String',para.yminedit);
set(handles.ymaxedit,'String',para.ymaxedit);
end
for i=1:10
sendEditFun(handles, i);
end
% UIWAIT makes com_serial wait for user response (see UIRESUME)
% uiwait(handles.figure1);
object_enable(hObject,handles);
% --- Outputs from this function are returned to the command line.
function varargout = com_serial_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;
function object_enable(hObject,handles)
set(handles.portpopup,'Enable',handles.enable);
set(handles.bautpopup,'Enable',handles.enable);
set(handles.datapopup,'Enable',handles.enable);
set(handles.checkpopup,'Enable',handles.enable);
set(handles.stoppopup,'Enable',handles.enable);
set(handles.openbtn,'Enable',handles.enable);
tmp = 'Off';
if (strcmp(handles.enable,'Off'))
tmp = 'On';
end
for i=1:10
set(handles.sendbtns(i),'Enable',tmp);
set(handles.sendedits(i),'Enable',tmp);
end
set(handles.closebtn,'Enable',tmp);
set(handles.autoSendcheck,'Enable',tmp);
set(handles.autoSendTimeedit,'Enable',tmp);
set(handles.autoAddSendcheck,'Enable',tmp);
set(handles.autoAddSend2edit,'Enable',tmp);
set(handles.autoAddSend3edit,'Enable',tmp);
set(handles.autoAddSendTimeedit,'Enable',tmp);
set(handles.sendcharbtn,'Enable',tmp);
set(handles.sendcharedit,'Enable',tmp);
set(handles.sendchartimecheck,'Enable',tmp);
set(handles.sendchartimeedit,'Enable',tmp);
function autoSend_enable(hObject,handles)
for i=1:10
set(handles.sendbtns(i),'Enable',handles.autoSendEnable);
set(handles.sendedits(i),'Enable',handles.autoSendEnable);
end
% 中断处理程序
function rcvIsrFcn(obj, event, handles)
global rcvTempData
% obj = handles.sbuff;
n = get(obj,'BytesAvailable');
if n
if ~get(handles.hexcheck,'value')
%c = fscanf(obj);
val = fread(obj,n,'uchar');
c = char(val');
c = strcat(get(handles.rcvedit,'string'),c);
set(handles.rcvedit,'string',c)
else
val = fread(obj,n,'uchar');
str = dec2hex(val,2)';
c = [str(1,:) str(1,:) str(1,:)];
c(2:3:end) = str(1,:);
c(3:3:end) = str(2,:);
c(1:3:end) = ' ';
% c=['',c(1:end-1)];%c(3:3:end) = ' '; %
if (~get(handles.pauseRcvShowbtn,'Value'))
set(handles.rcvedit,'string',strcat(get(handles.rcvedit,'string'),c));
% set(handles.rcvedit,'string',[get(handles.rcvedit,'string'),c]);
end
if (get(handles.nocheckradio,'value'))
return
end
val = val';
rcvTempData = [rcvTempData val];
checkok = 0;
while (~isempty(rcvTempData))
if (rcvTempData(1)~=240)
rcvTempData = rcvTempData(2:end);
else
rcvlen = length(rcvTempData);
if (get(handles.sum8radio,'value'))
if (rcvlen>=10)
len = 10;
if (bitand(sum(rcvTempData(1:len-1)),255)==rcvTemp