|
|
|
![]() |
|
Strumenti |
![]() |
#1 | |
Senior Member
Iscritto dal: May 2003
Messaggi: 1113
|
[VB.NET] Problema API Connessione USB
Ciao ragazzi,
ho un problema nel convertire una mia applicazione da VB6 a VB.NET o meglio ho un problema con un mio driver che serve ad interfacciarsi con una periferica USB in quanto il VB.NET mi restituisce errore sulla chiamata alla API CreateFile(...) per la connessione con un determinato apparecchio, vi posto il codice che mi da errore ed il tipo di errore: Codice:
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, ByVal lpInBuffer As String, ByVal nInBufferSize As Long, ByVal lpOutBuffer As String, ByVal nOutBufferSize As Long, ByVal lpBytesReturned As Long, ByVal lpOverlapped As OVERLAPPED) As Long Private Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As String, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByRef lpOverlapped As OVERLAPPED) As Long Private Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As String, ByVal nNumberOfBytesToWrite As Long, ByRef lpNumberOfBytesWritten As Long, ByRef lpOverlapped As OVERLAPPED) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long 'Costanti delle WinAPI Private Const OPEN_EXISTING = 3 Private Const GENERIC_READ = &H80000000 Private Const GENERIC_WRITE = &H40000000 Private Const FILE_SHARE_READ = &H1 Private Const FILE_SHARE_WRITE = &H2 'Attributi di Sicurezza per la comunicazione Private Structure SECURITY_ATTRIBUTES Dim nLength As Long Dim lpSecurityDescriptor As Long Dim bInheritHandle As Long End Structure 'Gestisce la sincronia della comunicazione Private Structure OVERLAPPED Dim Ternal As Long Dim TernalHigh As Long Dim Offset As Long Dim OffsetHigh As Long Dim hEvent As Long End Structure 'Passo dalla Modalità Modem a quella Normal Public Function SwitchToNormal(ByVal ModemGuID As String) As String Dim DeviceHandle As Integer Dim Sa As SECURITY_ATTRIBUTES Dim OV As OVERLAPPED Dim nShare As Integer Dim ReceivedData As Integer 'Dati Ricevuti da USB Dim Response As Integer Dim ResponseString As String nShare = FILE_SHARE_READ Or FILE_SHARE_WRITE LenghtReceivedBuffer = 261 DeviceHandle = CreateFile("\\.\" & ModemGuID, GENERIC_WRITE, nShare, Sa, OPEN_EXISTING, 0, 0) .... .... End Function Quote:
__________________
| Athlon XP Barton 3000+ | CoolerMaster HAC-V81 | ASUS A7N8X DELUXE v2.0 | 2*256 PC3200 + 1*512 PC3200 = 1GB DDR400| ATI Radeon 9250 | HD 80Gb Maxtor SATA | Ali Q-TEC 550W Dual Fan GOLD PFC |
|
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: May 2003
Messaggi: 1113
|
Ok trovati e corretti gli errori...
solo che sebbene durante il debug tutto vada correttamente la periferica nn fa ciò che dovrebbe...e non riesco a capire xkè... ho anche confrontato i debug del codice VB.NET con quello del VB6 e sono identici..quindi tutto si svolge per bene, o almeno sembra, però i risultati non sono gli stessi... non capisco dove e cosa sto sbagliando... ![]()
__________________
| Athlon XP Barton 3000+ | CoolerMaster HAC-V81 | ASUS A7N8X DELUXE v2.0 | 2*256 PC3200 + 1*512 PC3200 = 1GB DDR400| ATI Radeon 9250 | HD 80Gb Maxtor SATA | Ali Q-TEC 550W Dual Fan GOLD PFC |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 21:45.