detect USB connection

  • Our NetDCU10 device is configured as a mass storage device. Is there any change of getting a message/event/notification when it is connected to the PC? I know RegisterDeviceNotification and WM_DEVICECHANGE on the PC, but I need to react on the NetDCU device when it is connected to the PC.


    Thanks

  • You are right, the sdcard is removed when the NetDCU device is connected to a PC, but this is only half the rent. There seems to be no change notification when the device is disconnected: the sdcard isn't mounted again. But we also need to react if the NetDCU device is disconnected from the PC.


    The goal is to present our customers a dialog when the NetDCU device is connected to a PC and the sdcard isn't available through the device.

  • Hello,
    so if i understand you right, the notification is send when you get connected but it is not send when you get disconnected.
    And the main problem is that the sdcard isn't mounted again. Because this seems to be the reason for the missing notification.


    Can you enabel serial debug output for sd card (debug=255) and check if there is any (significant) output?
    If you select ffsdisk or RAM as mass storage device what happen is you disconnect, are these storage is mounted again?

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Quote from "fs-support_ZU"


    Can you enabel serial debug output for sd card (debug=255) and check if there is any (significant) output?


    Can you please tell us the relevant registry path? We tried


    HKLM/Drivers/SDCARD/ClientDrivers/Class/SDMemory_Class


    and


    HKLM/Drivers/SDCARD/ClientDrivers/Class/SDMemory_Class/High_Capacity


    without success (no output at all).

  • Hallo,
    this value can in general specified under "HKLM\drivers\builtin\<driver>" for each driver. In our case i would set the value for SDHC and SBBus.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Quote from "fs-support_ZU"

    Hello,
    so if i understand you right, the notification is send when you get connected but it is not send when you get disconnected.
    And the main problem is that the sdcard isn't mounted again.


    That's right. I can get a notification when the NetDCU device is connected to the PC because of the unmounted sdcard. But I don't get any notification when the device is disconnected from the PC.


    What I tried so far: catching any windows message (like WM_DEVICECHANGE), CeRunAppAtEvent, your EnumDev sample. We also take a look at the registry and at the storage manager, but there seems to be no "hint" when the device is disconnected.


    Quote


    this value can in general specified under "HKLM\drivers\builtin\<driver>" for each driver. In our case i would set the value for SDHC and SBBus.


    We tried these values too, but we got no relevant debug output.



    Some more explanations what we tried to achieve: we use the sdcard as mass storage in order to gain a simple access of the device data (without installing any drivers like ActiveSync on the PC). There is no problem to remount the sdcard when it was unmounted while connecting the NetDCU device to a PC. But the problem is the shared access to the sdcard from both sides at the same time which seems to end up in corrupted data from time to time. Therefore we are searching for a method to detect if the NetDCU device is connected to a PC.


    Another possible solution could be to turn off the mass storage access from the PC for a short time. We tried so far IOCTL_UFN_CHANGE_CURRENT_CLIENT (switching to ActiveSync and back) and SetDevicePower (to turn USB port off), without success.

  • Maybe we talk not about the same thing.
    My question is: can you access the card again, after connect to PC and disconnet from PC?
    If yes, i expect a notifcation, else i think there is a bug in the WCE.


    If you can access again:
    A quick, but bad, workaround is to poll for the storage device.
    To prevent that the card became unusable, try to format and use more then one partition and keep the user informed when one partition is demaged.
    Hope this helps.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Quote from "fs-support_ZU"


    My question is: can you access the card again, after connect to PC and disconnet from PC?


    No, we have to mount the sdcard manually after the NetDCU device was connected to a PC.

  • Ok, that is bad,
    Can you do a quick test please. Configure USB memory as mass storage, does it behave in the same way?


    PS: did you checked different SD Cards?

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Quote from "fs-support_ZU"


    Configure USB memory as mass storage, does ist behave in the same way?


    What exactly do you mean?


    As I already mentioned above, the NetDCU device is configured as mass storage (HKLM\Drivers\USB\FunctionDrivers\DefaultClientDriver = "Mass_Storage_Class"). The intern sdcard is used by the NetDCU device and the PC in order to exchange data. The problem is the simultaneously access on the sdcard through both, the device and the PC, which sometimes lead to corrupted data on the sdcard.


    In order to avoid simultaneously access we need to detect when the device is connected AND disconnected to a PC. There is no problem to detect a connection with the PC, because of the automatically unmounted sdcard. But we still need a method to detect the disconnecting, the sdcard is not remounted automatically.

  • My intension was to get more details were the problem comes from:
    instead of SDCARD configure HARD DISK as mass storage device.
    If this works correct, HARD DISK is usable after disconnect from PC, we know that the error is caused by the sd driver, else WCE may cause the problem.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • This isn't possible. Tests while evaluating the NetDCU10 device showed, that the system gets unusable when the HARD DISC is configured as mass storage, because the HARD DISC is unmounted automatically on connecting to a PC and the system can't access it any longer.

  • Replace "Storage Card" by "Hard Disk" in Registry and plug in a USB memory does not work?
    Mean you don't see SB memory stick as mass storage device?

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • That seems to make no difference. I can detect when the USB memory is plugged in and out into the NetDCU device. But I still can't detect if the NetDCU device is connected to a PC. The "Hard drive" is automatically unmounted when the NetDCU device is connected to the PC, but it isn't mounted again when disconnecting the PC - it is the same behavior as with the SDCARD.

  • Ok, many thanks for this test,
    then the device drivers should not cause the problem, it seems to be related to WCE or Storage Manager. I will check the www for a resolution.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Any progress so far? I want to remember, that we only need a safe method to detect if the NetDCU device is connected to or disconnected from the PC (while using the mass storage driver).