News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Usb communication

Started by george999, November 27, 2007, 05:43:09 PM

Previous topic - Next topic

george999

I want to get info from a mobile phone.I have done this through serial port(with serial cable),but through usb port I can't make it work.I can use CreateFile,WriteFile...etc,like i've done with serial port?

Sorry for my bad english.


george999

Thank you,but I couldn't find any precise example there,just a lot of USB specifications,but not examples.

zooba

It depends entirely on the driver. You're more likely to use DeviceIoControl than Write/ReadFile. However, it depends on how it has been implemented.

Either individual functions are implemented as part of the driver, in which case you'll use DeviceIoControl with whatever control codes are used for that driver, or the driver simply passes through blocks of data, in which case there'll be a library/specification somewhere (probably not public) that describes how to communicate.

It's all about using API calls, so examples in C/C++ are just as useful, and there's plenty of those in MSDN and the Windows Driver Kit.

Cheers,

Zooba :U

george999

Before i posted here i have searched with google and in msdn,but i still don't have any idea.On serial port I know what i have to do:
-open port (Createfile)
-configure port(baudrate,bytesize,etc.)
-read and write to port(ReadFile,WriteFile).
But on Usb I don't know from where to start and where to end.


zooba

USB is far more complicated than serial or parallel ports. I recommend downloading the Windows Driver Kit and looking through the sample applications. They're mostly in C/C++ but, as I said before, it's mostly based around API calls so the differences are limited.

Cheers,

Zooba :U

farrier

george999,

It depends on how the device is recognized by Windows.  I have used the CreateFile/WriteFile/ReadFile for communication with printers, both parallel and usb.  If your device is recognized by Windows, you can use CreateFile with the device name.

hth,

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

codmajik

george999:
Try:
    USB Complete: Everything You Need to Develop Custom USB Peripherals by Jan Axelson
    http://www.amazon.com/USB-Complete-Everything-Develop-Peripherals/dp/1931448027


   You can get the ebook version on knowfree.net or b213.net

george999

Ok,thank you.I downloaded the book and i readed some...It uses one function that i don't know--HidD_GetHidGuid.What include files I have to put in my code so i can use this function?

jj2007

Quote from: george999 on November 30, 2007, 03:38:45 PM
Ok,thank you.I downloaded the book and i readed some...It uses one function that i don't know--HidD_GetHidGuid.What include files I have to put in my code so i can use this function?

HidD_GetHidGuid is an export of HID.DLL not currently included in the libraries, so you will have to do it the conventional way. Try code of this kind:

   invoke LoadLibrary, chr$('hid.dll')
   .if eax==0
       mov eax, 12345   ; any number telling you no HID on this pc
       ret
   .endif
   mov hDLL, eax
   invoke GetProcAddress,hDLL, chr$('HidD_GetHidGuid')
   mov dll_GetHid, eax

... do your stuff ...

   push last_par
   push middle_par
   push first_par
   call dll_GetHid

... do your stuff ...

   invoke FreeLibrary,hDll

george999

george999,

It depends on how the device is recognized by Windows.  I have used the CreateFile/WriteFile/ReadFile for communication with printers, both parallel and usb.  If your device is recognized by Windows, you can use CreateFile with the device name.

hth,

farrier


Windows recognizes the phone like "Phone(COM3)" .I have a valid handle to comunicate to phone,but when I call Writefile the program freezes and i have to force close it.
The problem is not to get a handle,but how to send data.
I use a pure usb cable,not  usb to serial.



farrier

george999,

It seems strange that the phone is recognized as a COM3 device when attached via a USB cable!  When the phone is first plugged in, does Windows acknowledge it with a pop up window, saying "Device recognized"?

When you execute the CreateFile command, what is the return value in eax?  This will tell you if the phone is recognized.  Then if the phone is recognized, try the simplest command to illicit a response from the phone.  For instance, name of phone or model number.

hth,

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

zooba

Quote from: farrier on December 03, 2007, 09:54:30 PM
It seems strange that the phone is recognized as a COM3 device when attached via a USB cable!

It seems entirely reasonable to me. Telephony devices (modems, etc.) are often expected by older programs to be connected via a serial port, so for compatibility with older programs it makes a lot of sense to implement them this way.

COM ports are logical ports, rather than physical ports. Windows can easily set one up for your device no matter how it is connected.

Cheers,

Zooba :U

george999

CreateFile it's returns value 48.So the handle seems to be valid.No meather what command I send to modem the program it's freezing...