OSX: serial port crash / force closing of serial port

I’m doing a project where I’m controlling a pan-tilt servo set [1].

As a step in the process I’ve got an Arduino controlling the pan-tilt servo set based on values coming from my program and it works, but the Arduino stops doings it’s thing after a little while, which is fine in the big scheme of things, something is wrong somewhere so I just have to find it.

What is slowing me down somewhat is that I have to restart the mini-mac I’m working on each time this happens.

The program itself never closes, waiting for the serial port/Arduino I assume, and I can’t launch the program a second time obviously. (it also crashes XTorrent for some reason)

I’m using 0.06 on OSX Leopard and in this case I’m connecting to an Arduino NG with the ATmega 168 (although I’d have to double check and it’s at home)

on baseapp::exit() I am calling serial.flush() and serial.close(), I wasn’t before and had the same problem.

Has anyone experienced this before, if so did how did you manage it ?

Failing that, does anyone know of a way to force a serial port to close, from the terminal for instance?
I’ve been Google’ing, but I’m not a Unix/Linux expert so I might be missing a trick.

The Arduino code is below:

#include <Servo.h>   
Servo myServo1;  
Servo myServo2;    
int servoVal1 = 0;  
int servoVal2 = 0;  
void setup()   
  myServo1.attach(9);  // attaches the servo on pin 9 to the servo object   
  Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps  
void loop()   
  // send data only when you receive data:  
  if (Serial.available() >= 2)   
    // read the incoming bytes:  
    servoVal1 = Serial.read();  
    servoVal2 = Serial.read();      
    myServo1.write( servoVal1 );   
    myServo2.write( servoVal2 );       
    delay( 11 );     
    Serial.print("Servo vals: ");   
    Serial.print(", ");       
    Serial.print("."); // ask for more data  
void establishContact()   
  while (Serial.available() <= 0)   
    Serial.print(".");   // send a starting message  



[1] http://www.flickr.com/photos/hahakid/3707889112/

In case anyone had a similar problem or lands here via Google, I think my problem was related to the fact that I was using Serial.print(…) in my Arduino code, but not picking it up in my OF program (it was there from some earlier debugging). Maybe a buffer was filling up on the Arduino or something similar.

So far so good.