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).

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 :P.

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.

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.

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.

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?

Which micro controller are you using, and does the manufacturer provide any libraries you can use.

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

Ok..... at this point I'm going to throw in the towel with USB..... I'm just going to go with RS32 since my dad can help me out with that, but I still need help on the PC end.

How do I read and write to that port in C????

Well, I realize that it's been a few years since this thread started. I struggled with this problem a few months ago for my bachelor thesis. Create a USB interface is not easy. Nowadays Microchip provides some examples for USB communication (look for the Microchip USB framework). For linux, check this article I wrote a few months ago to achieve communication through an HID USB device using PIC18F4550 Click Here

This article has been dead for over six months. Start a new discussion instead.