Fwd: Problem with GUI / SERIAL / REALTIME.

classic Classic list List threaded Threaded
1 message Options
jonasv16 jonasv16
Reply | Threaded
Open this post in threaded view
|

Fwd: Problem with GUI / SERIAL / REALTIME.

Hi, I'm having a problem with GUI / SERIAL / REALTIME.
. After the serial is open, I can not close the serial by pressing the graphic button I created for this.
Someone there knows what might be happening. Thank you for your help.
. Below is the code.

//
// author: jonas vieira de souza
// email: [hidden email]
// date: 15/08/2017
//
// proposal: ..
//  in GUI, have ..
//      two buttons ( connect and disconnect the serial ),
//      two labels ( status and data received from the serial ).
//
// problem: ..
//
//  _disconnect_button.Callback = "close_serial";  <- NOT WORKING
//
//  After connecting,
//  when pressed the disconnect button,
//  is not being disconnected.
//

clear;
clc;

global serial;
global is_connected;
is_connected = %F;
global is_disconnected;
is_disconnected = %T;

// window background
_window = createWindow();
_window.Background = [ 0.8 0.8 0.8 ];
_window.axes_size = [ 200 400 ];

// connect button
_connect_button = uicontrol(_window,"style","pushbutton");
_connect_button.Units = "normalized";
_connect_button.Position = [ 0 0.75 1 0.25 ];
_connect_button.String = "connect";
_connect_button.BackgroundColor = [ 0.9 0.9 0.9 ];
_connect_button.Callback = "open_serial";
_connect_button.Relief="raised";

// disconnect button
_disconnect_button = uicontrol(_window,"style","pushbutton");
_disconnect_button.Units = "normalized";
_disconnect_button.Position = [ 0 0.5 1 0.25 ];
_disconnect_button.String = "disconnect";
_disconnect_button.BackgroundColor = [ 0.9 0.9 0.9 ];
_disconnect_button.Callback = "close_serial";
_disconnect_button.Relief="sunken";

// label status
_label_status = uicontrol(_window,"style","text");
_label_status.Units = "normalized";
_label_status.HorizontalAlignment = "center";
_label_status.Position = [0 0.25 1 0.25];
_label_status.String = "disconnected";
_label_status.BackgroundColor = [ 0.9 0.9 0.8 ];

// label data
_label_data = uicontrol(_window,"style","text");
_label_data.Units = "normalized";
_label_data.HorizontalAlignment = "center";
_label_data.Position = [0 0 1 0.25];
_label_data.String = "null";
_label_data.BackgroundColor = [ 0.9 0.9 0.8 ];

// ...
function read_serial()
    global serial;

    data_received = readserial(serial);
    if length(data_received) > 1  then
        set( _label_data, 'string', string(data_received) );
    end
endfunction

// ...
function open_serial()
    global serial;    
    global is_connected;
    global is_disconnected;
   
    if is_connected == %F then
        is_connected = %T;
        is_disconnected = %F;        
        serial = openserial( 2, "9600,n,8,1" );

        set( _connect_button, 'relief','sunken' );
        set( _disconnect_button, 'relief', 'raised');
        set( _label_status, 'string', 'connected' );
        
        while is_connected == %T & is_disconnected == %F then
            read_serial();
        end
    end
endfunction

// ...
function close_serial()
    global serial;    
    global is_connected;
    global is_disconnected;

    if is_connected == %T then
        is_connected = %F;
        is_disconnected = %T;
        closeserial(serial);                
        set( _disconnect_button,'relief','sunken');
        set( _connect_button,'relief','raised' );
        set( _label_status,'string','disconnected');
    end
endfunction
   

Jonas Vieira de Souza * Graduating in electronic engineering

[hidden email]

+55(48)9.9944-3117


Livre de vírus. www.avast.com.

_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev