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

ToutEnMasm

Hello,
Quote
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?
The library hid.lib is part of the WINDDK (The link to donwload it is closed but you can download the DDK)
The function is describe in the hidsdi.h with all functions beginning by HidD_...
There is just a translation to do.
Quote
void __stdcall
HidD_GetHidGuid (
   OUT   LPGUID   HidGuid
   );



MichaelW

#16
The recent WDK does not appear to be available for download, but the Server 2003 SP1 DDK is available here, and it includes at least three versions of hid.lib

BTW, in addition to the 64-bit stuff, this version includes a 32-bit ML and LINK, both version 7.10.4035.

And also MASM 5.10A, a 16-bit linker (5.60.220), and:

Microsoft (R) C/C++ Optimizing Compiler Version 8.00c, along with what appear to be a normal set of libraries and header files.

And multiple other 16-bit tools.
eschew obfuscation

farrier

zooba,

You're probably right, like with a USB to Serial conversion device.  I'm guessing that the phone emulates the COM port on its' side of the USB connection.

george999,

Are you using COM3 or another device name in the CreateFile call?  Immediately after the CreateFile, call GetCommState to check the whole COM port response.

Show the part of your code establishing the connection with the phone.  It may help us help you.

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

george999

usb            DCB {?}   
usbto      COMMTIMEOUTS {?}
f                    db "COM3",0

...............

invoke CreateFile,addr f,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL
mov hf,eax
mov usb.DCBlength,SIZEOF usb
        invoke GetCommState,hf,addr usb
        mov usb.BaudRate,CBR_115200
        mov usb.ByteSize,8
        mov usb.Parity,NOPARITY
        mov usb.StopBits,ONESTOPBIT
        invoke SetCommState,hf,addr usb
invoke GetCommTimeouts,hf,addr usbto
         mov usbto.ReadIntervalTimeout,MAXWORD
         mov usbto.ReadTotalTimeoutMultiplier,0
         mov usbto.ReadTotalTimeoutConstant,0
         mov usbto.WriteTotalTimeoutMultiplier,0
         mov usbto.WriteTotalTimeoutConstant,0
invoke SetCommTimeouts,hf,addr usbto
invoke WriteFile,hf,addr buf,11,addr bw,0


I used an usb monitor and it seems that before sending my buffer it's sending some buffer that i don't know from where it's  coming.   

farrier

george999,

What return value are you getting from:

GetCommState
SetCommState
GetCommTimeouts
SetCommTimeout

You might also try communicating with the phone without changing any of the parameters: Baudrate; ByteSize; Parity; Stopbits, etc. until you have established reliable communications.  Look at the values return by GetCommState, to see if they look reasonable.

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

george999

GetCommState
SetCommState
GetCommTimeouts
SetCommTimeout
All functions returns 1.
I think i am on a wrong way because the cable it's usb not serial or usb to serial cable.I guess I have to use something else.However i searched to other forums where people asked something similar and they got no answer.It seems that usb communication it's Top Secret for a newb like me  :lol


zooba

USB itself isn't a secret, the secret part is the firmware on the device itself. You either need to determine the commands sent from the driver to the device are or find some reference.

Even if you're not actually using a USB-serial converter, it is entirely possible that the modem actually has one inside. This is especially likely since it appears as a COM port. I would expect that the usual interfaces would work, since that makes sense for compatibility with existing programs.

Have you tried your code with a modem connected to a serial port?

NPNW

Maybe, the buffer you are getting is information from the phone telling the otherside what parameters to use, or the status of the phone?
Then the phone is waiting for a response. Since you are then trying to CreateFile, the phone ignores this response.

Have you tried to capture what the buffer from the phone is sending?

NPNW


NPNW

You can take a look at the USB 2.0 Spec here.
It may contain the different protocol specs that the USB device, and or phone is using to setup communication.

www.usb.org

This second reference talks about the protocols and lead me to the first link.
www.interfacebus.com/Design_Connector_USB.html

NPNW

NPNW

From what I have been able to read. From the USB 2.0 spec.

The USB device is trying to negotiate power, and speed. This is probably the buffer information that is being sent.
Since it doesn't get a proper response, it is waiting for the correct sequence.
That is why the writefile doesn't work.

NPNW



NPNW

If you go to tools at the USB site it looks like you can send commands to a device to test it.

http://www.usb.org/developers/tools/.

Here is a link to a white paper that has code for the WDM driver to init and communicate with a USB device.
Might give you some ideas of what is going on.
http://www.usb.org/developers/whitepapers/irp_mn.pdf

NPNW

NPNW

Here are the references that the writer of the driver recommends if anyone has links or copies.

References
[1] Windowsâ,,¢ 2000 DDK; Setup, Plug & Play, Power Management, Design Guide, Part 2:
Plug and Play; 3.0 Starting, Stopping, and Removing Devices; 3.1 Starting a Device; 3.1.1
Starting a Device in a Function Driver
[2] Windows 2000â,,¢ DDK; Setup, Plug & Play, Power Management, Design Guide, Part 2:
Plug and Play; 2.0 Rules for Handling PnP IRPS; 2.3 Postponing PnP IRP Processing Until
Lower Drivers Finish
[3] Windows 2000â,,¢ DDK; Kernel-Mode Drivers; Design Guide; Part 5: USB Drivers; 2.0
Configuring USB Devices

NPNW

george999

zooba,
With serial cable it's working without any problem.

NPNW,
Thank you for your help...but...i am tired reading theory,from where i can't understand anything.I'm looking for a concrete example...

farrier

george999,

I think I suggested this before: after CreateFile, make sure your DCB buffer is cleared--set to zero--then invoke GetCommState and check the BaudRate, ByteSize, StopBits, etc. and check to see if these numbers are reasonable.  If they are reasonable, don't change them, and then try to communicate.  Tell us what values GetCommState returns!

Once again I think zooba is correct!  The phone itself is acting as a USB to serial port converter so that the computer sees a COM3 when you plug the phone into the USB port.  When you first plug the phone in, what notification message do you see?

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

zooba

If your code is working with another modem, then obviously the drivers are not fully compatible.

Do you have any other programs that work with the USB modem? Will regular Windows dial-up networking work with it or do you need a special program running?

Using a device over USB should be completely transparent. The same API calls are used to access it, especially if it is emulating a COM port. You only need to read up on USB itself if you are writing a driver or firmware (and if you want to do that you'll spend a lot of time reading before you can do it).

Cheers,

Zooba :U