Code for USB at the PC side

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Code for USB at the PC side

619 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Wed Jan 30 13:03:43 MST 2013
[FONT=Tahoma][SIZE=2]I know that this a NXP mcu forum, but this does relate.

Once I have developed my USB device code on the MXP mcu (probably with lots of help from the forum members), how do I go about talking to it from the PC side.

1) I have looked at the Microsoft API documentation and there seems tp be a new API for USB (for Vista+, but can be installed on XP).
Like all reference documentation, it tells you exactly how to do with it says it will; but it doesn't (and it is not part of its remit) tell you when or why you might want to do it and what else you have to do to set it up.

2) Also I have come across a Win port of something called LibUSB. Again, it provides USB related things to do, but no cook-book of a basic PC application.

Otherwise Google was not my friend.

What I would like are pointers to tutorials, how to's, sample code for an **ABSOLUTE** USB beginner that will allow me to send (say a command e.g. start ADC on channel x) to the mcu, and read back therefrom (your ADC value was NNN).

So, forum guys, has any one any suggestions, links to web sites, pointers to sample code? (Pure "C" please and no paid for dll's -- and I won't touch dot NET with a full Bio-Hazard team on standby).

Thanks in advance for all suggestions, Mike






[/SIZE][/FONT]
0 项奖励
回复
5 回复数

608 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Fri Feb 01 08:53:13 MST 2013
[FONT=Tahoma][SIZE=2]Thanks for that.
I have the shelve the issue for now due to
other (very) pressing projects.

But I will keep in mind all the forum responses
when I am allowed to get back to this.

I have bought USB-Complete 4th Edition,
and I got about a third of the way through.

I am confident about writing the device firmware
probably on an NXP LPC1347.

It is still the PC end that concerned me.

Again, thanks to all posters.

Mike

[/SIZE][/FONT]
0 项奖励
回复

608 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Fri Feb 01 07:52:47 MST 2013
Never heard of that library, so can't comment. However, if you really want to create your own customer USB device class, remember
- you will need a device driver
- device drivers need to be installed. You will need 32 bit and 64 bit versions of the drivers (plus associated INF etc files)
- in recent versions of Windows, device drivers also have to be signed with an Authenticode cerificate. I think on Win7/64 drivers MUST be signed

This is all do-able, but it really causes a lot of hassle. In my limited experience, I can tell you that a lot Windows (XP) installations have corrupted driver databases that cause perfectly correct drivers to not install or not run. Trying to convince customers it is a problem with their machine and not my drivers is not a good  experience...

Unless there really is a very good reason, I would suggest trying to use one of the existing device classes. BTW: This also helps if you want to move to Linux (saves you having to write a Linux device driver too).

Anyway, that's just my 2c.
0 项奖励
回复

608 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Fri Feb 01 07:20:21 MST 2013
[FONT=Tahoma][SIZE=2]Thanks for the hints guys, I [I]am[/I] pondering in the background (can't you hear the
cogs grinding).

I have come across pages for "LibUsbK"; any opinions of that?

Ta, Mike
[/SIZE][/FONT]
0 项奖励
回复

608 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stalisman on Fri Feb 01 05:12:59 MST 2013
This is a tricky one because the answer could be as long as one wants it to be. The simple answer is that what you do on the PC side depends entirely on what the capabilities of your new device are. You can make your device anything you like but it helps to make it a device that windows recognises because then a lot of the work is done for you and there are plenty of shoulders to stand on.

Fallguy mentioned three of the most common device classes (serial, hid, mass storage) to which I would add printer (only because I wrote one once). I'd have thought that either serial or hid would be for you. With serial you can invent your own protocol over the serial link whilst with HID you have great flexibility over the information you send in from your device continuously. It is horses for courses. HID is a little tricky in that the report definition is a bit like suduko and you have to go through the windows apis to register your application to receive the HID reports.

Alternatively you could just do the minimum and communicate with your device via named pipes and utilise writefile, readfile etc. not very elegant but possible.

A good place to start is http://www.usbmadesimple.co.uk and also to take heed of 'everything' that Tsuneo adds to a USB thread :-)
0 项奖励
回复

608 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Jan 30 14:03:04 MST 2013
USB is many things - serial port, mouse, mass storage, etc. You need to decide whiat is most appropriate for the data you want to transfer.

I would strongly suggest that you use one of the standard type (serial, hid, mass storage) as you will then not need any additional driver. This then means you can use standard client code to read the data. There are lots of VB examples that show you how to do this (and you convert to your favorite programming language afterwards).

You only need additional drivers (and non-standard code) if you are using an 'odd' protocol.

Hope that helps.
0 项奖励
回复