LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2010, 07:39 AM   #1
wybourn
LQ Newbie
 
Registered: Jul 2010
Posts: 14

Rep: Reputation: 0
Read unknown data length from usb pipe


I've written a usb device driver and a program that sends and receives data over the bulk pipe. The read function sometimes returns -1 when I'm reading an unknown amount of data. However, using a usb tracker I can see that the correct data is being sent.

The error only occurs sometimes. I expect that the read function is told to read more data that it receives it would fail and return -1, however if this was the case then every read call would fail.

Thanks in advance for any help.
 
Old 08-12-2010, 04:34 PM   #2
Les Windoze
LQ Newbie
 
Registered: Aug 2010
Location: Florida
Distribution: RHEL5, RHEL6, Solaris 10
Posts: 18

Rep: Reputation: 1
Are you trapping the error value (errno) and checking what you're getting?
 
Old 08-14-2010, 09:00 AM   #3
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
The read function only returns a -1 if an error occurs, which if you are using non-blocking could include the EAGAIN error meaning no data was available at the time you tried to read
 
Old 08-16-2010, 09:19 AM   #4
wybourn
LQ Newbie
 
Registered: Jul 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks for the response. The value I get back is errno 5, which is Input/Output error. Also the problem goes away every time I disconnect and reconnect the device.

I also found out that I can make as many read/write calls to the device with out any problems initially. Its when the program closes then opens again that the problem occurs.

I know the data is being sent at the time of the read as I have a usb tracker which is logging every usb packet on a separate machine so I know the data is being sent, the same data each time whether the read command returns an error or not.

Last edited by wybourn; 08-16-2010 at 09:23 AM.
 
Old 08-16-2010, 09:33 PM   #5
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
do you verify that you are getting a good file descriptor on your open, maybe the device isn't getting released for another open to occur successfully on
 
  


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
Read/Write data to SD card physical address by USB Reader in Fedora 7 yuanlaidewo Linux - Newbie 0 07-14-2008 10:18 PM
USB mouse x, y data read borganve Linux - Hardware 1 03-17-2008 07:34 AM
How i can read/write data from USB PIC16? njel Programming 0 07-14-2004 10:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:53 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