[Stealth] put together a post explaining how he writes drivers for input peripherals. He’s using Python which makes the process fairly painless (we’ll get to that in a minute) but the value of his post is in the explanation surrounding how to interpret the data. Once you know how the communications are coming in from a device you can write the driver using any language you want. [Stealth] wrote in to let us know about this post after reading the PlayStation 3 Sixaxis controller sniffing hack. He’s pretty much doing the same thing but the background information is much more bountiful.
There are a couple of prerequisites to the process. First, [Stealth] is working in a Linux environment. That’s not to say you couldn’t do this on another OS, but you’re going to need to do some research to find out how to tap into the data stream from the device. Secondly, the input you are working with must already be set up and working on the machine. That means if there isn’t any support at all for the peripheral (in this case a USB joystick) you’re not going to be able to sniff the commands. That being said, a short Python snippet is all you need to dump the raw data coming in from the device. With data in hand it’s time to do some pattern hunting. As you start to figure out the size and scope of the incoming packets you can try out your own code to make sure you’ve got it right. Check out the demo video after the break which features a joystick button mapper written in Python.
[youtube=http://www.youtube.com/watch?v=WYaSHPWjU_E&w=470]
If you want to develop Python drivers for peripherals which are not support at all, try PyUSB: http://pyusb.sourceforge.net/docs/1.0/tutorial.html
I wrote a driver for my bluetooth obd2 dongle in bash. You can use any language.
I built one of those for a tv remote, but it looks like I used struct.unpack to unpack the buttons into integers rather than reading them as characters. Pretty cool, I’ve not seen very many other examples of Python drivers.
This is not a “driver” as it operates in userland and nor in kernel space…
In Windows at least, there are both user-mode and kernel-mode drivers — just because it doesn’t touch the kernel doesn’t mean it isn’t a driver! I’d imagine it would be the same for *nix systems too — there are aspects of a driver that do need the nitty-gritty OS to do the dirty work (Kernel), but then you just need to do some parsing, formatting, etc. that can be done anywhere (User space).
Always good practice to separate the two, you don’t want to throw bugs into the kernel-side of things!
This guy did something like this: http://www.engenhariadequintal.com/2011/03/usb-device-drivers-em-python-parte-1.html
He`s trying to control some bogus usb-to-parallel port adaptor
very nice!!
Anyone have a copy of the the article? Getting a 404 error when trying the link.
Try the Internet Archive’s Wayback Machine. It has it.Here’s the link.
http://web.archive.org/web/20110612181604/http://www.stealth-x.com/programming/driver-writing-with-python.php
We are not able to recieve patient’s record lab test result done by machine data from the Cobas c311 blood test biochemistry Analyzer (Following ASTM Protocal ) to seperate host machine(pc )using rs232 port .I thing we require one driver program for reading ASTM message coming from analyzer. Now the problem is just to dump the complete ASTM messages (from the Analyser to host) in a single file , ‘automatically’ i.e without user intervention. From that file we can extract out necessary information.
1) Setting the serial port parameters i.e baud rate,parity,stop bits etc.
2) Wait for the data to come, receive it and dump it in a file in real time.