How do I communicate to a USB port through C? (for Linux and Windows)

Reply

Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #1
Apr 3rd, 2008
As all of you can tell from the title, I need help understanding how to communicate to a USB port. Basically I need to send some bits to a usb micro controller and to do so I need to understand how you do it in C for both a Windows and Linux computers. I'm going to be creating my own interface (still figuring that out) which basically works by having the micro controller send out a signal so I can figure out what port it's on and from then on I just start sending the bits to it.

So here's a breakdown of what I need to know.

1. When the data exits the port to the device, will it have the port address with it when the device reads in the data?
2. I'm going to be working with Ubuntu and Win XP, what things will I need to utilize from the OS?
3. Would you recommend a better way to interface to USB?
4. Do I have to repeatedly send a signal when trying to find which usb port the device is on?

As you can tell I'm kind of jumping into this without know what I'm getting myself into. I'm open to any suggestions (other than giving up).
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 181
Reputation: Paul.Esson is an unknown quantity at this point 
Solved Threads: 10
Paul.Esson's Avatar
Paul.Esson Paul.Esson is offline Offline
Junior Poster

Re: How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #2
Apr 3rd, 2008
You may have to write a driver for the USB device or uterlize it as a communications port as say you do with usb serial adapters or things like that.

The windows device foundation SDK has methods for dealing with USB devices ( and also quite possable some sample code. ) Documentation can be found here.

The windows device foundation also allows you to write a usermode driver, if you don't want to risk crashing windows .
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Re: How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #3
Apr 3rd, 2008
So what's the easiest way about doing this? By the way, this all can be done in C right? I don't need C++ right?

I just need to create a program that takes a bunch of 1s and 0s as its argument (int[]) and sends it to the usb device?

By the way I'm using a PIC usb micro controller.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 181
Reputation: Paul.Esson is an unknown quantity at this point 
Solved Threads: 10
Paul.Esson's Avatar
Paul.Esson Paul.Esson is offline Offline
Junior Poster

Re: How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #4
Apr 3rd, 2008
I have looked around the net abit more and have not found any other ways to talk to USB in windows without using the windows device foundation. There will be examples included with the foundation probably in C, If the samples are not in C, I am certain that the drivers can be written in C.

I would look at the userspace driver samples provided with WDF.

I would love to know if there was a simple way to do this without writing a driver, Would be great to know.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #5
Apr 3rd, 2008
USB communication is easily 20 times more complex than RS232. No one I know bothers with it. There's a module
for the Python language called pyUSB which is said to simplify things. There's also Easy HID.
http://www.protongeeks.com/index.php...=136&Itemid=30
Last edited by Colin Mac; Apr 3rd, 2008 at 7:55 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,602
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #6
Apr 4th, 2008
ive heard Python has a very simple USB interface too.

but that means it's written in C.

doesnt linux have a device filename for USB ports? like /dev/ugen something or other? cant you then do fopen( ) on that?

just thinking... ive never done it, myself.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #7
Apr 4th, 2008
For ports (serial, parallel, usb etc), try http://www.lvr.com/
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Re: How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #8
Apr 4th, 2008
I think the best solution is to make the USB look like a serial (COM) port. If I do that, what would I have to do in C to find that particular port and how would I go about communicating with it? In other words how do I go to each port a listen to it?

Also for those who are familiar with doing this, will this work for linux also?
Last edited by Mr.UNOwen; Apr 4th, 2008 at 4:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #9
Apr 4th, 2008
Which micro controller are you using, and does the manufacturer provide any libraries you can use.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 116
Reputation: Mr.UNOwen is an unknown quantity at this point 
Solved Threads: 0
Mr.UNOwen Mr.UNOwen is offline Offline
Junior Poster

Re: How do I communicate to a USB port through C? (for Linux and Windows)

 
0
  #10
Apr 4th, 2008
I'm planning on using one of the Microchip PIC micro controllers. Haven't decided which one yet, but it's going to have at least 20 programmable I/O pins
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC