Jump to content
The simFlight Network Forums

Is there a way to identify a specific controller device in the client DLL?


pbrand

Recommended Posts

I am a fresh user of the client dll. I am looking at the examples and very nice that they are there because many questions are answered by looking at them! However I could not find an answer to the following.

When using lua in fsuipc you can open a device with something like

local honeycombBravoDevice = {
      Vendor  = 0x294B -- Honeycomb Bravo vendor id
    , Product = 0x1901 -- Honeycomb Bravo product id
    , Number  = 0      -- Multiple devices of the same name need increasing Device numbers
    , Report  = 0      -- I *think* all joystick types use Input Report 0
}

local dev, rd, wrf, wr, init = com.openhid(honeycombBravoDevice.Vendor, honeycombBravoDevice.Product, honeycombBravoDevice.Number, honeycombBravoDevice.Report)

Based on the vendor and product you now have access to the correct device.

In the client dll I can use 

FSUIPCConnection.UserInputServices.AddJoystickButtonPress("Btn0", joystickNumber, buttonNumber, StateChange.Both);

Here you have to specify the joystick number. I don't know which joystick number the real device has (I'm trying to make it usable for other users with other configurations).

Is there a possibility in the client dll to determine the joystick number based on vendor/product (or some other unique identifier)?

If not, then I shall have to use a configuration file to define which joystick number to use but hoping I don't have to 🙂

Regards,
Peter

 

Link to comment
Share on other sites

Hi Peter,

Unfortunately the DLL does not have that feature. There's no way to get the joystick names from the IPC interface.

Two ideas you can look into:

1. Have your program read the user's FSUIPCx.ini file. There are lines there detailing what the joystick numbers are: e.g.

[JoyNames]
AutoAssignLetters=No
0=Controller (Xbox One For Windows)
0.GUID={363210E0-98B7-11EB-8001-444553540000}

2. Use a .net library that lets you talk to the Windows Direct Input API to enumerate the plugged-in joysticks on the user's computer.  I'm pretty sure that's how FSUIPC gets the joystick numbers.

This is an example using the SharpDX.DirectInput library, available as a NuGet package:

        private void button1_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear();
            DirectInput di = new DirectInput();
            IList<DeviceInstance> devices = di.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly);
            for (int i = 0; i < devices.Count; i++)
            {
                DeviceInstance device = devices[i];
                this.listBox1.Items.Add(i.ToString() + " = " + device.InstanceName + " | GUID=" + device.InstanceGuid.ToString());
            }
        }

image.png.5bcc974bb71053043f48b1b1fa85663a.png

Paul

 

Link to comment
Share on other sites

Further to what Paul suggests, the FSUIPC Log file contains more details, including the VID and PID IDs:

      672 Product= Saitek Pro Flight Quadrant
      672    Manufacturer= Saitek
      672    Vendor=06A3, Product=0C2D (Version 2.2)
      687    GUIDs returned for product: VID_06A3&PID_0C2D:
      687       GUID= {33BA5110-5CD5-11EB-8001-444553540000}
      687       Details: Btns=9, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R0,U0,V0,X255,Y255,Z255


plus

      719 Device acquired for use:
      719    Joystick ID = 4 (Registry okay)
      719    4=Flight Throttle Quadrant
      719    4.GUID={33BA5110-5CD5-11EB-8001-444553540000}


So the Joystick ID number can be matched up, via the GUID.

I expect it would be easy enough for FSUIPC to put the Vendor and Product IDs into two 16 WORD arrays in offsets (cost 64 bytes of offset, so that much free space would need to be found), one pair for each ID number 0-15. You'd need to post a request in the main Forum so John will see it. but, beware, only FSUIPC6 and FSUIPC7 are still in development. And John is very busy with MSFS matters (but if he agrees, I could assist with this change, at least for FSUIPC6).

Pete

 

 

Link to comment
Share on other sites

@paul

Thanks Paul for your answer! You not only say it's not possible in the client dll but also give me a possible solution on how to get the information. Much appreciated! I have no experience with joy stick programming so your example code for SharpDX is very helpful and I will have to look into that further (Google is my friend 😄). Although it's a bit unfortunate I have to use such a library since I am now using widefs client to develop because I don't have Visual Studio 2019 installed on my flight sim computer. SharpDX will of course not work (I guess) if I'm not on the flight sim computer itself...

On that same level: The Honeycomb Bravo LEDs are controlled (in the lua script I wrote) with com.readfeature and com.writefeature. I guess those commands are also not available in the fsuipc client dll then?

 

@Pete

Thanks for your additional info. It's very helpful in identifying the joystick. I think it could be very helpful if vendor/product would be available. Especially since I am using widefs client because I don't develop on my flight sim computer. I shall post a request in the main forum. I'm using FSUIPC6 🙂

 

Peter

Link to comment
Share on other sites

Hi Peter,

Quote

SharpDX will of course not work (I guess) if I'm not on the flight sim computer itself...

Correct. It's only for the local PC. If you want it running over WideFS then getting the info from the ini or (as Pete suggested) the log file would be better. You'll need the user to setup windows file sharing though.

Quote

: The Honeycomb Bravo LEDs are controlled (in the lua script I wrote) with com.readfeature and com.writefeature. I guess those commands are also not available in the fsuipc client dll then?

They aren't no.. Lua is just a programming language and you're just using a Lua library to talk to your HID devices. There are .NET libraries available for talking to hid devices. I've never done this myself so I can't recommend any, or tell you how easy/difficult it is.  

One other thought comes to mind... You already have Lua plugins that handle the Joystick/LED stuff. Are you trying to replace these with your C# program, or do you intend having a Lua component to your application? If you're going to have both, then you could set up communication between your Lua plugin and your C# program. The easiest way would be via the user offsets. This would then run over WideFS without problems as the Joystick/HID code is all on the FS PC (in LUA). You could have the LUA plugin give information to the C# program and have the C# program tell the LUA program to light LEDs etc. (Your users would need a registered version of the FSUIPC to run the LUA part).

If you're intending to replace the Lua code with C# then you'll need to replicate everything you do in Lua in C#. My DLL will only handle reading/writing offsets and LVars. For everything else you'll need to find other .NET libraries that handle the particular task.

Paul

Link to comment
Share on other sites

1 hour ago, pbrand said:

I am now using widefs client to develop because I don't have Visual Studio 2019 installed on my flight sim computer. SharpDX will of course not work (I guess) if I'm not on the flight sim computer itself...

Note that WideFS's facility to send local button presses to FSUIPC won't operate with the normal FSUIPC joystick IDs 0-15, and won't be covered by the extra information I was proposing. I assume you must at least be testing your .NET application on the FS PC?

With Visual Studio you can install a debugging server on the main flight sim PC, and still use the VS debugging facilities on your development PC to debug your program on the flight sim PC.

Pete

 

Link to comment
Share on other sites

@Paul actually I'm using a lua library provided by fsuipc. Don't know how that works under the hood and if it talks to the HID directly or via fsuipc.

I have written some lua code to operate the LEDs on the Bravo. It is my first lua attempt and it works, but I found out that I'm not a great fan of lua. No strong typed variables etc. So I decided to have a go at it with c# since that is what I do for a living anyway 😄  I then came accross your library and thought it could do everything that fsuipc could but using .net. A clear misconception at my end and alas for me it doesn't. It's a great library but I need to do additional stuff in another way it seems.

I could use a lua 'bridge' have to think about it. It would be easier but also contain lua 😎

 

@Pete

Your assumption is correct. You always test what you've done in the real environment of course. The development process itself looked easier using widefs which I purchased yesterday for that purpose. I shouldn't have done that now it seems 🤣

Thanks for the tip about the debugging server! Hadn't thought of that. Shall look into that to see if you can also debug HID calls that way.

 

Much to do and many thanks for your help Paul and Pete!

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.