how find program has device driver - api

how can i find whether a program has device driver or not (or know program run in ring0 or ring3)
i need function(api) for this in c# or c/c++
like regmon it has device driver
thank

Is it Windows?
(Disclaimer: I have no experience with drivers. I'm just finding information from Google)
To find out whether a certain piece of code actually runs in ring0, you will need a kernel mode debuger, like WinDbg.
To find out whether a certain ring3 program communicates with a certain driver, use SysInternals Process Explorer and see if the ring3 program opens any files that says "\Device\something"
http://social.msdn.microsoft.com/Forums/en/Vsexpressvc/thread/5bc594a5-b593-4368-a2b3-31cc5f4a7ddb
http://www.microsoft.com/whdc/resources/default.mspx
Link

Another sign that a program uses a device driver is that if it imports/invokes the DeviceIoControl Function.

Related

USB communication with Python (Newport Instrument)

I´m currently trying to make USB communication to the laser controler TLB 6700 (New Focus - Newport) with python.
https://www.newport.com/f/velocity-wide-&-fine-tunable-lasers
This is my first python task, and I´ve been having several troubles. So, by steps:
1) This device has its own drivers, and a comercial software to control it. However, I would like to develop my own code to perform several automation procedures.
2) The newport drivers are not NI compatible. This mean that I can not use PyVisa to recognise the device if I´m using the Newport drivers.
3) I think I can not use PyUSB too, for the same reasson. Even I´m not totally sure about that.
4) A solution that I´ve found is to use the NI-Interactive control to install a secondary NI driver for the device. Following this procedure I can recognise the device with PyUSB.
5) However, I do not understand how to activate the device and to send commands. I guess that the correct procedure is something like:
5.1: Call a library. Newport provides diferent libraries and dllwrapers. I´m asuming that the correct procedure is to use Ctypes to call the primary device dll. This will lead the possible instruction call.
5.2: Recognise the device as I´ve done with the NI driver and thorugh PyUSB.
5.3: Open the device and send command through PyUSB code.
So, here my questions:
PyVISA seems much easier to use than PyUSB. Any of you know a procedure to do the same but with PyVISA?
Any of you have done similar procedure with Newport devices, or even with the same TLB 6700 controller?
Thank you in advance,
Cheers,
It might be a bit late but just in case, I developed a python code to control a TLB 67xx. You could find it in my github.
Basically I call the dll through (UsbDllWrap) python net (import clr) and use it to set the wavelength, start a scan , etc... I do have several decorator that you could dismiss (#InOut.output for instance). You might need to adjust the path of your dll, if you do not use Anaconda for python. That is the only decent way I found to control the NewFocus laser, as it will not be possible to control them through PyVisa.
Obviously, doing so it is only possible on Windows.
I am still working on a cross platform solution that could be suitable for Linux

Talk to an USB HID device from within GNU Octave

I need to control a measurement instrument from within GNU Octave. The instrument has an USB HID interface. I just need to read or change the settings of the instrument. It's not about getting measurement data from the instrument.
What options are there to do this from within GNU Octave, and how do they work?
The simplest approach would be to use an already made Octave package (like the instrument-control package). Then you could check the documentation and read /write to and from a USB device.
The package linked above (and here again) has a USB TMC set of functions if the USB device works with this library. See the function list to find out how to use the package. As far as I am aware this package only works on Linux for USBTMC (according to the wiki).
Otherwise if you are not running Linux, or the device is not supported, I cannot specifically see any other already-written set of Octave functions for communication.
However, if you have the time it could be worth writing just a singular MEX (C/C++) function to open the communication channel and read settings from the device.
You could then make this work on Windows as well. Most of this functionality is already implemented in libraries such as signal11 (just to name one...), which that library itself is already cross-platform. Using that library inparticular makes it look like a very short MEX file to write.
I hope this helps and check out the links for further information about the topics discussed :)

ISA port communication with Visual Basic

Is there any chance how I could write something to ISA card in Visual Basic .Net for Windows XP and higher? (I know Win XP and higher have restriction so U cant directly write data to port)
I have also done some research and if I understand the situation I have only 2 options:
Write driver (very problematic option :)) or
Try to use existing driver in kernel32 like driver to serial/paralel port.
If there arent any other options, how I have to modify "using of serial/paralel port" to use it for ISA port?
Modern versions of Windows will not allow direct port I/O from a user application. Your program is running in Ring 3, not Ring 0. You need some kind of driver to do the port I/O on your application's behalf.
The first thing to do would be to contact the card manufacturer and see if they made a Windows driver for your board.
If a Windows driver is not available, and you are only looking to do basic reigster reads and writes (no interrupts or DMA), there are some freely-downloadable libraries that you can download to do port I/O. Basically, the library includes a dummy "driver" that sits in Ring 0 and does the I/O for you. I have the most experience with WinIO.
WinIO has a C/C++ API, nothing .Net/CLR. You will need to use P/Invoke to call the WinIO functions from managed code.
If you search around, you may find a toolkit similar to WinIO that provides APIs for managed code. (Edit: Here is one I have bookmarked called DirectIO.)
The biggest problem with WinIO is that you are limited to basic register reads/writes. If you need interrupts or DMA, you are out of luck. At that point, you will need to write a "real" driver.
Writing a driver can be a pretty major task for the uninitiated (there is a lot you will screw up). You will need to start by getting a copy of the Windows Driver Kit, and studying Microsoft's Kernel Mode Driver Framework. You could also look into purchasing a copy of Jungo WinDriver. WinDriver is a third party tool that simplifies driver development considerably, but it is quite expensive for a one-off project.

How can I debug a USB HID device that does not come with a driver?

I have a single button USB controller, but it did not come with any drivers (simply a Windows program that communicates with it directly for its intended purpose).
USB Fidget
Vendor ID: 0x1d34
Product ID: 0x0001
Product name: DL100A Dream Cheeky Generic Controller
So, I would like to be able to read whether or not the button is being pressed. My main development environment is Mac, but I'd like the solution to run on Windows too. So ideally a cross platform solution would be best.
I can find pieces of code for other devices by the same manufacturer but there are differences in Product ID so the code does not work and I lack understanding to change anything other than the vendor/product.
As far as I understand it I need to poll the USB device with a feature request packet?
Is there some software I can use to "watch" the USB device so I can see what is actually happening when I press the button? If not, how would I go about writing some myself?
basically on MacOs very huge amount of usb devices work through IOUserClient. This standart class provide to user mode programs ability to control device without kernel mode driver (by using usermode part of IOKit framework). To sniff for usb packets you can use USB Prober, start from this article http://developer.apple.com/library/mac/#qa/qa1370/_index.html
On windows standart way - standart USB driver + standart HID driver, no need in specific vendor driver if they not develop some additional functionality over standart. You can use any of commercial or freeware tools to sniff usb packets - like this one http://www.hhdsoftware.com/usb-monitor
I don't know of any cross platform way to handle it. This is the presentation I point people to for how to create a driver app for a random piece of HID hardware:
https://developer.apple.com/videos/wwdc/2011/?id=207
For testing / accessing HID devices, i.e.
Get Feature Report (matt's original question)
Sending Feature Reports
Sending Output Reports
Receiving Input reports
I'd suggest the "HIDAPI Test Tool" / "testgui" included in the great cross-platform HID library from signal11/hidapi.
On Windows you require an additional 3rd party package to compile the testgui application, but it was pretty easy and the GUI tool was more straightforward that other code examples and tools I saw. (I could cross-check if I am maybe allowed to publish a VS2008 compiled version of this.)
Another free option for sending output reports and receiving input reports, is our own "Docklight" tool (in evaluation mode, unlimited time, just no storing), see Docklight Scripting HID USB.

How to make a library for the webcam?

I'm learning Factor and I thought it would be great to have a small program to capture images from the webcam that comes with my mac pro. I know every webcam will be very different but sounds like something I should be able to do. I want to create a library with support for Mac, Linux and Windows. The problem is that I'm not sure where to start.
Factor-based answers are welcome but I'm looking for the language agnostic solutio. When I google for it, all I get is programs that capture images. I want to learn how to interact (in the 3 big operative systems) with the drivers I guess.
I think the only clue I have is the ioctl wiki page. How would you start such a project? What kind of google keywords would you use? Books?
It's not clear if you want to write a driver for your particular webcam or a library that makes talking to the existing driver easier.
If you want to write a driver for your webcam, you probably want to investigate libusb for Mac and Linux and libusb-win32 for Windows. You would need to understand the protocol that your webcam talks, though. You could probably read the source code for the existing Linux driver (assuming there is one, which is pretty likely).
As for Google search terms, you might try "video capture" and maybe looking for Python/Ruby etc. code or Open Source programs will get you code you can look at to see how to do what you want to do.
Perhaps if you describe in a little more details what you're trying to accomplish someone could give you better suggestions.