windows - C - get COM port number of specific device -
is there way automatically detect com port device connected on windows? 1 specific device know name or whatever need this.
right have c program, must input com port number in console e.g.:
printf("com port number?\n"); scanf("%d",&port_no); do_stuff_with_com_port(port_no); it annoying check everytime in windows device manager number device connected , want program automatically detect port number. how can achieve this?
thanks.
each physical port on machine has number doesn't change. if connect device on same port every time shouldn't need this.
but if might change port everytime, solution might work :
try open com 1
- if have error, port open else, go step 3
- if port open, move on step 2
try send message recognized device
- if receive expected answer, know it's right port.
- if don't receive (or nonsense), know it's not right com port.
- move next available com port , repeat until find it, or enumerated com ports
Comments
Post a Comment