Read USB interrupt data - c#

I have a USB device which which uses the libusb WIN32 drivers and
Interrupt data is available from the
accelerometer through the USB-HID
interface endpoint 83 (in EP83). Data
is in little end-in format with the
following fields (x,y,z,Vbat,CpuTemp.)
Data are acquired every 62.5ms (16Hz).
There a number of USB HID "get" and
"set" Reports available (through ep0)
How can I access this data via .NET and C#?

libusb32 is c/c++ library of generic usb driver. it comes in 2 layers. low layer in kernel mode is generic client driver libusb0.sys + .inf file that you change and it tells to what device to upload this generic usb driver.They have inf-wizard.exe tool that helps for you to make this .inf file for your device. Upper layer in user space is libusb.lib (you can make also static link) that talks to libusb driver. You can find in sources usb.h that actually defines interface between you code and usb (usb driver). To access unmanaged code or you should write your layer of interop in c# or in c++/cli or use ready layer that been made by somebody. Here the link to one of the projects, http://sourceforge.net/projects/libusbdotnet/
How to use libusb library i advice you to see some example from them. Usually it like you open handle to usb bus, then find there your device by VendorId & ProductId, get it's handle. Then make write/read to endpoints of device.

If it is HID device I recommend you to use Windows's default driver - hid.dll, I used it and it was ok. This way you should not care about deploying also a driver, it's there anyway and you just have to understand the API and use it. For this I recommend you Jan Axelson book USB Complete, she has pretty good explanation and samples there, it is a mixture of C/C++ and C# but the trend is for .net Also she has a HID Page on her website and there you find the code samples you just need.

Related

Device Libraries for CEN/XFS

I am currently working on CEN/XFS. I have read the documentation. As far as I know, for each device (for example: Card Reader, Dispenser, Pinpad...) there is a special library (.dll) for interacting with CEN/XFS
Where can I get a library (.dll) for a specific device (for example, for a card reader)?
The dll is usually provided by the device manufacturer. It then gets loaded by the Xfs Manager.
If you are implementing a service provider for a specific device you have to implement this dll.

How to communicate with device with GPIB?

I use "82357B USB/GPIB" in order to communicate with a device with "Agilent Communication Expert".
How can I communicate with the device in C# code? What should I need to install? Which references to add? etc.
And how to diploy the application to another computer? Does the computer need some installations?
Thanks
See "Keysight IO library suit Getting started with Visa.Net C# Instrument control program"
This document describe how to build visual studio solution with visa to communicate with device over GPIB
https://keysightsales.my.salesforce.com/sfc/p/#1a000000awb5/a/2L0000009JeU/UxdJUjDDylNahqCuK6OHVbjWCycgVq7mZhTdkMgNDDI
Another important document is "Keysight IO Library Suite VISA.NET / C# Quick Reference Guide" (google it)

Assign fixed COM ports to keyspan adapters on Windows

I have an application that reads and sends data from/to 2/3 machines attached to the PC through keyspan USB to Serial adapter. Sending/receiving works well.
My problem is that on restart of the PC, the COM ports are assigned "at random", often swapped. That makes automatic processing of data impossible.
I tried to manually set the COMm ports in the Device Manager and with Keyspan assist software without success.
Questions:
how to fix COM ports on Windows so after restart they are always same?
How to assign COM ports with java/c#/powershell (get ports setting and save it(once configured), set on next restart from configuration file)?
Thank you in advance for any suggestions.
Roman
thank you very much for your help.
In the mean time I've slightly modified the solution from http://syswow.blogspot.ch/2013/03/change-device-com-port-via-powershell.html
Unfortunately my current keyspan device ID's are not stable (KEYSPAN*USA19HMAP\00_00 and KEYSPAN*USA19HMAP\01_00 and KEYSPAN*USA19HMAP\02_00), as noted before. These ID's can and often change in between restarts (I suppose as Windows is "registering" them).
I have swapped to another vendor and now I get stable ID's / COM's (FTDIBUS\VID_0403+PID_6001+FTH8ZL5AA\0000 and FTDIBUS\VID_0403+PID_6001+FTH919SZA\0000 etc.).
Thank you once again for your help.
Roman
It's not possible without special USB drivers from your vendor. I don't know who made the USB drivers for your keyspan USB, but you might send them an email asking if they offer something like this. We use Silabs CP210X drivers for usb drivers for our products and they offer a special one that makes it so the COM ports are assigned and don't change randomly when our devices are plugged in. You might try it and see, but no promises it will work with your USB.
In my experience, COM port names are stable in Windows. I suspect there is something weird about the way your USB-to-Serial adapters were implemented, or something weird about the Windows driver you are using with it.
However, given that the COM port names are not stable for you, I would suggest using libusbp. It's a USB abstraction libary written in C which can enumerate the USB devices on your system and tell you the names of their COM ports. What you would do is:
Get a list of devices using libusbp_list_connected_devices.
For each device, call libusbp_device_get_os_id. This will return a string that is something like USB\\VID_1234&PID_DA01\6&11A23516&18&0000. That string should be stable across reboots, so you would have a list of those strings in a configuration file for your software.
If you see a device whose ID matches what is in your configuration file, then use libusbp_serial_port_create and libusbp_serial_port_get_name to get the COM port name.
The library is in C, but it can compile to a Win32 DLL, and you can use PInvoke (FFI) to call functions in it from C# or Java. The library might have some minor compilation errors if you try to compile it in Visual Studio, since it is mainly used in MinGW/GCC/clang environments. You should be able to fix those errors and/or report them as issues on GitHub.

Write/Read file in my iPhone app Shared File

I wrote an app on my iPhone. It's a more portable and smaller version of my pc software. I activated the File Sharing feature on my app so now I can transfer files through iTunes. But I want my pc software to be able to read or write files to that shared folder on my iPhone without having to do it manually through iTunes.
I have big constraints:
I can't use a Jailbroken iPhone/iPod/iPad
The vast majority of my customers don't have Internet access (It's a farm management software so even cellular are not available in some area)... :(
I heard there is a way using Manzana and MobileDevice.dll (itunesmobiledevice.dll). I don't really know how to use these dll. I tried to use Manzana a little but I can't access my folder since it's not a jailbroken iPhone.. Can someone help me with a little bit of code example?
Or is there other ways to make my iPhone app communicate with my C# application using the USB cable without internet access or Wifi?
mobiledevice.codeplex.com. This project should let you send and retrieve files from the phone
I'd suggest seeing if you can use the iTunes scripting interface. Add the COM reference iTunes 1.1 Type Library to a project and you can control many parts of itunes automatically. I can't find the documentation for it, but you can play around with the library and see if there is something to access the file sharing section.
Here's a decent introduction to using it:
http://www.codeproject.com/Articles/7723/Controlling-iTunes-through-COM

How to access an OPTICAL block device directly under Windows

The question is similar to How do I read a disk directly with .Net?, except that the drive that requires direct access is a CD-ROM or DVD-ROM drive. These drives are not including as a physical drive and cannot be accessed using the DeviceStream class or CreateFile Win32 API method as cited in the topic above.
The Windows kernel automatically creates the internal device markers for various attached block devices. The first CD-ROM drive appears as \Device\CdRom0, though attempting to open this via CreateFile() will fail (apparently per http://support.microsoft.com/kb/235128).
Considering unmanaged applications can access these block devices natively (any CD-burning software, DD for Windows, Cygwin [via /dev/scdN]), is there a programmatic method available to access these block devices (preferably usable by .NET)?
You may want to look at this article
This is what I used when faced with an issue of making backups to CD's

Categories

Resources