simple slider with RS232 and C# - c#

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.

Related

Get Bluetooth Devices sorted by strength/proximity

I am trying to build a solution in C# which allows the identification of a laptop based on the Bluetooth devices around it. I hope to preferably use Bluetooth LE and have the ability to know which devices are more likely relevant by their strength.
My first idea was to use RSSI, but it seems that path is near impossible due to how Microsoft's Bluetooth Stack doesn't support reading the RSSI values. I've even looked into using Nobel with edge.js, however, that requires you to replace your Bluetooth driver entirely (making it useless for anything else) in order to support RSSI readings which is currently my last resort, as it would make it difficult for users to adopt.
However, I only really need which devices are more relevant/closer.
Is there any way I could get the Bluetooth devices in range ordered from closest to furthest in C#? Or maybe even in JS?
Thank you.

Sending an analog input to the system

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.

Polling USB Game controller device C#

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)

Use USB to activate MOSFET/Relay

I am working on a personal project involving sending simple signals from my computer to a circuit via USB. Basically I am using the USB signal as the gate signal for a MOSFET which will in turn activate a relay to turn on/off various AC peripherals. For example if I want to turn on a light bulb for 5 seconds every minute I would be sending a 1 down the first wire for the first 5 seconds of every minute.
This is my problem: I have no idea how to manually send a 0/1 down a specific wire on a USB cable, or even interact with a USB port at all :(
So I guess there are multiple parts to this question, is it possible to interact directly with the bits being sent via a USB port? If so how would I do this? I am familiar with C++ and C#, so I really hope that you can do it in one of those...
Thanks!
edit Hmm so it looks like the USB port actually only has one 5V pin so direct USB interaction wont work. Going to take a look at a parallel adapter and get back on it.
USB is a bad fit for anything that doesn't have a USB interface at the other end of the wire. If you don't want to get into building your own USB device, I'd suggest buying a USB to serial adapter, which gives you two directly-controllable output lines (the flow control lines), or a USB to parallel adapter, which gives you more than 8 lines.
Chris Johnson's answer has a link to instructions for Windows serial port programming. You'll want to look at section 7 -- the SETDTR, CLRDTR, SETRTS, and CLRRTS are your flow control line toggles (for the DTR and RTS lines, respectively).
As far as hardware goes, a "1" (SET) value on a flow control line is +3 to +15 volts on the line, and a "0" is -3 to -15. Actual voltages can vary between devices; measure it to be sure. (EDITED; I got the 1 and 0 mixed up. The control lines use the opposite convention from the data lines.)
Here are Wikipedia pages for voltage characteristics and pinouts.
EDIT: Having done some more research on USB-to-parallel adapters, I don't think they will give the needed level of control. For best results, you'll need a PCI or PCMCIA parallel card, or a parallel port built into the motherboard.
I'm not a Windows programmer, but this library might be useful for controlling the parallel port's lines from Windows.
The easiest thing to do for this application is to use serial port emulation, either with a USB-Serial cable, or with a USB-Serial converter chip (e.g. the FTDI FT232) in your hardware device.
Either way, this allows you to interact with your USB device as you would a serial port (see, e.g. here for how to do this in C++ in Windows)
Much like Chris suggested, you can get a USB slave device from FTDI. $27 at digikey will get you a small board with all the fine wiring already done.
However, for your purposes the bit-banging mode described on page 39 of the datasheet would be much better than the UART mode (UARTs generate pulses at several kilohertz, you want to have the voltage stay at the level you set it to).
Hopefully your MOSFET will turn on with a 3V signal since the FTDI will put out approximately 3.1-3.2V for a high output.
Also, make sure you use the latest drivers from FTDI... a couple years ago they had drivers (WHQL-certified even) that caused frequent BSOD, and I've often found that driver CDs that come with hardware are several years out of date.
I built something very similar to what you are doing (I was running a car window motor from a usb device, used a mossfet H bridge (the HDR1X8 on the diagram) to drive the motor.). You need a USB to I/O device this is what I used (I got a U421, they fit perfectly over the center line of a breadboard, the 401 works well with breadboards too if you don't have a split one.
They give you a dll and you just link in to it with your code. its just as simple as making a call to WriteA and WriteB for writing out to your mosfet device. Be warned logic level lines are not meant to drive current so you will need to hook this up to a transistor if you expect any kind of medium to large current flow. See App1 in the application notes of the menu on the usbmicro site to see the proper way to hook it up.
Use a USB prototype board. It usually comes with a software SDK.
Check out these links from my web site:
1.You can use a usb to serial converter. All you need to know is here
2.You can use programming to access the usb directly but for this one you have to have a driver already installed for you device. Details are here

Creating a usb time lapse for Cannon EOS Rebel XS using a c# program

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]#

Categories