Go Down

Topic: How to detect if the board is connected to PC? (Read 1 time) previous topic - next topic

Stan09

The board is collecting data from some sensor. I want it transmit the data to PC with Serial if it is connected to PC; if there is no connection, it should switch to logging data on SD card.
How I could detect programmatically if serial connection is available?
I see there is if(serial) function that does the thing, but only for Leonardo. How to achieve something like that with Duemilanove?
There is an obvious solution for this - like, make PC to send  some response when serial bytes  arrive, and detect this response wit Arduino program; I don't want to use this approach.
There might be also a possible solution with detecting power voltage, it looks rather unreliable and also requires some hardware arrangements.
Are there any programmatically only alternatives?

PaulS

Quote
How I could detect programmatically if serial connection is available?

The data needs to be sent to some application. Make that application send a specific response to a question like "Ready?". If you get the appropriate response, within some time frame, send the data. Otherwise, log it.

Quote
There is an obvious solution for this - like, make PC to send  some response when serial bytes  arrive, and detect this response wit Arduino program; I don't want to use this approach.

Why?

Quote
There might be also a possible solution with detecting power voltage, it looks rather unreliable and also requires some hardware arrangements.

There is nothing in the USB connection, if that is what you are thinking of, that defines whether the USB connector is receiving power only, or power and there is something on the other end of the serial port. The USB to serial and serial to USB is handled by a separate chip that the Arduino can not access (for obvious reasons).

Stan09

#2
Jul 06, 2012, 07:23 pm Last Edit: Jul 06, 2012, 07:31 pm by Stan09 Reason: 1

Quote
There is an obvious solution for this - like, make PC to send  some response when serial bytes  arrive, and detect this response with Arduino program; I don't want to use this approach.

Why?

Can you imaging a generic application that just listens to serial port and handles data regardless of what device is sending it?

There is nothing in the USB connection, if that is what you are thinking of, that defines whether the USB connector is receiving power only, or power and there is something on the other end of the serial port.

If USB is connected this is enough for me to know the board is connected to PC and to start serial communications.
http://arduino.cc/forum/index.php?topic=107860.0

PeterH

Is there any way to tell whether the Serial output buffer is full? I haven't looked into how it works, but I'm guessing there's some sort of FIFO within the Arduino runtime. That might offer a way to tell whether the Serial stream is actually moving.
I only provide help via the forum - please do not contact me for private consultancy.

WizenedEE


Is there any way to tell whether the Serial output buffer is full? I haven't looked into how it works, but I'm guessing there's some sort of FIFO within the Arduino runtime. That might offer a way to tell whether the Serial stream is actually moving.


Since Serial doesn't have any handshaking, there's no way to tell if the usb chip is actually reading the stream.

Go Up