Go to Post Is any robot ever actually done? - BlondeNerd [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 25-01-2003, 00:17
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
CloseHandle Error!!

I am using Rob's serial port method in Dashboard3D and everything is working well (I'm about half done) but when I go to close the port, the CloseHandle function never returns! The code is as follows:

HANDLE hSerial; //Opened in the constructor with CreateFile, etc.
CSerial::~CSerial(){CloseHandle(hSerial);}

I have debuged it up to that point so it does get to the CloseHandle function but it never passes. It took me two days to even figure out why the process wouldn't end in WinXP! Any suggestions? (I don't want to "just leave it open"...)
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic
  #2   Spotlight this post!  
Unread 25-01-2003, 00:26
jeremy562 jeremy562 is offline
Engineer
#0562 (SPARK 562)
 
Join Date: Feb 2002
Location: Fitchburg, MA
Posts: 74
jeremy562 is an unknown quantity at this point
Send a message via AIM to jeremy562
I've never heard of CloseHandle() not returning... is hSerial a valid handle? It hasn't already been closed? Are you 100% sure?

Other than that (an invalid handle), the only thing I can think of is that the file is still in use (being written to by another thread?) so the handle can't be invalidated.
__________________
SPARK 562: Students Pursuing Applied Robotics Knowledge

2006 BAE Granite State Regional: Finalists with 319 and 176
2006 BAE Granite State Regional: Winners of Motorola Quality Award
2004 BAE Granite State Regional: 7th Seed
2004 Mayhem on the Merrimack Champions! Thanks, 61 and 1289!
  #3   Spotlight this post!  
Unread 25-01-2003, 10:34
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
It is definately a valid handle (I checked for an address in debug) but the app does use multithreading to read from the port. I wasn't sure how to close the thread.

void SerialThread(PVOID pvoid);
_beginthread(SerialThread,0,NULL);
<--In the CSerial constructor

I figured I would use _endthread() but then I realized that there is no way to tell it what thread to end. Even though there is only one thread running, I would like to be able to end a specific one and not all in general...
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic
  #4   Spotlight this post!  
Unread 25-01-2003, 10:40
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
An update on the problem:
It appears that it isn't just the CloseHandle() that won't return. I tried to do _endthread() before it and that wouldn't return either. I think it has to do with my class deconstructor. These calls are in there and they are not working... Any ideas?

CSerial::~CSerial(){_endthread();CloseHandle(hSeri al);}

PS: Also, if anyone knows why this upper line (the code) seems to be splitting about half-way through the page width, please explain. The rest of this message spans fine...
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic
  #5   Spotlight this post!  
Unread 25-01-2003, 17:45
illumanat'i's Avatar
illumanat'i illumanat'i is offline
make me care
#0555
Team Role: Student
 
Join Date: Jan 2003
Location: New Jersey
Posts: 110
illumanat'i is an unknown quantity at this point
Send a message via AIM to illumanat'i
adam, are you sure you didn't press enter?
__________________
Trust, Love, and Magic
  #6   Spotlight this post!  
Unread 25-01-2003, 20:39
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
You have to call _endthread from within the thread you are trying to end. Also, nothing will execute after an _endthread() as it functions very similarly to a "return".

If you want to avoid multi-threading, download RoboCon from my website and look through its source. It uses the built-in timeouts to accomplish a very similar thing to multithreading.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #7   Spotlight this post!  
Unread 25-01-2003, 20:52
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
I'll try using a bool to check if running and, if not, I'll use _endthread(). I actually don't mind multithreading. It was just starting with it that took some getting used to. I got the program to get input today but it seems to be giving me strange numbers... Example: the p2wheel variable goes from -2 to -127 (up to mid-way) and then from 127->2 (mid-way to down).. I have no clue...
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic
  #8   Spotlight this post!  
Unread 25-01-2003, 22:36
Ryan Meador Ryan Meador is offline
Registered User
#0190
Team Role: Electrical
 
Join Date: Jan 2002
Rookie Year: 1999
Location: Worcester, NH
Posts: 68
Ryan Meador will become famous soon enough
*unwraps a hermetically sealed project from ages gone by*

I believe the function you're looking for is TerminateThread(). It's a bit inelegant, but it works quite well It's first argument is the thread handle, and the other I'm not quite sure of... passing zero accomplishes my goal, but I can't remember what it does.

*mothballs his old MUD source code again*
__________________
-Ryan

"You're not a real programmer until you end all your sentences with semicolons;"
  #9   Spotlight this post!  
Unread 29-01-2003, 19:02
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
I finally got it to work using _endthread() but if anyone can help me here, please do. I need it...
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic Run Error BBFIRSTCHICK Programming 10 02-04-2003 22:43
EMERGENCY! EPROM FULL error?!? CHSguard72 Programming 2 05-03-2003 20:51
Basic Init Error yan184 Programming 5 14-12-2002 13:10
Basic Run Error Ulibrium Programming 12 21-02-2002 01:02
programming error agenova Programming 1 20-02-2002 13:00


All times are GMT -5. The time now is 04:00.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi