• Advertisement
Sign in to follow this  

[.net] Getting available USB ports on system

This topic is 4143 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone I'm not sure if this question should be posted on .NET or Multiplayer forum, but here it goes. I have been developing a game with DirectX, which is intended to use several USB devices (over 20 and one for each player). I know how to load each connected USB device and use it, but the problem is that using that amount of devices creates the need to handle where a device is connected. For example, a game console like Xbox if you have connected controls on ports 1 and 4 (2 players) and you are on a select character screen, the game shows you the cursor of each player with a tag like 1p,4p or something like that. The thing is that the game loads input devices based on port number rather than device number, but if I try to do this behavior on windows, players 1 and 4 will be known as 1 and 2 and the player on port 4 (when thinking himself as 4, will be tagged with a 2 number). The problem is that when using several USB devices (sometimes 20, sometimes 10) connected to any port in any order, I need a fast method to tell the user who he is. Without this feature, I need to map each device to a player number at runtime (human work) which may take a long time (unacceptable to users). That’s why I need a game console like behavior on Windows. I'm using C# and I have tried a lot of APIs and DLLs. I'm not sure if I don't know how to use them to achieve my goal or if those tools just cannot do what I need, but some of the tools I have looked up are the following: USBSharp http://www.lvr.com/hidpage.htm#csharp - Uses Windows API functions like SetupDiGetClassDevs and SetupDiEnumDeviceInterfaces from setupapi.dll but it reads devices based on device rather than port. LibUsb-Win32 http://libusb-win32.sourceforge.net/ - If I'm right, this reads based on device rather than port. PortTalk http://www.beyondlogic.org/porttalk/porttalk.htm - Seems to be useful but i didn't see a way to use .NET with it. WinIO http://www.internals.com/ - This one seems to be even more powerful than i need, but i'm not sure if it can enumerate USB ports. I also read about getrawinput* set of functions from user32.dll but i didn't find port information. Any help or suggestions to solve this problem will be greatly appreciated. Best regards.

Share this post


Link to post
Share on other sites
Advertisement
Couldn't you just have the controller pick the player number? Like give each controller a cursor and let them pick their name from a list (like the way Smash Brothers does).

Or you could enumerate through them.

Player 1 press a button...
Player 2 press a button...
.
.
.
Player 20 press a button...

Then see which controller hits the button first, and assign that to that player number.

I don't know much about how USB works but I think will be very difficult to assign a number to each player given how many configurations of ports/USB hubs/USB devices that plug into other USB devices...

Share this post


Link to post
Share on other sites
Quote:
Original post by Stru
Couldn't you just have the controller pick the player number? Like give each controller a cursor and let them pick their name from a list (like the way Smash Brothers does).

Or you could enumerate through them.

Player 1 press a button...
Player 2 press a button...
.
.
.
Player 20 press a button...

Then see which controller hits the button first, and assign that to that player number.

I don't know much about how USB works but I think will be very difficult to assign a number to each player given how many configurations of ports/USB hubs/USB devices that plug into other USB devices...



Yes, that's similar to what I'm doing now. The problem is that there can be 20 players at the same time and it's not as easy to locate a cursor as it should be when you only have 4. I mean that if you locate yourself on the screen by moving your cursor, it's easy to identify yourself with only 4 similar cursors, but having 20 is difficult and even frustrating. I have done tests with groups of 10 people and it has become a mess, so I wanted to give each device an easier way to relate with the cursor shown on screen.

It's easy for me to assign an incremental number to a device in a per load basis, but if I have an USB hub with 20 ports and I only have 10 users connected at any port, this assignment of number may not have sense for humans. For example, if I connect the first player on port 4, the second in port 8 and so on, player on port 4 would be tagged as p1, player on pot 8 as p2 and that would be confusing for users.

The purpose of tagging a user is avoid a mapping process of device to number which would have to be done before players even touch the game. All that is to avoid confusion from players.

The only way I have found to be sure my program assigns a number to a device that would make sense with the port a player is using is to connect all devices to the hub in order one after one (10 users to ports 1-10). This way I could safely assign device 0 a tag 1 and the user who knows himself connected to port 1 would understand his cursor on screen is the cursor labeled 1.

I thought that using devices based on port should avoid me of doing such a restriction to my users, but it seems there is no other solution right now.

Thanks for your suggestions.

Share this post


Link to post
Share on other sites
I'm not sure about what it is you are deploying. But I figure this must be something you set up once, and run for an extended period of time, so how about a slightly less technical solution. Instead of identifying the port the device is plugged into, Identify the device.

Make the cursor for each player different like a letter, number, color, Symbol whatever, so long as they are distinct enough that people can quickly and easily tell them apart. Plug in all the equipment, and then physically put a tag on each controller. A sticker, or a plastic luggage tag hanging from the cord, that matches the symbols on the screen.

So it takes a few more minutes at setup time, but I think that's acceptable if you are trying to reduce the amount of time for players to figure out what controller they are holding.

I hope I am making sense.

Share this post


Link to post
Share on other sites
Quote:
Original post by zangetsu
I'm not sure about what it is you are deploying. But I figure this must be something you set up once, and run for an extended period of time, so how about a slightly less technical solution. Instead of identifying the port the device is plugged into, Identify the device.

Make the cursor for each player different like a letter, number, color, Symbol whatever, so long as they are distinct enough that people can quickly and easily tell them apart. Plug in all the equipment, and then physically put a tag on each controller. A sticker, or a plastic luggage tag hanging from the cord, that matches the symbols on the screen.

So it takes a few more minutes at setup time, but I think that's acceptable if you are trying to reduce the amount of time for players to figure out what controller they are holding.

I hope I am making sense.



Yes, you are right, it's a set up once procedure. Right now I'm using colors to identify each image. I think I'll combine colors and shapes to make identification easier. This kind of technique may improve identification time, but I’ll have to do some tests first.

Final users will be children up to 6 years old I think, so I have to carefully implement this functionality.

Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement