|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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);
|
|
#4
|
|||
|
|||
|
Quote:
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 |
|
#5
|
||||
|
||||
|
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. |
|
#6
|
|||
|
|||
|
all the pcs i have purchased have came with visual C++ and studio express
|
|
#7
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Using C to send data through USB port |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|