Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

QWERTY MATLAB GUI Code: Connection and Broadcasting Functionality, Study Guides, Projects, Research of Network Programming

A matlab script for creating a user interface (gui) using the qwerty toolbox. The script includes various callback functions for handling user interactions such as starting the application, generating a new connection, entering device names and pin codes, and broadcasting data to all connected devices. The script also includes functions for handling errors and displaying status messages.

Typology: Study Guides, Projects, Research

2011/2012

Uploaded on 07/31/2012

dhanush
dhanush 🇮🇳

4

(3)

39 documents

Partial preview of the text

Download QWERTY MATLAB GUI Code: Connection and Broadcasting Functionality and more Study Guides, Projects, Research Network Programming in PDF only on Docsity! function varargout = qwerty(varargin) % QWERTY M-file for qwerty.fig % QWERTY, by itself, creates a new QWERTY or raises the existing % singleton*. % % H = QWERTY returns the handle to a new QWERTY or the handle to % the existing singleton*. % % QWERTY('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in QWERTY.M with the given input arguments. % % QWERTY('Property','Value',...) creates a new QWERTY or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before qwerty_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to qwerty_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 qwerty % Last Modified by GUIDE v2.5 28-Dec-2009 18:53:47 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @qwerty_OpeningFcn, ... 'gui_OutputFcn', @qwerty_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 end % --- Executes just before qwerty is made visible. function qwerty_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure docsity.com % 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 qwerty (see VARARGIN) % Choose default command line output for qwerty handles.output = hObject; % Update handles structure guidata(hObject, handles); end % UIWAIT makes qwerty wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = qwerty_OutputFcn(hObject, eventdata, handles) %% Initialization: global num nodes IPs_Stack varargout{1} = handles.output; snap = imread('1.JPG'); axes(handles.axes2); %Create axes in arbitrary positions. imshow(snap) set(handles.edit1,'string','Initially, there is no connection between Bluetooth devices'); IPs_Stack = ['198.168.2.1'; '210.1.100.1'; '150.150.3.1'; '198.168.2.2'; '127.136.3.1'; '200.150.1.3'; '100.160.2.5';'198.168.4.1']; % These are obtained by the user from the master when the user enters the correct pin code end %% Start of Simulation: function start_Callback(hObject, eventdata, handles) global num node IPs_Stack node = []; % to delete the previous value since its global snap = imread('2.JPG'); axes(handles.axes2); imshow(snap) set(handles.edit1,'string','A device requests for connection, hence acting as Master node'); num = 1; % i.e. 1 active node in the network node(1).Device_Name = 'Master'; node(1).IP = IPs_Stack(1,:); node(1).Pincode = 0000; flag = 1; % to abort queue image simulation, so that imediately termination or broadcasting is done as soon as the button is pressed. end %% New Connection Button: function newconn_Callback(hObject, eventdata, handles) docsity.com for j = 1:100 if flag == 1 break end for i = 1:num-1 axes(handles.axes2); imshow(im(i).simu) set(handles.edit1,'string',im(i).stat); drawnow bytes = data; set(handles.bytedit,'string',num2str(bytes)); drawnow end end end else x = imread('45.jpg'); axes(handles.axes2); imshow(x) status = 'There are already 7 nodes in BT PAN, Connection rejected to '; status = [status name]; set(handles.edit1,'string',status); drawnow bytes = data; set(handles.bytedit,'string',num2str(bytes)); drawnow pause(2); end end %% The Pincode displayed by Master: function master_pincode_Callback(hObject, eventdata, handles) end function master_pincode_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end docsity.com end %% Broadcast Button: function broadcast_Callback(hObject, eventdata, handles) global num node flag broad = broadcast(num,node); axes(handles.axes2); imshow(broad.simu) set(handles.edit1,'string',broad.stat); drawnow bytes = data; set(handles.bytedit,'string',num2str(bytes)); drawnow pause(3) end function selected_Callback(hObject, eventdata, handles) end %% For sending data to just 1 client: function sending_Callback(hObject, eventdata, handles) global sending sending = get(hObject, 'String'); end function sending_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end end %% For Showing Transferred Bytes: function bytedit_Callback(hObject, eventdata, handles) end function bytedit_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end end %% Getting Selected Client Name: function cliesel_Callback(hObject, eventdata, handles) global node num flag sending docsity.com check = 0; flag = 1; bytes = data; set(handles.bytedit,'string',num2str(bytes)); drawnow for i=1:num c = strcmpi(sending,node(i).Device_Name); if c == 1 set_val = i; % For defining the entered user's serial numbaer in data base check = 1; break end end if check == 0; set(handles.edit1,'string','The device name is not in the data base of Master Device'); drawnow pause(3) else s = sel(num,node,set_val); axes(handles.axes2); imshow(s.simu) set(handles.edit1,'string',s.stat); drawnow bytes = data; set(handles.bytedit,'string',num2str(bytes)); drawnow pause(3) end end function cliesel_CreateFcn(hObject, eventdata, handles) end %% For terminating connection of a device from the piconet: function term_Callback(hObject, eventdata, handles) global node num deviceterm flag flag = 1; check = 0; bytes = data; set(handles.bytedit,'string',num2str(bytes)); drawnow for i=1:num c = strcmpi(deviceterm,node(i).Device_Name); if c == 1 docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved