Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function menuprinc
- bg = [0 0 0];
- figure('color', bg, 'name', 'Interface Homme-Machine', 'units', 'pixels', 'numbertitle', 'off', 'tag', 'figureMain', 'Position',[550 200 800 600]);
- %Menu principal
- uicontrol('style', 'text', 'units', 'normalized', 'position', [0.35 0.7 0.35 0.18], 'ForegroundColor', [1 1 1], 'backgroundColor', bg, 'string', 'Menu', 'fontSize', 52, 'tag', 'title');
- uicontrol('units', 'normalized', 'position', [0.7 0.5 0.2 0.125], 'string', 'Identification', 'BackgroundColor', [1 1 1], 'callback', @goToInterface, 'fontSize', 12, 'tag', 'btInterface');
- uicontrol('units', 'normalized', 'position', [0.11 0.5 0.2 0.125], 'string', 'Commande', 'BackgroundColor', [1 1 1], 'callback', @goToCommande, 'fontSize', 12, 'tag', 'btCommande');
- uicontrol('units', 'normalized', 'position', [0.37 0.3 0.26 0.125], 'string', 'Tester connection', 'BackgroundColor', [1 1 1], 'callback', @goToTester, 'fontSize', 12, 'tag', 'btTestConn');
- uicontrol('style', 'text', 'units', 'normalized', 'position', [0.22 0.07 0.35 0.1], 'ForegroundColor', [1 1 1], 'backgroundColor', bg, 'string', 'N. Port USB', 'fontSize', 18, 'tag', 'textUSB');
- uicontrol('style', 'edit', 'units', 'normalized', 'position', [0.55 0.1 0.1 0.07], 'ForegroundColor', [1 1 1], 'backgroundColor', bg, 'string', '0', 'fontSize', 16, 'tag', 'editUSB');
- %Interface
- uicontrol('units', 'normalized', 'position', [0.7 0.1 0.2 0.125], 'string', 'Menu', 'BackgroundColor', [1 1 1], 'callback', @goToMenu, 'fontSize', 12, 'tag', 'btMenu', 'visible', 'off');
- uicontrol('units', 'normalized', 'position', [0.7 0.5 0.2 0.125], 'string', 'Draw', 'BackgroundColor', [1 1 1], 'callback', @draw, 'fontSize', 12, 'tag', 'btMenu', 'visible', 'off');
- uicontrol('units', 'normalized', 'position', [0.7 0.3 0.2 0.125], 'string', 'receive', 'BackgroundColor', [1 1 1], 'callback', @receive, 'fontSize', 12, 'tag', 'btMenu', 'visible', 'off');
- axes('Position',[0.1 0.1 0.5 0.5], 'color', [1 1 1], 'tag', 'axesInterface', 'visible', 'off');
- data = guihandles(gcf);
- guidata(gcf, data);
- function goToInterface(obj, event)
- data = guidata(gcbf);
- %hide old data
- set(data.btInterface, 'visible', 'off');
- set(data.btCommande, 'visible', 'off');
- set(data.btTestConn, 'visible', 'off');
- set(data.textUSB, 'visible', 'off');
- set(data.editUSB, 'visible', 'off');
- %show new data
- set(data.btMenu, 'visible', 'on');
- set(data.axesInterface, 'visible', 'on');
- set(data.title, 'string', 'Interface');
- guidata(gcbf, data);
- function goToMenu(obj, event)
- data = guidata(gcbf);
- %hide old data
- set(data.btMenu, 'visible', 'off');
- set(data.axesInterface, 'visible', 'off');
- set(data.plotidentif, 'visible', 'off')
- %show new data
- set(data.btInterface, 'visible', 'on');
- set(data.textUSB, 'visible', 'on');
- set(data.editUSB, 'visible', 'on');
- set(data.btCommande, 'visible', 'on');
- set(data.btTestConn, 'visible', 'on');
- set(data.title, 'string', 'Menu');
- function draw(obj, event)
- data = guidata(gcbf);
- data.plotidentif = plot(rand(3));
- guidata(gcbf,data);
- function goToTester(obj, event)
- data = guidata(gcbf);
- % Définition du port série
- comUSB = get(data.editUSB,'String');
- port = sprintf('COM%s', comUSB);
- s = serial(port); % Création de l'objet « s » pour y placer COM1
- set(s,'Terminator',''); % Changement du paramètre Terminator
- set(s,'InputBufferSize',8); %
- %set(s,'OutputBufferSize',10); %
- set(s,'Baudrate',19200); %
- set(s,'Timeout',2); %
- Error_flag=0;
- % Pb de warning...
- warning off all
- fclose(instrfind);
- fopen(s);
- % Envoi d'une trame STX LNG RACK CHECKSUM
- fprintf(s,2);
- fprintf(s,1);
- fprintf(s,16);
- fprintf(s,1);
- % Réception d'une trame
- [trame_recue,count,msg]=fscanf(s);
- if(strcmp(msg, 'A timeout occurred.'))
- Error_flag=1;
- msgbox(sprintf('Connection time out: are you sure COM%s is the correct Port?', comUSB), 'Time out', 'error');
- end
- % Vérification de la trame d'acquittement STX LNG ACK CHECKSUM
- Trame_type='02018001';
- % Error_flag=0;
- for i=1:count
- if trame_recue(i)~=Trame_type(i)
- msgbox('erreur de trame', 'Trame mechante', 'error');
- Error_flag=1;
- end
- end
- % Message
- if Error_flag == 0
- %disp('dsPIC33 OK !');
- set(data.btTestConn, 'BackgroundColor', [0 1 0]);
- data.portVerifie = port;
- else
- %disp('Pb de comm avec le dsPIC33 !');
- set(data.btTestConn, 'BackgroundColor', [1 0 0])
- end
- % Serial port closing
- fclose(s);
- guidata(gcbf,data);
- function receive(obj, event)
- data = guidata(gcbf);
- s = serial(data.port); % Création de l'objet « s » pour y placer COM1
- set(s,'Terminator',''); % Changement du paramètre Terminator
- set(s,'InputBufferSize',8);
- %set(s,'OutputBufferSize',10);
- set(s,'Baudrate',19200);
- set(s,'Timeout',2);
- Error_flag=0;
- % Pb de warning...
- warning off all
- fclose(instrfind);
- fopen(s);
- for i = 1:11
- % Envoi d'une trame STX LNG RACK CHECKSUM
- fprintf(s,2);
- fprintf(s,1);
- fprintf(s,16);
- fprintf(s,1);
- % Réception d'une trame
- [trame_recue,count,msg]=fscanf(s);
- if(strcmp(msg, 'A timeout occurred.'))
- Error_flag=1;
- msgbox(sprintf('Connection time out: are you sure COM%s is the correct Port?', comUSB), 'Time out', 'error');
- end
- % Vérification de la trame d'acquittement STX LNG ACK CHECKSUM
- Trame_type='02018001';
- % Error_flag=0;
- for i=1:count
- if trame_recue(i)~=Trame_type(i)
- msgbox('erreur de trame', 'Trame mechante', 'error');
- Error_flag=1;
- end
- end
- %%% recepetion donnees
- set(s,'InputBufferSize', 261);
- % % % % % % Envoi d'une trame STX LNG CMD CHECKSUM
- fprintf(s,2);
- fprintf(s,1);
- fpritf(s,208);
- fprintf(s,1);
- % % % % %
- % % % % %
- if(strcmp(msg, 'A timeout occurred.'))
- Error_flag=1;
- msgbox('Connection time out.', 'Time out', 'error');
- end
- entree=[];
- % Réception d'une trame Réponse à la requête d’échange de données STX LNG DATA ... DATA CHECKSUM
- [A,count,msg]=fscanf(s);
- entree=[entree traiterTrame(A)];
- end
- % Envoi d'une trame STX LNG RACK CHECKSUM
- fprintf(s,2);
- fprintf(s,1);
- fprintf(s,16);
- fprintf(s,1);
- % Réception d'une trame
- [trame_recue,count,msg]=fscanf(s);
- if(strcmp(msg, 'A timeout occurred.'))
- Error_flag=1;
- msgbox(sprintf('Connection time out: are you sure COM%s is the correct Port?', comUSB), 'Time out', 'error');
- end
- % Vérification de la trame d'acquittement STX LNG ACK CHECKSUM
- Trame_type='02018001';
- % Error_flag=0;
- for i=1:count
- if trame_recue(i)~=Trame_type(i)
- msgbox('erreur de trame', 'Trame mechante', 'error');
- Error_flag=1;
- end
- end
- %%% recepetion donnees
- set(s,'InputBufferSize', 201);
- % % % % % % Envoi d'une trame STX LNG CMD CHECKSUM
- fprintf(s,2);
- fprintf(s,1);
- fpritf(s,208);
- fprintf(s,1);
- % % % % %
- % % % % %
- if(strcmp(msg, 'A timeout occurred.'))
- Error_flag=1;
- msgbox('Connection time out.', 'Time out', 'error');
- end
- entree=[];
- % Réception d'une trame Réponse à la requête d’échange de données STX LNG DATA ... DATA CHECKSUM
- [A,count,msg]=fscanf(s);
- entree=[entree traiterTrame(A)];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement