Serial Port Question

Hi

I'm brand new to the Arduino although have worked with other microcontrollers.

My Arduino programs often hang when using print.serial when my terminal or the IDE serial monitor is not open.

This is not a surprise, actually expected behavior.

My Objective:

I would like the Arduino to be able to run in a "stand-alone/production" mode without a comm device attached.

Questions:

Is their a simple way to test and then close serial communications if no comm device is available at startup?

Is the Arduino philosophy always expected to have a comm device available?

-Thanks

irobot522: Questions:

Is their a simple way to test and then close serial communications if no comm device is available at startup?

Is the Arduino philosophy always expected to have a comm device available?

-Thanks

Q1 : I believe the state of the 2 transmission lines can be tested ? What if you transmit a character and wait for a timout, if no answer is received ?

Q2 : Certainly not. It is designed to run standalone, only reacting to your code. The comm port must be setup and initialised, before you can use it. If you dont, there is no sense in writing or listen to the port.

Thanks for the response . . .

I realize one solution is simply to not initialize the serial port at setup, and rem out all serial.print statements.

Would prefer to just do a simple check in setup/startup . . . ;)

Hardware flow control is not used so Serial.print can never hang indefinitely, it will have to wait for the bits to be sent out on the wire (to which nothing need be listening) at the currently selected baud rate.

irobot522: My Arduino programs often hang when using print.serial when my terminal or the IDE serial monitor is not open.

This is not a surprise, actually expected behavior.

It should be a surprise, and is unexpected behaviour. The arduino's job is no more than send a signal to the port. It neither knows nor cares if anything is connected to receive it. About the only way it can "hang" is when you tell it to hang until there is a response from a serial device, and it never comes because you have forgotten to connect one.

Is their a simple way to test and then close serial communications if no comm device is available at startup?

You could use

 In the event of no serial input
serial.end()

I don't think it is designed for what you have in mind, but it disables serial communication to allow the RX and TX pins to be used for general input and output. I have never seen the command used.

Is the Arduino philosophy always expected to have a comm device available?

No.

Check the first programme you are likely to have used, Blink. It has no serial commands

I have an Atmega 328 happily sending characters to the ether for the past 12 months.

It must be some other problem. Post your code.

...R