LinuxQuestions.org
Help answer threads with 0 replies.
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 06-12-2013, 11:53 AM   #1
PeterUK
Member
 
Registered: May 2009
Posts: 281

Rep: Reputation: 16
Programming C- Help with USB interface


Hi! I am following a code which use the USB bus with FX2

I would like to ask about the buffer size in the programer use array char 1024 which should be 1025 bits. right?

When you said payload is the same as packet size? I think the maximum frame size is 1024 right?

But I think the date packet is 4 bits right?

Maybe I need to do more reading but I though maybe let the master give me a push! Thanks

UPDATE: Also what does " * Need to change stdin to non-blocking. */" means?

Last edited by PeterUK; 06-12-2013 at 11:55 AM.
 
Old 06-12-2013, 06:20 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Can you post a link to the code you're working with?

Kevin Barry
 
Old 06-13-2013, 05:44 AM   #3
PeterUK
Member
 
Registered: May 2009
Posts: 281

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ta0kira View Post
Can you post a link to the code you're working with?

Kevin Barry
This is the non-blocking bit

Code:
		 * Need to change stdin to non-blocking. */

		n = fcntl(0,F_GETFL);
		if(n<0) {
			fprintf(stderr,"Trouble getting stdin flags\n");
			n = 0;
		}
		n = fcntl(0,F_SETFL,n|O_NONBLOCK);
		if(n<0) {
			fprintf(stderr,"Trouble setting stdin flags\n");
			n = 0;
		}

		n = 0;
		k = 1;
		for(;;) {
			char outbuf[1024];
			char inbuf[1024];
			if(n==0) {
				n = read( 0, outbuf, 1024 );
				if(n<0) {
					if(errno == EAGAIN) {
						usleep(10000);
						n = 0;
					}
					else {
						fprintf(stderr,"read n= %d err = %d\n",n,errno);
					}
				}
			}
			if(n>0) {
				int rtn;
				rtn = usb_bulk_write(usbhandle,0x02,outbuf,n-1,10); 
				if(rtn >= 0) n = 0;
				fprintf(stderr,"usb_bulk_write %d\n",rtn);
			}
			if(k==0) {
				int rtn;
				rtn = usb_bulk_read(usbhandle,0x06,inbuf,1024,10); 
				if(rtn != -110) fprintf(stderr,"Got %d\n",rtn);
				if(rtn>0) k = rtn;
			}
			if(k>0) {
				fprintf(stdout,"usb read %d bytes\n",k);
				/* TODO: Print them. */
				k = 0;
			}
		}
Those function are defined in usb.h under the user... folder, right?

It also include this at the beginning #include <fcntl.h>

Last edited by PeterUK; 06-13-2013 at 05:46 AM.
 
  


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
socket programming in c interface vipin_jss Linux - Networking 4 03-04-2008 08:45 AM
Serial interface programming smallfire Programming 2 07-12-2006 09:24 AM
RS-422 Interface programming amirmk Programming 3 09-29-2004 08:13 AM
I need a good programming interface for C\C++.. diam0nd Linux - Software 1 11-29-2003 04:43 AM
HTTP Interface Programming Nauseous Programming 1 08-04-2003 08:29 PM

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

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