C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 3rd, 2009, 01:16 PM
fr_cassidy fr_cassidy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 41 fr_cassidy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 13 m 47 sec
Reputation Power: 5
Using C to send data through USB port

Hi,
I am looking for a little help regarding how I can send data through the USB port using C. I am currently designing a project where I need to send a few bytes to an arduino board connected via USB.

I have been doing some googling, but I haven't been able to get too much info. I;m not sure how many options there are for doing this, but the only one I find is by using libusb available on sourceforge.

Anyway I downloaded the library and am not even sure how to use it. I have copied the .a, .c and .h files to the directory of my program, but when I call the usb_init(); function in my code it produces a linker error.

I am not even sure if I have done what is nessesery with libusb due to my lack of experience and knowledge in this field, so my main questions are:

Can anyone give me maybe a step by step guide on what I have to do with libusb in order to use the functions. (I am using Dev-C to write my programs, but can chaange if it is nessesery)

Is there another way of sending data through USB which is more straightforward and easily understood for a beginner like me?

Many thanks for any suggesstions

Reply With Quote
  #2  
Old July 3rd, 2009, 04:04 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is online now
Banned ;)
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 8,313 Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 23rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 4 Days 4 h 38 m 19 sec
Reputation Power: 2529
The linker error is because you haven't told your compiler to link to libusb.a. Just because you download the file to your computer doesn't mean the compiler knows about it. You have to go to your Project Options --> Parameters and add -lusb to the linker options.

In addition, you may need to go to Compiler --> Options and add the directory that you have downloaded libusb into your list of directories.

Incidentally, why Dev-C++ and why not Visual C++. It is a better compiler, comes with a set of better dev tools and there is a free version as well.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by Fishmonger, superior perl programmer of the month

Reply With Quote
  #3  
Old July 4th, 2009, 09:21 AM
fr_cassidy fr_cassidy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 41 fr_cassidy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 13 m 47 sec
Reputation Power: 5
Thank you very much for your reply.
I did what you recommended and I can successfully compile a program, so thank you for saving me some time.

I am writing a program to communicate with an arduino board (www.arduino.cc) which has an FT232R USB UART.

I have a program which seems is able to talk to the UART on the external board, as I have a small program with LED's which flash once it receives something.

I have been using the usb_bulk_write function to send something, but I am not sure how to read the response from the board. The way I have designed the program on the arduino, is to send back data when it receives a certain character, for example it sends back the temperature when I send 'T', the Windpeed when I send 'W'..etc.

My level of C is very basic and also I do nt find it easy to interpret how to use the functions of libusb.

I am hoping that someone can guide me i the right direction. I think I'm close, as the external board is sending back some data. But I just need to know how I can capture it.

I have tired using the usb_bulk_read function, but I dont understand the parameters that are passed (http://libusb.sourceforge.net/doc/function.usbbulkread.html). Maybe someone can enlighten me as to what are refered to by endpoints?

Below are the 2 functions I have been using to communicate with the board. usb_bulk_write seems to work, but I receive -116 when I run the usb_bulk_read command. I'm not sure what I doing wrong, but any ideas wuld be much appreciated.
Thanks

Code:
response = usb_bulk_write(dev, EP_OUT, tmp, sizeof(tmp), 5000); printf("Arduino says: %d\n",response);   //    { //      printf("error: bulk write failed\n"); //      system("PAUSE"); //    }   response = usb_bulk_read(dev, EP_IN, tmp, sizeof(tmp), 5000); printf("Arduino says: %d\n",response);

Reply With Quote
  #4  
Old July 6th, 2009, 02:28 PM
fr_cassidy fr_cassidy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 41 fr_cassidy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 13 m 47 sec
Reputation Power: 5
Quote:
Incidentally, why Dev-C++ and why not Visual C++. It is a better compiler, comes with a set of better dev tools and there is a free version as well.


Can someone tell me where I can find the free version. I have been googling but I dont see it on the microsoft site

Thanks

Reply With Quote
  #5  
Old July 6th, 2009, 03:14 PM
salem's Avatar
salem salem is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2005
Posts: 2,139 salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 1 Month 2 Weeks 1 Day 23 h 22 m 21 sec
Reputation Power: 861
Any search of "visual studio express" should lead you to it.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Reply With Quote
  #6  
Old July 6th, 2009, 06:24 PM
TXchron-420 TXchron-420 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 15 TXchron-420 User rank is Sergeant (500 - 2000 Reputation Level)TXchron-420 User rank is Sergeant (500 - 2000 Reputation Level)TXchron-420 User rank is Sergeant (500 - 2000 Reputation Level)TXchron-420 User rank is Sergeant (500 - 2000 Reputation Level)TXchron-420 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 h 10 m 42 sec
Reputation Power: 0
all the pcs i have purchased have came with visual C++ and studio express

Reply With Quote
  #7  
Old July 6th, 2009, 06:28 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Crab
Click here for more information.
 
Join Date: Jun 2005
Posts: 5,693 sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 49th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 10 h 45 m 32 sec
Warnings Level: 5
Reputation Power: 4274
They're atypical, then.
__________________
Write no code whose complexity leaves you wondering what the hell you did.
Politically Incorrect DaWei on Pointers Grumpy on Exceptions

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Using C to send data through USB port


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
Stay green...Green IT