1. Serial.ew getting hung up?

I have the following whittled down version of code. Using wxEuphoria and Serial.ew. Basically a window, with a Dialog that opens when a button is clicked. Reading the serial port (USB, info from an Arduino) every second.

On the wxEuphoria side, when I show_modal(), the return is always 0. The Dialog is displayed just fine.

On the Serial.ew side, it seems that everything works fine. I can open the Dialog and (in my actual program) plot temperatures all day. The problem comes when I close the Dialog. The main window freezes and I can't even shut it down unless I go through Task Manager and End Process.

So, my first question is, what am I doing wrong with show_modal() that I never get a return value?

2nd, any ideas why the serial connection gets hung up?

--Test.exw-------------------- 
without warning 
include wxeu/wxeud.e 
include std/text.e 
include ArduinoSerialTemperature.ex 
 
export atom gw = 0 
 
----------------------------------------------------------------------------- 
-- controls 
 
export constant     
-- the window 
MyFrame = create( wxFrame,{0,-1, " ", -1,-1, 400, 300} ), 
MainWindow = create( wxPanel, {MyFrame}), 
-- timer for polling temperatures 
timer_id = new_id(), 
timer = create( wxTimer, {MyFrame, timer_id}), 
  
graph_screen_btn = create( wxButton, {MainWindow, -1, "GRAPH", 50, 100, 100, 50}) 
 
include Test.ex 
 
---------------------------------------------------------------------------- 
-- actions 
---------------------------------------------------------------------------- 
 
procedure PollTemperatures(atom this, atom event_type, atom id, atom event) 
 
sequence all_temps = GetTemperature() 
 
	--UpdateGraph()  --would like to call this only when GraphWindow is open 
 
end procedure 
 
------------------------------------------------------------------------------------------------ 
 
procedure onClick_GraphWindowButton(atom this, atom event_type, atom id, atom event) 
 
	gw = show_modal(GraphWindow)  --gw is always 0 
	delete_instance(GraphWindow) 
 
end procedure 
 
 
------------------------------------------------------------------------------------------------ 
--Event Handlers 
------------------------------------------------------------------------------------------------ 
 
set_event_handler(MyFrame, timer_id, wxEVT_TIMER, routine_id("PollTemperatures")) 
 
set_event_handler(graph_screen_btn, get_id(graph_screen_btn), wxEVT_COMMAND_BUTTON_CLICKED, routine_id( "onClick_GraphWindowButton" )) 
 
------------------------------------------------------------------------------------------------ 
 
start_timer( timer, 1000, 0 ) 
-- hand control over to Windows 
wxMain( MyFrame ) 
 
 
--Test.ex----------------- 
include Test.exw 
include wxeu/wxeud.e 
 
export constant GraphWindow = create( wxDialog, {MainWindow,-1, "Temperatures Graph", 20,20,400,300}) 
 
constant Century = create( wxFont, {14,wxMODERN, wxNORMAL, wxBOLD,  0,"Century"}) 
 
sequence extent = get_client_size( GraphWindow ) 
 
atom pxmap = create( wxBitmap, {BM_IN_MEMORY, extent[1], extent[2]} ), 
	 mem_dc = create( wxMemoryDC, pxmap ) 
 
------------------------------------------------------------------------------------------------ 
export procedure UpdateGraph() 
atom client_dc 
 
    draw_polygon( mem_dc, {0, 0, extent[1], 0, extent[1], extent[2], 0, extent[2]}, 0, 0, wxODDEVEN_RULE ) 
     
    set_font( mem_dc, Century) 
    set_text_color( mem_dc, {100,100,200} ) 
	 
	wx_puts( {GraphWindow, 5, extent[2] - 150, mem_dc}, sprintf("Return Value From show_modal() = %d",gw)) 
	 
	client_dc = create( wxClientDC, {GraphWindow} ) 
	begin_drawing(client_dc) 
    	blit( client_dc, 0, 0, mem_dc, 0, 0, extent[1], extent[2], wxCOPY ) 
	end_drawing(client_dc) 
    delete_instance(client_dc ) 
	 
end procedure 
------------------------------------------------------------------------------------------------ 
 
 
--ArduinoSerialTemperature.ex--------------- 
include serial.ew 
include Test.exw 
include std/sequence.e 
 
atom hCom, t 
 
for COM = 1 to 15 do 
	hCom = serial_open(COM) 
	if hCom != -1 then 
		exit 
	end if 
end for 
 
------------------------------------------------------------------------------------------------ 
 
public function GetTemperature() 
	 
	return serial_gets(hCom) 
	 
end function 
------------------------------------------------------------------------------------------------ 
new topic     » topic index » view message » categorize

2. Re: Serial.ew getting hung up?

evanmars said...

So, my first question is, what am I doing wrong with show_modal() that I never get a return value?

The correct way to return a value from show_modal() is to use end_modal() to close the dialog. It accepts a return value that is passed back though show_modal(). A return value of '0' is still valid - it just means the user closed your dialog manually (i.e. with the red X button in Windows). I find it best to pass the message_box() return values (wxOK, wxCANCEL, etc.) to end_modal() with my own corresponding buttons.

evanmars said...

2nd, any ideas why the serial connection gets hung up?

Are you closing serial_close()? I don't see that anywhere. It seems like that a handle left open hang the app. You could add an event handler for wxEVT_CLOSE_WINDOW and then close the handle from there.

Also, here is an example of how to better handle creating and showing a dialog dynamically, and how to double-buffer your graph bitmap: http://openeuphoria.org/pastey/254.wc

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: Serial.ew getting hung up?

Excellent. Thanks for the help.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu