Read data from an USB-GPS-Receiver - c#

I'm wondering how difficult it is to read positioning data from an USB GPS Receiver (also known as "USB Mouse"). Is there some kind of ready-to-use API in .NET (like it is in mobile platforms like Android/WP7 etc.) which works because the GPS device's driver integrates much into Windows or is this some annyoing pinvoke stuff that depends on the GPS device?
Any experience?

Typically a GPS device shows up as a virtual com port. You should see it listed in com ports in the device manager. Nearly every GPS sends data to the computer using standard NMEA 0183 messages, you just need a library to read them. One really nice full featured one is DotSpatial, the DotSpatial.Positioning library should automatically find your gps and report data from it.

You may have to and your equipment supplier contact, and obtain recognition equipment driver, and call the API for communication equipment. If you can get from a GPS device on bytes, closer to success is just around the corner, and the rest is packaging and analytical data packets. PS: if is serial communication, realizing in DONET is more easily.

Related

How to print document to Bluetooth printer from windows mobile 5 in C#

I am new to windows mobile development and searching for how to print document to Bluetooth printer using C#.Net. I have go through some blogs but not sure from where to start.
Below are the some information I found
Zebra provides an SDK for Windows mobile which has many examples, short sample applications, and even a demo utility. You just simply call the APIs provided and the SDK will make the proper connection to the printer via Bluetooth (or TCP) for you.
- But I am not sure whether its free to use?
Please help me to find better option for printing on bluetooth printer from windows mobile device.
Thanks in advance
-Nitin
Using the Zebra SDK is free. It is a fast an easy way to use there printer on windows mobile. But you are stuck to Zebra (if you ever change the printer vendor that might be an issue) and what there SDK provides.
You can go the free way and start your own printing lib and have full control over the code:
Before you can start printing, you need a connection to the printer. For Bluetooth you can use other free SDKs (with free source code) like inTheHand (32feet.net).
Further on you have to start learning the Zebra printer's language. That may be, for example, ZPL. You need to send commands to the printer to get something out.
Bluetooth printer can be connected to Windows Mobile (WM) by using a socket or a virtual COM port.
Starting with virtual COM port is an easier approach, just call registerDevice with the right args to get back a new virtual COM port you can use to communicate with the printer. A problem may occur, if the printer requests a PIN. I did not yet find a native way to set this PIN from code and used 32feet libs to overcome this.
You may also use TCP/IP socket programming to communicate with the printer. If the printer is already paired with the WM device, it is an easy task: https://github.com/hjgode/btprint using a lot of MS BT API.
If you are not familar with printer languages like ZPL, ESC/P and need to print text only, you may consider using the commercial PrinterCE SDK. It frees you from knowing all the bits and bytes of printing languages.
You can find some demo BT/VCOM printing code at http://code.google.com/p/win-mobile-code/source/browse/#svn%2Ftrunk%2FCommAppCFbtSearch%253Fstate%253Dclosed (CommApp... folders).

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.

Send/Receive WiFi traffic data

Is it possible to monitor WiFi traffic and send data myself? My goal is to learn how to monitor probe requests, send deauth packets, and other operations similar to AirCrack and the other libraries found on the BackTrack os flavor.
You might have a tough time doing what you want to do in a Windows environment. If you poke around the Aircrack site a bit you'll see that the Windows version is pretty useless in comparison to its Linux counterpart, in large part due to the open source driver availability in Linux and the lack thereof in Windows. You can definitely packet sniff etc. ( http://www.codeproject.com/Articles/12458/SharpPcap-A-Packet-Capture-Framework-for-NET ) but you won't get the robustness that you can get out of a similar application in Linux.
I don't know about sending just random radio signals, but you can certainly monitor the traffic and data. Here is an article which describes how to do it.
AirPcap from Riverbed. USB adapter that can run in monitor mode and has an API for channel switching and more, and you can send Wi-Fi frames if you buy the right adapter. Wireshark has builtin support too. The Alfa cards are a good choice, but only for 'nix

How to differentiate between USB device types?

Having read up on this question regarding working with USB devices, I got to wondering what method is being used by the operating system to differentiate between types of USB device?
For example, I can plug in a USB mouse and the computer "just knows" it's a mouse. If I plug in my 1GB USB drive it "just knows" it's 1GB's worth of removable storage.
What sort of code is being used by the device to 'announce' what type it is? Or is the operating system polling the device and getting some standardised response?
How would I program a device to identify itself as, say, a keyboard?
In order to build a device that works over USB, you will almost certainly have to read the USB specification available from http://www.usb.org/developers/docs/
In regards to your specific question, there are GET methods associated with various standard USB variables. These are stored in the firmware of the device and provided when requested. Eg, GET_DESCRIPTOR, GET_STATUS etc are request types that can be sent to the device.
USB has its own set of protocols that would be quite a task to implement in their entirety, so most device manufacturers buy a USB controller chip from some third party.
If you're just interested in hacking something together, then I think the specification will be enough to get you sending a few packets.
The only other option I can think of may not be suitable for your project; wire-tap a real keyboard, let the keyboard to all the complicated address resolution and device identification etc, then just have your device push data onto the wires as and when.
This is something I have managed before when I build a keyboard black-box for password sniffing at high-school, the black-box stored keypresses then regurgitated them onto the wires as if it were a keyboard. Once it had stored a few passwords, and I retrieved it, I had to plug it in attached to the keyboard, then unplug the keyboard before setting it to output the keypresses (with a handy gedit window open :P) otherwise the keyboard would interrupt the transmission with its own data.
The type (or rather, the device class) is determined by reading the device's class from the device's device and interface descriptors. You may want to read this segment about USB device descriptors from USB in a Nutshell for information. (I also recommend reading the whole thing, if you're interested)
In Device Manager open the properties of a device and select the Details tab. The various values give the information (or rather is generated from the information from the device and its driver).

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