Pages: [1]   Go Down
Author Topic: arduino code for com-port  (Read 332 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 25
Posts: 1872
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Mark
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 19, 2013, 07:55:28 am by jeffreyy » Logged

Offline Offline
Edison Member
*
Karma: 57
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

EDIT : fixed it with my java code

Tell us how you did it. It is interesting.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11138
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: