🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
9 messages
9 total messages Started by Peter Stefanos Mon, 26 May 2008 01:17
I don't get DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
#274
Author: Peter Stefanos
Date: Mon, 26 May 2008 01:17
94 lines
3819 bytes
Hello all,

I have been unsuccessfully trying to get DBT_DEVICEARRIVAL and 
DBT_DEVICEREMOVECOMPLETE when listening to WM_DEVICECHANGE messages when 
I plug and unplug my USB device. The USB device has been made to look 
like a COM port and comes up as COM9 on my computer.

I have done the following:

1. Built a USB device (LPC2148 micro), used the LPCUSB USB stack
2. I have used the usbser.sys driver under Windows XP.
3. Registered for notification using RegisterDeviceNotification().
4. If I plug in a commercially available USB to serial device, I get the 
DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE message types successfully.

Can anyone tell me what I have done wrong? I hope its obvious.

Could it be the way the driver was installed?

I am very inexperienced with this stuff... I have been stuck on this one 
for many days now...

Here is my code:

Header File:

...
class TForm1 : public TForm
{
__published:	// IDE-managed Components
   TListView *ListView1;
   void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
private:	// User declarations
public:		// User declarations
   __fastcall TForm1(TComponent* Owner);
   void LogData(char *Format, ...);
   void __fastcall USBConnectHandler(TMessage &Message);

BEGIN_MESSAGE_MAP
   MESSAGE_HANDLER(WM_DEVICECHANGE, TMessage, USBConnectHandler);
END_MESSAGE_MAP(TForm)
};
...


Main CPP file:

...
HDEVNOTIFY hDevNotify;
...
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
   DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;

   ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
   NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
   NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
   NotificationFilter.dbcc_classguid = 
GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR;

   hDevNotify = RegisterDeviceNotification(Application->Handle, 
&NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);

   if (!hDevNotify) {
     Application->MessageBox(Message.c_str(), "Error", MB_OK);
   }
}
//---------------------------------------------------------------------------


void __fastcall TForm1::USBConnectHandler(TMessage &Message)
{

   PDEV_BROADCAST_DEVICEINTERFACE pInterface;

   DebugOut("WM_DEVICECHANGE: %d, %d, %d",
     Message.Msg, Message.WParam, Message.LParam);
   switch (Message.WParam) {
   case DBT_DEVICEARRIVAL:
     DebugOut("Got DBT_DEVICEARRIVAL");
     break;
   case DBT_DEVICEREMOVECOMPLETE:
     DebugOut("Got DBT_DEVICEREMOVECOMPLETE");
     break;
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
   UnregisterDeviceNotification(hDevNotify);
}
//---------------------------------------------------------------------------
Re: I don't get DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
#277
Author: Hans Galema
Date: Mon, 26 May 2008 19:54
7 lines
1276 bytes
Peter Stefanos wrote:

> I have been unsuccessfully trying to get DBT_DEVICEARRIVAL and 
> DBT_DEVICEREMOVECOMPLETE when listening to WM_DEVICECHANGE messages when 
> I plug and unplug my USB device. 

Do you get any WM_DEVICECHANGE message?
Re: I don't get DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
#278
Author: Peter Stefanos
Date: Mon, 26 May 2008 22:20
35 lines
2122 bytes
Hans Galema wrote:
> Peter Stefanos wrote:
> 
>> I have been unsuccessfully trying to get DBT_DEVICEARRIVAL and 
>> DBT_DEVICEREMOVECOMPLETE when listening to WM_DEVICECHANGE messages 
>> when I plug and unplug my USB device. 
> 
> Do you get any WM_DEVICECHANGE message?

Yes. I get 2 WM_DEVICECHANGE messages when I plug in my USB device and 1 
WM_DEVICECHANGE message when I unplug it. i.e.

<plug my USB to serial device in>
WM_DEVICECHANGE, WParam = 537, LParam = 7
WM_DEVICECHANGE, WParam = 537, LParam = 7

<unplug my USB to serial device>
WM_DEVICECHANGE, WParam = 537, LParam = 7


For the commercial (ATEN) USB to serial device, I get 3 WM_DEVICECHANGE 
messeges when I plug it in and 2 WM_DEVICECHANGE messsages when I unplug 
it. i.e.

<plug ATEN USB to serial device in>
WM_DEVICECHANGE, WParam = 537, LParam = 7
WM_DEVICECHANGE, WParam = 537, LParam = 32768
WM_DEVICECHANGE, WParam = 537, LParam = 7

<unplug ATEN USB to serial device>
WM_DEVICECHANGE, WParam = 537, LParam = 7
WM_DEVICECHANGE, WParam = 537, LParam = 32772

Kind Regards,
Peter.
Re: I don't get DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
#284
Author: Hans Galema
Date: Wed, 28 May 2008 13:58
12 lines
1469 bytes
Peter Stefanos wrote:

> <plug my USB to serial device in>
> WM_DEVICECHANGE, WParam = 537, LParam = 7
> WM_DEVICECHANGE, WParam = 537, LParam = 7
> 
> <unplug my USB to serial device>
> WM_DEVICECHANGE, WParam = 537, LParam = 7

So that is difficult to distinguish between plug and unplug.

I'm sorry that I can't help you.
Re: I don't get DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
#290
Author: Leo Havmøller
Date: Thu, 29 May 2008 04:16
17 lines
1725 bytes
> <plug ATEN USB to serial device in>
> WM_DEVICECHANGE, WParam = 537, LParam = 7
> WM_DEVICECHANGE, WParam = 537, LParam = 32768
> WM_DEVICECHANGE, WParam = 537, LParam = 7
>
> <unplug ATEN USB to serial device>
> WM_DEVICECHANGE, WParam = 537, LParam = 7
> WM_DEVICECHANGE, WParam = 537, LParam = 32772

wParam and lParam are swapped in your output.
Also please print in hex instead of decimal.

wParam=0x7=DBT_DEVNODES_CHANGED
wParam=0x8000=DBT_DEVICEARRIVAL
wParam=0x8004=DBT_DEVICEREMOVECOMPLETE

Leo Havm�ller. 
Re: I don't get DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
#289
Author: Leo Havmøller
Date: Thu, 29 May 2008 04:21
13 lines
1603 bytes
> 1. Built a USB device (LPC2148 micro), used the LPCUSB USB stack
> 2. I have used the usbser.sys driver under Windows XP.

Have you checked the USB communication?
What about the INF?

> 3. Registered for notification using RegisterDeviceNotification().
> 4. If I plug in a commercially available USB to serial device, I get the 
> DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE message types successfully.

Different device, driver and USB communication. Not comparable.

Leo Havm�ller. 
Re: I don't get DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
#291
Author: Peter Stefanos
Date: Mon, 02 Jun 2008 23:20
59 lines
2585 bytes
Leo Havm�ller wrote:
> Have you checked the USB communication?
> What about the INF?

By USB communication, do you mean if there is any? Yes, I can transfer
lots of data back and forth.

The INF file is one that came with the USB software stack.
It can be found here at:
http://wiki.sikken.nl/index.php?title=LPCUSB

The inf file is listed below. I have changed some of the strings to suit 
my application.

[Version]
Signature="$Windows NT$"
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
Provider=%LINUX%
DriverVer=08/17/2004,0.0.2.0
; Copyright (C) 2004 Al Borchers (alborchers@steinerpoint.com)
; released under GNU General Public License

[Manufacturer]
%LINUX%=GSerialDeviceList

[GSerialDeviceList]
%GSERIAL%=GSerialInstall, USB\VID_FFFF&PID_0005

[DestinationDirs]
DefaultDestDir=10,System32\Drivers

[GSerialInstall]
CopyFiles=GSerialCopyFiles
AddReg=GSerialAddReg

[GSerialCopyFiles]
usbser.sys

[GSerialAddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"

[GSerialInstall.Services]
AddService = usbser,0x0002,GSerialService

[GSerialService]
DisplayName = %GSERIAL_DISPLAY_NAME%
ServiceType = 1                  ; SERVICE_KERNEL_DRIVER
StartType = 3                    ; SERVICE_DEMAND_START
ErrorControl = 1                 ; SERVICE_ERROR_NORMAL
ServiceBinary = %10%\System32\Drivers\usbser.sys
LoadOrderGroup = Base

[Strings]
LINUX = "Linux"
GSERIAL = "USB CDC serial port emulation"
GSERIAL_DISPLAY_NAME = "USB CDC serial port emulation"
Re: I don't get DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
#292
Author: Leo Havmøller
Date: Tue, 03 Jun 2008 03:53
9 lines
1495 bytes
> By USB communication, do you mean if there is any? Yes, I can transfer
> lots of data back and forth.

Then you havent checked the USB communucation.
The USB CDC protocol uses a boat-load of set/get on the control endpoint, 
and your device firmware must answer them correctly.
Use a USB analyzer.

Leo Havm�ller. 
Re: I don't get DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE
#301
Author: Peter Stefanos
Date: Tue, 03 Jun 2008 22:30
17 lines
1851 bytes
Leo Havm�ller wrote:
> 
> Then you havent checked the USB communucation.
> The USB CDC protocol uses a boat-load of set/get on the control 
> endpoint, and your device firmware must answer them correctly.
> Use a USB analyzer.
> 
> Leo Havm�ller.

Unfortunately I was not given much time to read the USB 2.0 spec and 
hence was hoping to use the LPCUSB stack (like a black box) without 
having to understand it.
I enabled the debug messages and indeed there seems to be some problem 
when my USB device is connected.
Something about descriptor 0x600 not found, handle request failed.
Any suggestions?
If not, is there a open source/free USB analyser that you could recommend?
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads