serial port / arduino / mac - closing the port

Hi,

i’m using the serial class to read data from an arduino on a mac. I have a problem that when the program hits an error and jumps to the debugger, the port doesn’t get closed and the program won’t end properly. The only choice is to reboot the computer and start again. I’ve put ‘port.close’ in the destructor, but this seems to get missed. I’ve also put try-catch code around vulnerable areas, closing the port in the catch segment but this doesn’t get called either. Does anyone know a fix for this?

thanks,

Chris

I don’t have a fix, but i can just add that its also a problem if the arduino sends to much data to fast, and of doesnt read the data fast enough… It seems like the ftdi driver is really bad, and will make the USB bus crash if it gets a overflow…

If you’re on OSX/Linux you should be able to step in and see what happens with the call to tcsetattr() in Serial.close(). That error code would probably help you figure out what’s going on. Also, the Serial close() method doesn’t check the return value of unix close(). You might try checking that to see what’s going on because, as the man page sez: “Not checking the return value of close() is a common but nevertheless serious programming error.”

Something like:

  
if (bInited){  
    		int happyClose = 0;  
			happyClose = tcsetattr(fd,TCSANOW,&oldoptions);  
    		printf("%i", happyClose);  
    		happyClose = ::close(fd);  
    		printf("%i", happyClose);  
    	}  

in the Serial::close() might help you see what’s going on. This might not help with your debug-related problem, but it could be worth a shot.