Serial only works when Arduino Serial Monitor is open?

I’m writing a program in OSX to talk to a sketch that’s running on my Arduino Uno.

Right now the communication is very simple: I send a single byte to the Uno (‘i’), and it returns a LF terminated string identifying itself. In the serial monitor, this works just fine. In my program (using the termios library), the call to read() will hang indefinitely UNLESS the Arduino Serial Monitor is open.

If I leave this window open, my program works just fine. If I close the SM, then I receive no data back from the Uno. Does anyone have any insight into what the Serial Monitor might be changing when it opens the port for communication? Even a link to some source for the SM would be fine (I’m not sure where the SM code is within the Arduino github project).

Well I found the source for the serial monitor… but it doesn’t provide any insight, unfortunately.

github.com/arduino/Arduino/blob … nitor.java

The SM utilizes the RXTX library for Java, and merely creates a port and a callback for data received. If I want any more insight from source, I will have to dig into the RXTX library.

Hello.

I don’t think people here know too much about this, so you might be better served by asking about it on the Arduino Forums. When you say it works, do you mean the read() function in your program actually returns with the serial monitor open? If not, probably something is wrong with your code. Otherwise, does it work if you close the Arduino IDE entirely?

- Ryan

I agree with Ryan that we don’t know very much about this, but I’m wondering: when the serial monitor is open, does the read() command actually return the correct data you were expecting to get from the Arduino or does it return an error?

–David

I’ll ask on those forums. Thanks guys.

When the serial monitor is open, it behaves as expected, sending the byte and receiving the identification string.