I learned recently how PS2 game controllers send continuous updates to the PS2, with data identifying which buttons have been pressed, etc.
Having an adapter that allows my PS2 game controller to connect to a USB port, I started looking into writing a driver to allow it to control the mouse (similar to Joy2Mouse (http://atzitznet.no-ip.org/Joy2Mouse3/) ), as an exercise in understanding how it works.
I am having trouble even grasping the basics of how to access and asynchronously poll a USB device for input, and was wondering if anyone had any example code (C#) for accessing the USB device and polling its input, or could explain how it is done?
From what I can gather, I will need to use some windows drivers for accessing the USB device, but I have no experience of this, and so don't know how to do this.
Thanks for any help you can give.
Those PS2 adapters interface with the controller for you, and provide a joystick interface for you.
There are a few ways of accessing a joystick. An older method (but still works) is by using Managed DirectX. http://www.codeproject.com/KB/directx/joystick.aspx
Note that Managed DirectX is no longer released. You might try SlimDX (http://slimdx.org/features.php)
Related
I've been creating a program to play games on a computer, but the controls are on my phone.
But, I didn't know how to simulate the joystick, so I searched online.
In this website, someone said that I need to make my own device driver to simulate it, but in this website (Solution 2), it says that you could do it using Joystick Notification Messages. I looked it up, but it seems like it only supports C++, not C#.
This previous website (Solution 1) also stated that you could do it by faking an rs232 serial port, however I do not know what that means, nor do I have the tools to do it.
I used Unity for the program, so I figured, if I made a post on Unity Forum, I would get an answer. Turns out, I didn't get an answer. (link to my thread on the forum)
Is there any way to simulate the joystick of a PS4 controller using C#, preferably without external programs and device drivers, or am I stuck using vJoy or ViGEm?
Thanks in advance!
I ended up using ViGEm, which is compatible with C#. ViGEm is a gamepad emulation program for C# that supports XBOX 360 and PS4 controllers.
The reason I use ViGEm instead of vJoy is because ViGEm has simpler instructions and a forum.
I have a USB microscope camera and I would like to open the Windows 10 camera app automatically if the camera gets connected to a USB port. After checking that this isn't possible with Windows 10 at the settings level, I have decided to write a short C# program that monitors the USB ports for a camera device connection (and runs the camera display app).
As to the monitoring I haven't got a slightest clue where to begin. Needless to say that the monitoring program should be lean with respect to blocking ressources, because it would be running all the time. Can I simply obtain an event notification of USB connection? Do I have to expect problems with permissions?
And of course, suggestions for alternative approaches are welcome, if any. Note that I do not want to capture and display video from the camera myself, unless it is easier to do it that way instead of opening the existing camera app.
assuming the microscope is using the web-camera interface I would look for guides about how to enumerate and connect to web-cameras. I have found a few alternatives:
Media capture API
Aforge
Versatile WebCam
I had most success with versatile webcam, but if you just want to enumerate devices any of them should do. Aforge is probably the easiest to use.
You can then use a timer to check for devices, and do something if the microscope is connected.
If the microscope is not a webcamera you will need to refer to the camera documentation on how to enumerate devices.
I'm trying to make a joystick. The idea is that I will get an analog input from a pot by arduino I'll send the value to visual studio via serial port and finally I have to put this value as joystick analog input to the system so I'll be able to use it in the games but I couldn't find the command to do this.
I found a command like SendKey and I tried it but the result isn't what I needed. For example if I use the SendKey.Send("a") the car in the game acts fully turned to left. I want to use the potentiometer like an analog stick. If I turn the pot half way, the steering wheel will turn half way.
I think it would be definitely a better idea to implement a HID joystick profile instead handling serial data and create a virtual joystick in windows via C#. But if it is very important for you to have a virtual joystick check the vJoy project.
As I mentioned above, I would implement a HID Joystick profile. You can do that in many ways and it is not complicated at all.
For example use a Arduino board that have a native supports of joystick HID profile (such as the Teensy Boards), use a Arduino which you can modify to use a Joystick library (e.g. USBAPI) (like the Arduino Leonardo boards, instructions see here), or use a compatible bluetooth module with HID firmware, such as the RN42 HID from Sparkfun. There are several example codes for that application in the web.
I want to try add a simple slider (something like throtle on joysticks) to my computer.
The hardware part shouldn't be a problem as I can almost do anything about it. It only comes down to having some kind of driver for it.
What I have at the moment is a microcontroller and a potentiometer, which by turning the potentiometer I can transfer values between 0 and 254 to the RS232 of PC. Is this enough from hardware point of view?
Would be nice if you can give me some tips about where to look for info, what to do, and in the best case some code snippets.
So what I am looking for is to be able to present my hardware to windows as a GAMEPAD or JOYSTICK.
Thanks
The gamepad and joystick you mention are likely HID devices (if they are natively being recognized as such) - gamecontroller
Here's some information on the gamecontroller HID class
http://msdn.microsoft.com/en-us/windows/hardware/gg487464
You will need to develop a HID emulator driver which either
identifies (via some sort of unique
id obtained from querying the serial
port hardware)
or is configured as
one of the device types you mention
(gamecontroller).
You then need to translate the values coming in over the serial port to the appropriate values for the HID class you are emulating.
Here's an example in python of a HID emulation driver
http://code.google.com/p/hidemulator/
Here's a c++ example
http://examples.oreilly.de/english_examples//9780735618039/cd_contents/Samples/Chap13/hidfake/hidfake.htm
You can try to look at SerialPort class.
The most useful event is DataReceived.
Sorry that I didn't get the exact question you asked. I just used this class in my project and felt a little excited about it. I hope someone else can give you a better answer.
I am wondering if this is even possible. I want to make my own software to control the release of the shutter via the remote shutter release. From the diagrams I have seen it has a 3.3 v (no load) and a threshold voltage of 1.8v. I am wondering if I can use limit a usb cables voltage which is around 5.25v, if I am understanding correctly. Is this even possible, or do I need to look in a new direction. I am hoping to write the software in c# which I am fairly confident in.
Thank you in advance for your help :)
I've played a lot with these type of shutter remotes, for both the sony alpha and for the canon line of dslr's. For the cannon, it is usually a 2.5mm stereo plug. It has 3 contacts: ground, focus and shutter. Shorting each one of them and you will trigger that function in the camera.
http://www.doc-diy.net/photo/eos_wired_remote/
A few years ago, I designed my own circuitry that would take serial commands from the host (in my case an HP Pocket PC) and drive one of the lines down using a microcontroller GPIO port.
Nowadays there are similar devices with much easier connection and control options. And if you'd like to take the DIY road, there are very nice options such as the arduinos or if you're a c# addict, there are the netduinos.
Here's a commercially available solution, including SDK:
http://www.breezesys.com/DSLRRemotePro/features.htm
Working with USB devices in .Net is not the most straightforward task... There are no libraries in the BCL to deal with USB. However, it is possible to use Win32 API's.
This article should get you started in the right direction, as far as accessing a USB device if you want to pursue this.
As for whether it's possible, it might be... I don't rule anything out, but I think you're in for a LOT of research time to make it work if it's possible at all. (I've never seen anything in the Win32 API documentation that allows you to control the voltage, for example). However, it would be very cool if you could make it work, and the satisfaction factor alone may be worth the try.
Added
I took a look at PInvoke.net (a very good site for learning about Win32 API calls) to see if they cover power management for USB drives, and I see nothing at all.
http://www.pinvoke.net/search.aspx?search=usb&namespace=[All]#