Get Bluetooth Devices sorted by strength/proximity - c#

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.

Related

How to control my USB port using C# [duplicate]

This question already has answers here:
Power off an USB device in software on Windows
(5 answers)
Closed 9 years ago.
What I want to write is an application that would be able to access my USB port.
To control when to charge my phone and when not to. And perhaps with time I would like to extend the application to control light bulbs, fans and the television in my room.
I want to learn how to work this out rather than just copy some line of codes and paste. I wish for a quick and very simplified tutorial on this, I would be highly grateful (small language please, You all know am still learning :-)).
The exact job I want to achieve is just to make the port send out power when needed. That is it should be switched off and on using codes if possible.
It isn't possible to change the power status of a USB port from User mode code. It's not a .NET limitation, no user application can change the power status of a USB port. Actually, I think that the power state is controlled by the chipset itself and you can't turn it off without using a specialized chipset.
Besides, if your device short-circuited, you could burn your chipset and your motherboard.
The only (safe) solution is to use an external device that will control a relay to turn power on or off for your devices.
There are multiple answers to similar questions, eg Windows- Power off a USB device in Software
A good option is to use an external device like Arduino (or Netduino), .NET Gadgeteer or any number of external boards. Prices and capabilities vary of course.
If you want to build the device yourself, you can find numerous USB relays with a simple Google search
EDIT
Regarding serial ports, there is almost no relation at all between the two port types. Serial ports are not designed to provide power. You can use tricks to use a pin's voltage to power some external device, although this will lead to problems because there is not enough current to power most devices. Burning the chipset is another likely outcome.
A USB port on the other hand, is explicitly designed to provide power through specific wires which can't be controlled normally. This is why you can charge your phone from a desktop's USB port even if the machine has shut down.
EDIT 2: Sleep-and-charge ports
As Ben Voigt noted, not all USB ports allow charging while shutdown.
There are multiple port types that support charging. Charging ports provide more current than plain ports but shut down when the computer is switched off. Sleep-and-charge ports on the other hand can provide power even when the computer is off.

simple slider with RS232 and 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.

How to detect Bluetooth activated laptops in range in Windows using C#

I'm interested in creating a wireless network of laptops using Bluetooth developed in C#.
I want to get the list of Bluetooth activated devices in range ( preferable computers, not dongles, headsets or phones). I don't think I need to use a Bluetooth adapter specific stack coz I have seen Windows searching for Bluetooth devices in range. How can I run such a search in my C# app and list the computers in range?
Please help me to do this, also let me know if my effort is wrong. Thank you.
There is a nice C# Bluetooth library available in 32feet.NET.
If you have no need for any of the additional features it offers and you wish to do the P/Invoke on your own, documentation can be found here; specifically the BluetoothFindFirstDevice and BluetoothFindNextDevice for device discovery.
Additionally, you can use windows sockets to do device/service discovery. Information on that can be found here.
If you wish to specifically filter out types of Bluetooth devices, you will want to look at the ulClassOfDevice field in the BluetoothDeviceInfo.

fingerprint reader software using C#

I am planning to verify the user input for my application using the biometric input. I did some research on net and came up with following options of biometric input:
Fingerprint
Facial Recognition
Retinal Scan
Iris Scan
Voice Recognition
Signature Verification
Out of which I felt the fingerprint as most suitable options. But the problem with this is the API of the fingerprint device will vary with its hardware. So most probably I think I will need to code against the multiple devices API, which I don't find friendly.
I intend to do the programming stuffs in C#. Is there any way out of this. As I am new to this I'm clueless. What is the way to attack this problem and how vast is the project scope and what should be my approach for this project.
The problem is not unique to fingerprint readers, it will apply to all other options in your list and many other peripherals. In fact a standard API is the exception.
So you will have to look for somebody selling a library for this or writing your own (COM and/or Interop). And rolling your own will usually not be small or simple project.
Your program will have a list of supported devices, excluding the rest.
A colleague of mine was tasked with building a biometric based staff clock-in system for the company we both worked for. We, IT, choose Fingerprints as the biometric source. He researched and used this library from Bayometric - Griaule Fingerprint SDK along with some cheap MS print readers. From what he showed me and talked about at the time, does lead me to believe that this .net library had a nice API and was easy to work with.
The biometric system is still being used today, some 5 years later.
I work in the biometric field, and I use C# for a lot of the fingerprint stuff I do. My company had to develop a fingerprint device abstraction library for this very reason. Consider that all fingerprint scanners only REALLY need one call: getImage. Knowing this, my company wrote a library which initializes and sets up each device, creates a generic wrapper, assigns a unique ID, and throws it into a big list that you can enumerate over.
Then from the C# side all you have to do is "pick" a device (all you have to go on is a unique ID and maybe a manufacturer) and then use it. The image data that comes back has to be decided on in advance so that you know what you're going to get every time
The main problem with this approach is that a lot of devices these days have various gimmicks (e.g. programmable flashing lights), and by abstracting the devices away you lost the ability to access these special abilities. Furthermore, some devices actually return multiple channels of data (various spectrums of light for example) and you have to throw away all but one channel so that the application can remain device agnostic, which is a hard decision.
Finally keep this in mind: if you do minutiae extraction, the device you use unfortunately WILL impact which minutiae are detected. Some devices are "tuned" for certain algorithms, and so enrolling with device A and matching with device B may not work at all despite having picture-perfect fingerprints.
There is a similar question here: finger print reader for .net windows forms / WPF or silverlight client
Check the links in the answers

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

Categories