LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Assigning a fixed com number to a USB port on a computer

Despite my research, I couldn't find anything worthwhile. I decided to ask here, I hope someone can help?

 

I want to permanently assign a Compport number for each usb port on the computer.
This is because; For example I have multiple usb devices connected to windows 10. These are products of the same company. Choosing a fixed com port number is wrong because they get random compport numbers. Since the devices I use are usb video capture devices, I cannot send information and compport numbering according to the information received. Therefore, in short, I need to assign fixed com ports to the usb ports on the computer.

 

 

Any opinion given is worthy of respect

Message 1 of 33
(11,423 Views)

Assuming you are on a Windows machine, Windows handles the Com port naming. Windows will keep the same com port for each device if they have a unique VID, PID, and/or serial number. Some cheaper USB to serial adapters just use a default value for those and in that case the com ports will be assigned somewhat randomly. As far as I know there is no way to assign a com port to a device in LabVIEW.

Message 2 of 33
(11,412 Views)

I don't quite understand how your USB Cameras are configured, but I think you are asking the "wrong question".  What you really want to do (I think) is "Connect to Camera #X", you know how to connect to "Com Port #Y", but you don't know how to write the function that takes X into Y (i.e., given the Camera #, which Com Port do I use?).

 

If this is the "real question", then the answer reveals itself -- before you start running your "main program" and using Cameras, you need to run a little routine that queries each Com Port, asks "Is there a Camera attached?", and if the answer is "Yes", ask "Which Camera Is It?" (you can use "Camera #0" if there is no camera attached).  Once you have this mapping, inverting it is trivial.

 

So how do you figure out which Camera is attached?  Most USB cameras adhere to some form of the GenICam specs, which include getting information about the attached camera, such as its manufacturer and serial number.  I'd think that might be a start ...

 

Bob Schor

Message 3 of 33
(11,396 Views)

thanks for your answers.

 

 StevenD wrote:

Assuming you are on a Windows machine, Windows handles the Com port naming. Windows will keep the same com port for each device if they have a unique VID, PID, and/or serial number. Some cheaper USB to serial adapters just use a default value for those and in that case the com ports will be assigned somewhat randomly. As far as I know there is no way to assign a com port to a device in LabVIEW.




I guess I'm trying to do the hard work.Yes, I know that com port cannot be assigned in labview. If there is a different method, we can apply it.


@Bob_Schor wrote:

I don't quite understand how your USB Cameras are configured, but I think you are asking the "wrong question".  What you really want to do (I think) is "Connect to Camera #X", you know how to connect to "Com Port #Y", but you don't know how to write the function that takes X into Y (i.e., given the Camera #, which Com Port do I use?).

 

If this is the "real question", then the answer reveals itself -- before you start running your "main program" and using Cameras, you need to run a little routine that queries each Com Port, asks "Is there a Camera attached?", and if the answer is "Yes", ask "Which Camera Is It?" (you can use "Camera #0" if there is no camera attached).  Once you have this mapping, inverting it is trivial.

 

So how do you figure out which Camera is attached?  Most USB cameras adhere to some form of the GenICam specs, which include getting information about the attached camera, such as its manufacturer and serial number.  I'd think that might be a start ...

 

Bob Schor


I have AHD video converter. It's not just one converter but 2 converter.

I can find out if the camera (video converter) is installed or even how many. But that's not the real problem. Which camera (converter) the compport assigned for each converter belongs to is somewhat problematic because the desired video must be displayed in the desired position.

It also makes the device naming for the converter "converter" and "converter _1".

But this is not always the same because it does this naming according to the order in which it is plugged into the computer.There may be serial numbers that can change. Devices with different serial numbers can be installed from the same product.

I think I've explained the problem a little bit.

0 Kudos
Message 4 of 33
(11,360 Views)

Try this instead

"If you weren't supposed to push it, it wouldn't be a button."
Message 5 of 33
(11,347 Views)

@paul_cardinale wrote:

Try this instead


Thanks for your answer. I've seen the example you have before. This example doesn't work very well in this regard.

I guess I can't explain the problem fully.
Let me try to explain in more detail.I have AHD converters and I want to connect them to a usb input that I specified.
For example:
usb port 1
usb port 2
usb port 3
When a video converter is plugged into either of these ports, it should get a fixed com port number. Because I am trying to create an application that works without user intervention.

I tried to explain a little in the picture below.

 

The question can be asked, why don't usb ports on computers get fixed compport numbers?

0 Kudos
Message 6 of 33
(11,322 Views)

Hello Constructionworker,

 

with this setting i doubt  you get it "foolproof". But if you insist on plugging first the converter of Camera_1 and then Camera_2, you could get it. Then you have to poll the list of attached USB ports and assign newly appearing devices in the order they are found.

Greets, Dave
0 Kudos
Message 7 of 33
(11,315 Views)

@daveTW wrote:

Hello Constructionworker,

 

with this setting i doubt  you get it "foolproof". But if you insist on plugging first the converter of Camera_1 and then Camera_2, you could get it. Then you have to poll the list of attached USB ports and assign newly appearing devices in the order they are found.


thanks for answer.

 

so,I have a question
If it is under my control, if I do the sorting myself and clone the windows 10 with these settings and distribute them to a different computer with the same features, will they have the same compport numbers on all computers?

0 Kudos
Message 8 of 33
(11,305 Views)

@constructionworker wrote:

@daveTW wrote:

Hello Constructionworker,

 

with this setting i doubt  you get it "foolproof". But if you insist on plugging first the converter of Camera_1 and then Camera_2, you could get it. Then you have to poll the list of attached USB ports and assign newly appearing devices in the order they are found.


thanks for answer.

 

so,I have a question
If it is under my control, if I do the sorting myself and clone the windows 10 with these settings and distribute them to a different computer with the same features, will they have the same compport numbers on all computers?


Nope. Maybe, very maybe, if the user also has the exactly same computer hardware. And that means EXACTLY the same. Even if you have the same model number, they nowadays can contain revisions of system boards that may actually use a different chipset with different PCI bridge configuration and hence an entirely different Plug and Pray enumeration order and then you are back at square one.

 

The solution is to enumerate the hardware (COM Ports) yourself at startup and query them for some identifying information such as their serial number and store that assignment somewhere. Then on startup do this mapping again and again every time you startup the application. In your application you are not communicating with COMx anymore but with Device1 which is assigned to be Serial Number XYZ and then you do a lookup form Device1 into your internal device management buffer, find out what COM port it currently matches too and open that COM port under the hood. With a neat little LabVIEW class this can be done very nicely and you can then create a device API that looks, feels and tastes like VISA but it is your own specific abstraction layer on top of it.

 

If your devices don't have some identification to clearly distinguish them you have only a few solutions left:

 

- Buy other hardware that does offer such a possibility

- Bite the sour apple and make the user be bothered with which COM port is which device

- Go back to DOS, there the hardware association was very strict and no Plug and Pray was trying to be helpful.

- Give up and trash the project

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 33
(11,302 Views)

@rolfk wrote:

@constructionworker wrote:

@daveTW wrote:

Hello Constructionworker,

 

with this setting i doubt  you get it "foolproof". But if you insist on plugging first the converter of Camera_1 and then Camera_2, you could get it. Then you have to poll the list of attached USB ports and assign newly appearing devices in the order they are found.


thanks for answer.

 

so,I have a question
If it is under my control, if I do the sorting myself and clone the windows 10 with these settings and distribute them to a different computer with the same features, will they have the same compport numbers on all computers?


Nope. Maybe, very maybe, if the user also has the exactly same computer hardware. And that means EXACTLY the same. Even if you have the same model number, they nowadays can contain revisions of system boards that may actually use a different chipset with different PCI bridge configuration and hence an entirely different Plug and Pray enumeration order and then you are back at square one.

 

The solution is to enumerate the hardware (COM Ports) yourself at startup and query them for some identifying information such as their serial number and store that assignment somewhere. Then on startup do this mapping again and again every time you startup the application. In your application you are not communicating with COMx anymore but with Device1 which is assigned to be Serial Number XYZ and then you do a lookup form Device1 into your internal device management buffer, find out what COM port it currently matches too and open that COM port under the hood. With a neat little LabVIEW class this can be done very nicely and you can then create a device API that looks, feels and tastes like VISA but it is your own specific abstraction layer on top of it.

 

If your devices don't have some identification to clearly distinguish them you have only a few solutions left:

 

- Buy other hardware that does offer such a possibility

- Bite the sour apple and make the user be bothered with which COM port is which device

- Go back to DOS, there the hardware association was very strict and no Plug and Pray was trying to be helpful.

- Give up and trash the project


Thanks for your answer.
Actually, I didn't think much of sticking to com port numbers.

I actually did a little test. I tried the devices I have on computers of the same version and I got an output like the one below with the same port location numbers.

constructionworker_1-1671101973201.png

The port number changes according to the port the device is plugged into. They show the same number on computers of the same version.

Can something be done with the location information here? So it's like reading the compport number in location.

0 Kudos
Message 10 of 33
(11,283 Views)