Hi.
I am involved in a little problem using my modest program on Windows Vista on a NoteBook also using an USB to RS232 adapter. This adapter install a Serial Port where you dont have one and you can see it on Hardware Devices as a RS232 port in fact. It creates a COM13 port.
Here the problem, I have used WinAPI32 for my program and it has been a good experience on XP using an onboard RS232 (it is named com1 in this case) but it doesnt workon vista at all. (may be, the problem resides on USB adapter, I dont know)
Here the piece of my code where the problem arise.
The problem is that CreateFile return INVALID_HANDLE
//--------------------------------------------------------------------
idComDev = CreateFile("COM13",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
//--------------------------------------------------------------------
I have made some changes from original (which works fine on XP without USB adapter) trying with other flags, Atributes, etc.
Any Body understands what is going on?
THANKS THANKS A LOT!
People from this forum has helped me many times a lot.
ivan Perino
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That only works up to COM9. You have to use "\\.\Com13" to get it to work. Any time the number is greater than 9 or it's not a number (ComABC for instance) you have to use the double-slash-dot-slash "\.\" prefix, which in C requires the extra slashes to make the string come out right.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-11-14
An easier way is to change the assigned port number for the serial port. This can be done from device manager, select the "Advanced" button in the port "Properties" dialog. If the port says "In use" and you know it is not, ignore it, you can force the change. Changes are not shown in Device Manager until you re-scan for hardware changes or close it and re-open it, but the change is effective immediately regardless.
You may find that the port assumes a different device number for each USB socket on your machine - so either set the port for each one or always use the same port. I have found that sometimes the settings do not seem to stick through a boot cycle, but your milage may vary - perhaps Vista handles this better.
Clifford.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think it's also driver-dependent. I have two different types of USB-to-serial adapters, and one assigns a new COM number depending on which socket it goes into (but it is at least consistent - COM4 is always the one under my mouse, COM5 is in the back, etc) while the other adapter always shows up as COM7 no matter which USB socket it goes in to.
Also, I may have failed to mention this in my other post, but the \.\ thing also works for 1 thru 9, so in my opinion the easiest thing is to do something like:
sprintf(port_string,"\\.\Com%i",port_number);
That will work for all numbers, so you never have to worry about it again if you end up with a port number greater than 9.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-11-14
Good point. However it is still sometimes useful to be able to assign the port number; some applications do not allow you to select ports greater that either 4 or 8 (TeraTerm for example).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi.
I am involved in a little problem using my modest program on Windows Vista on a NoteBook also using an USB to RS232 adapter. This adapter install a Serial Port where you dont have one and you can see it on Hardware Devices as a RS232 port in fact. It creates a COM13 port.
Here the problem, I have used WinAPI32 for my program and it has been a good experience on XP using an onboard RS232 (it is named com1 in this case) but it doesnt workon vista at all. (may be, the problem resides on USB adapter, I dont know)
Here the piece of my code where the problem arise.
The problem is that CreateFile return INVALID_HANDLE
//--------------------------------------------------------------------
idComDev = CreateFile("COM13",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
//--------------------------------------------------------------------
I have made some changes from original (which works fine on XP without USB adapter) trying with other flags, Atributes, etc.
Any Body understands what is going on?
THANKS THANKS A LOT!
People from this forum has helped me many times a lot.
ivan Perino
That only works up to COM9. You have to use "\\.\Com13" to get it to work. Any time the number is greater than 9 or it's not a number (ComABC for instance) you have to use the double-slash-dot-slash "\.\" prefix, which in C requires the extra slashes to make the string come out right.
An easier way is to change the assigned port number for the serial port. This can be done from device manager, select the "Advanced" button in the port "Properties" dialog. If the port says "In use" and you know it is not, ignore it, you can force the change. Changes are not shown in Device Manager until you re-scan for hardware changes or close it and re-open it, but the change is effective immediately regardless.
You may find that the port assumes a different device number for each USB socket on your machine - so either set the port for each one or always use the same port. I have found that sometimes the settings do not seem to stick through a boot cycle, but your milage may vary - perhaps Vista handles this better.
Clifford.
I think it's also driver-dependent. I have two different types of USB-to-serial adapters, and one assigns a new COM number depending on which socket it goes into (but it is at least consistent - COM4 is always the one under my mouse, COM5 is in the back, etc) while the other adapter always shows up as COM7 no matter which USB socket it goes in to.
Also, I may have failed to mention this in my other post, but the \.\ thing also works for 1 thru 9, so in my opinion the easiest thing is to do something like:
sprintf(port_string,"\\.\Com%i",port_number);
That will work for all numbers, so you never have to worry about it again if you end up with a port number greater than 9.
Good point. However it is still sometimes useful to be able to assign the port number; some applications do not allow you to select ports greater that either 4 or 8 (TeraTerm for example).