C and USB

Any other programming language that is not covered in the Web Scripting category.

C and USB

Postby whitehat101 on Thu Sep 01, 2005 5:07 am

Anyone know how to write a program that can interact with a USB/serial device? I'm thinking I'm trying to dive into something bigger than I am at the moment, but know of any books (or links) that talk about interacting with the outside world? Sending a signal to a device and reading it's input.

I'm hoping to make a device that can be controled by a computer eventually, and I figure learning the soft side is a good a place as any to start!
If it hurts, rub it.
whitehat101
Contributer
Contributer
 
Posts: 41
Joined: Fri Jun 24, 2005 5:18 am
Location: Orangevale, CA

Postby al_tyranny on Thu Sep 01, 2005 8:32 am

I have no idea if this is useful or not, but I found something at linuxjournal about how to write your own USB driver. I know I could not do it, I lack knowledge in how the kernel works. Hopefully you can see something to use though.

http://www.linuxjournal.com/article/7353
mm_freak wrote:Slackware users are dreamers. Sorry to say.
al_tyranny
Phoenix Veteran
Phoenix Veteran
 
Posts: 294
Joined: Tue May 17, 2005 3:18 am
Location: Greater Boston Area

Postby whitehat101 on Tue Sep 06, 2005 5:49 am

That is a very interesting link (and thanks for posting it), but sadly I' gonna end up doing this on a win compter...

I've done some reading on usb and I think I'll ask a hardware question. USB uses twisted wires and an inverted signal to help deal with noise. How exavtly would you invert a signal?

and I'm thinking that this is going to be asyncronys comunication... I found libusb that works with *nix and win, but it only offers syncronus communication until the next major release. Yeah, I'm not sure... I'm thinking you send it a signal, and it sends one back, not sure how it would sync...

I don't know about that old com port on the back of this crappy lappy... I don't think com uses inverted signals... But then I wouldn't be able to use the cable on a mac computer! So, is inverting a signal hard to do? Ohh... I guess I would have to filter it back out into one signal... or... could I just leave the inverted wire unatached...

I think I'm rambeling... anything that you think might be useful please share!
If it hurts, rub it.
whitehat101
Contributer
Contributer
 
Posts: 41
Joined: Fri Jun 24, 2005 5:18 am
Location: Orangevale, CA

Inverting signals.

Postby ncfisher on Mon Oct 24, 2005 2:56 pm

I had a very similar question with USB devices when I could not get my MP3 player to work and the vendor was from korea and no useful info was available and no one would return my support calls. It would have been cheaper for me to buy another device, and I probably will, but I started doing some research on USB just to see how difficult it was so I can see why you are asking, but your question may need clarification to get what you are looking for. Let me be general at first to help set the context of the discussion.

You have two levels you are talking about.

The signaling and inversion is hardware related. It has to do with your physical device cards. Are you building your own device?

Then, from the second level you are dealing with device drivers. These are the software interface to the hardware.

The levels you have to deal with in computers are multi-leveled... The main hardware and OS of the computer (like a windows system, a unix box, or laptop), the bus you are plugging the device into (USB, IDE, etc), and the device.

The device communicates on the bus using standard protocols and the driver is generally communicating via the kernel via the bus using some addressing mechanism to talk to a specific device. There may be multiple device drivers, one for the bus, and one for the device on the bus.

The USB bus has addresses as well, and you can search on google for some USB addressing information, and look for USB tools that allow you to scan your USB bus. This will be informative, even if you don't get to the level of writing your own device driver or building your own USB device.

I have a Bachelors Degree in Electronic Engineering Technology, but I am a little rusty... (and though I have built many hardware devices that interfaced with a computer, USB was not popular when I was in school)

Would love to know what you find out.
ncfisher
Newbie
Newbie
 
Posts: 15
Joined: Sat Oct 22, 2005 12:45 pm

Postby bart416 on Mon Oct 24, 2005 7:30 pm

I'm sure their are premade libraries for usb connection.
But finding them might be a bit hard.
bart416
Valued Member
Valued Member
 
Posts: 164
Joined: Fri Sep 30, 2005 6:50 pm

Postby mm_freak on Mon Oct 24, 2005 11:04 pm

A quick search through installed packages on my system returned this:

qpkg -I -i usb wrote:dev-libs/libusb-0.1.10a *
Userspace access to USB devices [ http://libusb.sourceforge.net/ ]
I'm x^10 + x^8 + x^5 + x^4 + x^3 + 1, so don't mess with me!
mm_freak
Moderator
Moderator
 
Posts: 635
Joined: Sun Sep 11, 2005 12:29 pm
Location: Baden-Wuerttemberg (Germany)

Postby bart416 on Tue Oct 25, 2005 7:56 pm

mm_freak wrote:A quick search through installed packages on my system returned this:

qpkg -I -i usb wrote:dev-libs/libusb-0.1.10a *
Userspace access to USB devices [ http://libusb.sourceforge.net/ ]

He needs something for windows Sad
bart416
Valued Member
Valued Member
 
Posts: 164
Joined: Fri Sep 30, 2005 6:50 pm

Might be wrong but...

Postby reki on Wed Oct 26, 2005 2:29 pm

So this might be completely off base, but couldn't you do signal inversion with a not-gate? Might be too simplistic, but that's what I would think
reki
Contributer
Contributer
 
Posts: 24
Joined: Wed Oct 26, 2005 4:00 am

Postby mm_freak on Wed Oct 26, 2005 8:07 pm

bart416 wrote:He needs something for windows :(


That's a joke, isn't it? You shouldn't be writing Windows programs. =P

I can imagine how a call related to USB looks like in Windows:

Code: Select all
UNIVERSALSERIALBUSSTRUCTEX usb;

usb.strDriver = "mssuperduperusb.dll";
usb.dwDevice = USBDEVICE_ONE_OF_THE_MICE_CONNECTED;
usb.dwReserved1 = 0;
usb.dwReserved2 = 0;
usb.wReserved3 = 0;
usb.wReserved4 = 0;
usb.strReserved5 = NULL;

/* ... */
MsgWaitForMultipleObjectsEx(...);
MsUsbInitializeUsbDeviceEx(usb, 1);
/* ... */


=)
I'm x^10 + x^8 + x^5 + x^4 + x^3 + 1, so don't mess with me!
mm_freak
Moderator
Moderator
 
Posts: 635
Joined: Sun Sep 11, 2005 12:29 pm
Location: Baden-Wuerttemberg (Germany)

Postby whitehat101 on Tue Nov 01, 2005 5:36 am

I was planning on writing something for a windows computer because that crappy computer was what I had the most access to at the time, but then it went and died (I was about a day away from making adapter to let me use a desktop hdd with it [that I was going to install a real os on] and then the motherboard went and died)

Anyways, I'm switching to trying to work with os x, but I'm also dropping my origional porject (a simple smart card reader) because that with usb is more than I could build at the moment, I was ready to make one with the com port, but then it died and I never got the parts so!

What I could do is try to make a program like p2kman (a program for editing motorola phones) because that is the one thing that I haven't been able to do on a mac. I've been busy recently, but I'll probably have time to crack into it by this weekend! Wich my luck
If it hurts, rub it.
whitehat101
Contributer
Contributer
 
Posts: 41
Joined: Fri Jun 24, 2005 5:18 am
Location: Orangevale, CA

Postby mm_freak on Tue Nov 01, 2005 6:51 am

I'm interested in your experiences with this. When you've got useful results, please post something about it. I was going to buy a programmable microchip that could do calculations faster than current CPUs, but I'd like to hear from others' experiences first.
I'm x^10 + x^8 + x^5 + x^4 + x^3 + 1, so don't mess with me!
mm_freak
Moderator
Moderator
 
Posts: 635
Joined: Sun Sep 11, 2005 12:29 pm
Location: Baden-Wuerttemberg (Germany)

Postby bart416 on Wed Nov 02, 2005 7:58 am

1) Never use tutorials from the web

C:\dev\code>gcc -ansi -pedantic -Wall -O file file.c
file.c:1: warning: ANSI C does not allow `#ident'

You get things like that when you use them Smile

I need to remember you guys to the fact that their are loads of books for embedded programming. And those should include some instructions on USB Smile


mm_freak, you will need a special compiler depending on the micro controller.
Common used is avr-ggc Smile
Should be included on fedora core if i don't mistake.
bart416
Valued Member
Valued Member
 
Posts: 164
Joined: Fri Sep 30, 2005 6:50 pm

Postby banderlog on Sat Nov 19, 2005 7:17 pm

i have very similar problem.
i have to write a program that will send a raw data (precisely 01010101) to any printer that i'll connect to my PC. At this time printer must not print anything. Printer can be eigher USB or LPT connected.
This program must be written in VC coz i have to improve the previous version of a whole project.
Some my friends wrote me that i must to write my own driver. But i want only to send data to USB device. Maybe someone here knows the way i can make printer not to act on my signals?
banderlog
Contributer
Contributer
 
Posts: 64
Joined: Sat Nov 19, 2005 5:48 pm

Postby mm_freak on Sun Nov 20, 2005 6:43 am

banderlog wrote:This program must be written in VC coz i have to improve the previous version of a whole project.


Improving a program written in VC means completely giving it up and writing it from scratch in real C++ again.

banderlog wrote:Some my friends wrote me that i must to write my own driver. But i want only to send data to USB device. Maybe someone here knows the way i can make printer not to act on my signals?


They are wrong. As long as the printer is standards compliant, you don't have to write own drivers. I don't know how to do this in Windows, but in Linux, for example, you'd just open the device file like any other regular file and write to it.
I'm x^10 + x^8 + x^5 + x^4 + x^3 + 1, so don't mess with me!
mm_freak
Moderator
Moderator
 
Posts: 635
Joined: Sun Sep 11, 2005 12:29 pm
Location: Baden-Wuerttemberg (Germany)

Postby banderlog on Sun Nov 20, 2005 2:03 pm

mm_freak wrote:... I don't know how to do this in Windows, but in Linux, for example, you'd just open the device file like any other regular file and write to it....


tnx i kno and tnats why we are both here Very Happy and that's why it is my first program for windows. Evil or Very Mad
banderlog
Contributer
Contributer
 
Posts: 64
Joined: Sat Nov 19, 2005 5:48 pm

Next

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron