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: [email protected]// 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) ); endendfunction // ...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 endendfunction // ...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'); endendfunction Jonas Vieira de Souza ** **Graduating in electronic engineering* [email protected] <[email protected]> +55(48)9.9944-3117 <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Livre de vĂrus. www.avast.com <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>. <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
_______________________________________________ dev mailing list [email protected] http://lists.scilab.org/mailman/listinfo/dev
