LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Writing Device Drivers... (https://www.linuxquestions.org/questions/linux-hardware-18/writing-device-drivers-506726/)

worldgnat 12-01-2006 09:41 PM

Writing Device Drivers...
 
I'm not sure if this is the right place for this post, but I'm trying to write a device driver (I'd like to write a Java class library so that it's cross platform compatible). I can get a load of hex data from a usb port sniffer, but it makes no sense to me. Can anyone recommend a good guide on device driver programming or the like? It's a diabetes management device and preliminary googling turned up nothing, so I doubt there's anything out there.

-Peter

GrueMaster 12-02-2006 03:04 AM

Why not just tap into libusb as a user app? It should get you what you need to communicate with a usb device, unless you need more realtime access to the usb bus.

Do a google search on libusb, it should turn up some results that might help.

worldgnat 12-02-2006 11:08 AM

This is using a serial to usb converter. It may work, I don't know anything about libusb or device drivers in general. I assume there's some kind of universal protocol, but I'm dealing with devices that create data and then will send that data to the computer when told to (blood glucose meters, wikipedia Glucose meter). As long as I can build a java program that will interface with the device I'll be happy. Apparently there's something called jUsb. I might check that out too. (I'm in no way saying "I get it now". I'm still lost, so anyone who has something, please tell me!)

-Peter

hiren_bhatt 12-02-2006 11:49 AM

Its not a direct help but may be of some use. On Sourceforge there are 16 name listed under "diabetes". The very first is Diabetes Management System, try that or try some other from that list, may be you find some thing.

Still if your need is to program you dont need to really write a device driver. You are right jusb will let you read data from the usb port. Now it depends how this data is formatted. If it is in plane text then you may be able to read it easily, if it is encoded in some way you need to know the exact data format used by the Glucose meter. I think it should be some thing standard but dont know what.

worldgnat 12-02-2006 12:05 PM

Any ideas on how to get jUSB to connect to the device? I'm working on it, but It's a little confusing. If I can create a new Device I can probably get it going.

Edit: Right now I'm having trouble declaring a new Device variable. Here's my code:
public ConnectMeter {
try {
Device meter = Bus.getDevice(3); //Bus is an interface
}
catch(IOExcepetion er) {
er.printStackTrace();
}
}
It keeps telling me that getDevice() can't be referenced from a static context, but it's not being refered to from a static context.

-Peter

hiren_bhatt 12-02-2006 12:10 PM

Please refer to the following link, I think it will help you.

http://www-128.ibm.com/developerwork...ary/j-usb.html

michaelk 12-02-2006 12:24 PM

What distribution / version of linux are your running?
Is your USB serial converter a seperate device from the meter and is it being recognized? The usb-serial converter will have a device ID /dev/ttyUSB0.

IMO it would make your java program easier to write.

worldgnat 12-02-2006 12:31 PM

The converter is recognized, and I'm running kubuntu (actually ubuntu with kubuntu-desktop installed, if that makes any difference). The meter actually isn't recognized by anything, on Windows or Linux, it just dumbly waits for a signal to cross the line, and then in starts spitting out data, from what I can tell. I've gotten it to compile, as per the link hiren_bhatt provided, but now it gives me an IOException and says that USB Host support is unavailable.

-Peter

hiren_bhatt 12-02-2006 12:42 PM

Make sure that paths are ok, specially libjusb.so needs to be at java_home/jre/lib/i386. Also ensure that you have the usbdevfs
virtual device mounted. Dont know if any thing else is there.

michaelk 12-02-2006 12:46 PM

All you need to do is read/write your commands using /dev/ttyUSB0 device instead of using jusb.

BTW most RS-232 devices will not send data automatically unless polled.

worldgnat 12-02-2006 01:34 PM

I've tried using /dev/ttyUSB0, but it's not a console device, so it want's straight up hex fired between devices. The ASCII output of the data it sends is litterally @........ I'll try it, but I'm not sure.... Also, where, praytell, might I find libjusb.so?


-Peter

GrueMaster 12-02-2006 01:44 PM

I agree with the others. If this is a serial device, you don't need to tap the usb interface, just open the serial port for communication. You will need to know the baud rate and packet info (i.e. 9600,8,n,1). Try using minicom to start with.

I wrote a small temperature monitoring system using a serial port watchdog timer a while back. Had the same issues when I started. Once I figured out the settings in minicom, it was easy to write a program that opened the serial port for read/write.

If you want to look at my program as a sample, send me an email. It's written in C, but it should give you an idea.

Tobin

worldgnat 12-02-2006 01:52 PM

Well, I tried opening tail -f /dev/ttyUSB0 in one konsole window, and did echo @....... >> /dev/ttyUSB0 in the other (That's one of the packets I saw in the hex dump), and got nothing. I'll try minicom, but I'm not sure how to use it. Help?

Edit: I think I figured it out. I set the serial port to /dev/ttyUSB0, then I set local echo on. I sent the data I have in my hex dump to the meter, but got nothing. It's weird....

Edit2: I just connected minicom again, and made sure that the device was on when I connected, and it gave me something like ..x.x.x.x Does that mean anything to anyone? While playing with it a bit it seems that the meter is either pinging the computer (why?!) or it's counting down for it's autoshutoff. I don't know, but they seem to be periodical. Once I shut the meter off it seems to stop.

-Peter

michaelk 12-02-2006 02:14 PM

echo "@......." > will send ascii text and not a binary character.
But that really isn't much of a problem. Writing an application to send a hex command is not any more difficult then text. Can you post some command/response examples?

worldgnat 12-02-2006 02:24 PM

Sure. Bear in mind, these were produced from the interface with the device's Windows software using a port sniffer. I can't get the device to do anything but sit there an look at me (and spit out x. when ever I turn it on). Here's the output of the sniffer (hhd usbmonitor). It looks like there are a bunch of crap packets that do absolutely nothing (the first hundred or so packets), and then there's some decent information transfer. Also, my C++ is a little rusty, so I'm not sure how to write a program to send hex data to the device. Something just hit me: I keep seeing the device send 01 60 to the computer. I'm just guessing, but I'll bet that 01 60 is .x in ascii. - Wrong. Just looked it up and x is 78. oh well...

-Peter


All times are GMT -5. The time now is 02:11 AM.