LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 12-01-2006, 09:41 PM   #1
worldgnat
Member
 
Registered: Oct 2004
Posts: 337

Rep: Reputation: 30
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
 
Old 12-02-2006, 03:04 AM   #2
GrueMaster
Member
 
Registered: Aug 2005
Location: Oregon
Distribution: Kubuntu.
Posts: 848

Rep: Reputation: 30
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.
 
Old 12-02-2006, 11:08 AM   #3
worldgnat
Member
 
Registered: Oct 2004
Posts: 337

Original Poster
Rep: Reputation: 30
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
 
Old 12-02-2006, 11:49 AM   #4
hiren_bhatt
Member
 
Registered: Oct 2005
Distribution: FC3,Debian
Posts: 127

Rep: Reputation: 15
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.
 
Old 12-02-2006, 12:05 PM   #5
worldgnat
Member
 
Registered: Oct 2004
Posts: 337

Original Poster
Rep: Reputation: 30
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

Last edited by worldgnat; 12-02-2006 at 12:13 PM.
 
Old 12-02-2006, 12:10 PM   #6
hiren_bhatt
Member
 
Registered: Oct 2005
Distribution: FC3,Debian
Posts: 127

Rep: Reputation: 15
Please refer to the following link, I think it will help you.

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

Last edited by hiren_bhatt; 12-02-2006 at 12:11 PM.
 
Old 12-02-2006, 12:24 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,751

Rep: Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929
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.
 
Old 12-02-2006, 12:31 PM   #8
worldgnat
Member
 
Registered: Oct 2004
Posts: 337

Original Poster
Rep: Reputation: 30
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
 
Old 12-02-2006, 12:42 PM   #9
hiren_bhatt
Member
 
Registered: Oct 2005
Distribution: FC3,Debian
Posts: 127

Rep: Reputation: 15
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.
 
Old 12-02-2006, 12:46 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,751

Rep: Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929
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.
 
Old 12-02-2006, 01:34 PM   #11
worldgnat
Member
 
Registered: Oct 2004
Posts: 337

Original Poster
Rep: Reputation: 30
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
 
Old 12-02-2006, 01:44 PM   #12
GrueMaster
Member
 
Registered: Aug 2005
Location: Oregon
Distribution: Kubuntu.
Posts: 848

Rep: Reputation: 30
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
 
Old 12-02-2006, 01:52 PM   #13
worldgnat
Member
 
Registered: Oct 2004
Posts: 337

Original Poster
Rep: Reputation: 30
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

Last edited by worldgnat; 12-02-2006 at 02:12 PM.
 
Old 12-02-2006, 02:14 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,751

Rep: Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929
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?
 
Old 12-02-2006, 02:24 PM   #15
worldgnat
Member
 
Registered: Oct 2004
Posts: 337

Original Poster
Rep: Reputation: 30
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

Last edited by worldgnat; 12-02-2006 at 02:39 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Writing device drivers in Linux: A brief tutorial LXer Syndicated Linux News 0 04-26-2006 03:21 PM
Writing Linux Device Drivers pr@vn_t Programming 3 08-22-2005 08:52 PM
writing device drivers jessy jane Linux - Newbie 2 11-04-2004 12:25 AM
writing a loopback device ebh1 Linux - Newbie 2 03-12-2004 05:12 PM
writing device dummyagain Programming 2 10-18-2003 04:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 09:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration