tagCANDY CGI VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板) [ツリー表示へ]   [Home]
一括表示(VB.NET VB2005)
タイトルUSB通信について
記事No11192
投稿日: 2013/12/20(Fri) 10:42
投稿者ひで
初めて投稿させてもらいます。
以前、本や雑誌でのっておられる柏野さんのUSBドライバーを使用して
VB6.0でUSB通信をしていました。
今回VB2008、windows7にて同じように通信をしようと考えたのですが、一度は認識するのですが
2度目は認識しなくなりました。
XPでは、問題なく2度とも認識します。
非常に困っており、投稿してみました。
下記にプログラムをのせます。
ご教授いただけれないでしょうか。
よろしくお願いします。

**********************************標準モジュール******************************

    'USBドライバDLLファンクション
    Declare Function Uusbd_Open Lib "UUSBD.DLL" () As Integer
    'UPGRADE_NOTE: Class は Class_Renamed にアップグレードされました。 詳細については、'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"' をクリックしてください。
    Declare Function Uusbd_Open_mask Lib "UUSBD.DLL" (ByVal flag As Integer, ByVal Class_Renamed As Byte, ByVal SubClass As Byte, ByVal Vendor As Short, ByVal Product As Short, ByVal bcdDevice As Byte) As Integer
    Declare Function Uusbd_Close Lib "UUSBD.DLL" (ByVal hUSB As Integer) As Integer
    Declare Function Uusbd_OpenPipe Lib "UUSBD.DLL" (ByVal hUSB As Integer, ByVal Interface_num As Byte, ByVal pipe_num As Byte) As Integer
    Declare Function Uusbd_ResetPipe Lib "UUSBD.DLL" (ByVal hFile As Integer) As Integer
    Declare Function Uusbd_ResetDevice Lib "UUSBD.DLL" (ByVal hUSB As Integer) As Integer
    Declare Function Uusbd_ClassRequest Lib "UUSBD.DLL" (ByVal hUSB As Integer, ByVal dir_in As Integer, ByVal recipient As Byte, ByVal bRequest As Byte, ByVal wValue As Short, ByVal wIndex As Short, ByVal wLength As Short, ByVal data As Integer) As Integer
    Declare Function Uusbd_VendorRequest Lib "UUSBD.DLL" (ByVal hUSB As Integer, ByVal dir_in As Integer, ByVal recipient As Byte, ByVal bRequest As Byte, ByVal wValue As Short, ByVal wIndex As Short, ByVal wLength As Short, ByVal data As Integer) As Integer

    'ファイルハンドル入出力
    Declare Function WriteFile Lib "kernel32" (ByVal hFile As Integer, ByRef lpBuffer As Byte, ByVal nNumberOfBytesToWrite As Integer, ByRef lpNumberOfBytesWritten As Integer, ByVal lpOverlapped As Integer) As Integer
    Declare Function ReadFile Lib "kernel32" (ByVal hFile As Integer, ByRef lpBuffer As Byte, ByVal nNumberOfBytesToRead As Integer, ByRef lpNumberOfBytesRead As Integer, ByVal lpOverlapped As Integer) As Integer
    Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer

    '各種ハンドル
    Public hUSB As Integer      'USBハンドル
    Public hCMD As Integer      '計測コマンド出力
    Public hLED As Integer      'LED点灯制御
    Public hLCD As Integer      '液晶表示器への出力
    Public hMSR As Object       '計測データ入力


    'オープンするUSBターゲットデバイスのベンダIDとプロダクトID
    Public Const Vendor = &H9B9     'ベンダID
    Public Const Product = &H42   'プロダクトID

    'マスク条件設定ビット
    Public Const UU_MASK_NO = 0
    Public Const UU_MASK_CLASS = 1
    Public Const UU_MASK_SUBCLASS = 2
    Public Const UU_MASK_VENDOR = 4
    Public Const UU_MASK_PRODUCT = 8
    Public Const UU_MASK_BCDDEVICE = 16

*************************************************************************

*******************Form1*************************************************
        hUSB = Uusbd_Open_mask(UU_MASK_VENDOR + UU_MASK_PRODUCT, 0, 0, Vendor, Product, 0)
        Uusbd_Close(hUSB)

        hUSB = Uusbd_Open_mask(UU_MASK_VENDOR + UU_MASK_PRODUCT, 0, 0, Vendor, Product, 0)
        Uusbd_Close(hUSB)
****************************************************************************

結果は、一回目のhUSBは、0と返され、二回目では-1と返されます。

[ツリー表示へ]