Go Down

Topic: arduino code for com-port (Read 410 times) previous topic - next topic

jeffreyy

Hello,

is there a command, to see in which com-port the arduino is connected to?

For example, if my arduino is connected to COM4, is there a way to get this in my arduino program?
if i do for example : test = Serial.getPort().... and that "test" takes the value of the com-port, so that "test" = "COM4".

best regards

holmes4

No. The Arduino does not know about comms ports at all let alone which comms port. Why do you need it to know?

Mark

jeffreyy

#2
Feb 19, 2013, 01:39 pm Last Edit: Feb 19, 2013, 01:55 pm by jeffreyy Reason: 1
i am making a project, and the people where it's intended for,
doesn't know what com ports are.

I communicate with a java program, maybee i can do this with the java program.

Buth i thought if the arduino itselfs know in what com-port it's in, it was verry easy.

best regards




EDIT : fixed it with my java code

Erdin


EDIT : fixed it with my java code


Tell us how you did it. It is interesting.

PeterH


Buth i thought if the arduino itselfs know in what com-port it's in, it was verry easy.


Actually, I don't see that would be any help at all since the Arduino has no way to tell anyone what port it's on unless they have already connected to the correct port.

Better would be to have the client establish a list of possible COM ports (on Windows you can look in the Windows Registry to find which COM ports the Arduino USB driver has created, or you might just try all COM ports) and implement a handshake between the client and the Arduino so that the client can ask, in effect, "Are you the Arduino I'm looking for?" and the Arduino can reply "Yes I am".
I only provide help via the forum - please do not contact me for private consultancy.

retrolefty

Quote
Buth i thought if the arduino itselfs know in what com-port it's in, it was verry easy.


Only the arduino IDE knows what com port you selected is, and even the IDE doesn't know if you told it the correct port name or not. The AVR chip is just sending and receiving TTL serial data out pins 0 and 1 with no idea if anyone is really connected or not, let alone which com port an attached PC might be using. So no, the arduino board has no way of knowing or caring and neither does the sketch when compiling know that information.

Lefty

Go Up