Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CreateFile WriteFile ReadFile with USB Port
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01162598
Message ID:
01176871
Vues:
19
>I have a device on a usb port which I can successfully write directly to. However, I am experiencing difficulties reading directly from the port.
>
>Everything below works (the commands go to the device) until it gets to the readfile portion. The device is sending data back but the readfile() is not capturing it. Any ideas?
>
>
>*--lc_DeviceName is returned from SetupDiGetDeviceInterfaceDetail
>lh_Device = CreateFile(lc_DeviceName, ;
>      GENERIC_READ + GENERIC_WRITE ,;
>      FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_ALWAYS,;
>      FILE_ATTRIBUTE_NORMAL + FILE_FLAG_SEQUENTIAL_SCAN, 0)
>
>IF (lh_Device != INVALID_HANDLE_VALUE)	&& Later test using DeviceIoControl From Lh_Device also
>
>   lw_Buffer = SPACE( MAX_PATH )
>   lcSendValue = [! U1 MCR 80 T1 T2] + CHR(10) + CHR(13) && a command the USB device recognizes
>   lnWritten = 0
>
>   IF WriteFile(lh_Device, lcSendValue, LEN(lcSendValue),@lnWritten,0) <> 0 && 0 is failure
>
>        *!!!! Success - the device responds to the command sent
>        *!!!! Now capture the data returning from the device (the response)
>
>	lcReadBuffer = REPLICATE(" ",MAX_PATH)
>	lnBytesReturned = 0
>	lnCounter2 = 0
>
>        *--Latest attempt is to loop through a read for awhile
>	DO WHILE lnBytesReturned == 0
>		lncounter2 = lncounter2 + 1
>		IF ReadFile(lh_Device, @lcReadBuffer, LEN(lcReadBuffer), @lnBytesReturned, 0) <> 0
>		   lncounter = 0
>		   DO WHILE lncounter < 50
>			lncounter = lncounter + 1
>		        DOEVENTS
>			IF !EMPTY(MakeANSI(lcReadBuffer))
>			    ? lcReadBuffer
>			    ? MakeANSI(lcReadBuffer)
>			ENDIF
>		   ENDDO
>		   * ADD GetQueuedCompletionStatus()
>		ENDIF
>		IF lncounter2 = 100
>		   EXIT
>		ENDIF
>	ENDDO
>   ENDIF
>   CloseHandle( lh_Device )
>ENDIF
>
Sorry Tracy - I'm way behind you in this area but interested in reading data from USB scanners - if I get anywhere I'll let you know

Colin
Specialist in Advertising, Marketing, especially Direct Marketing

I run courses in Business Management and Marketing
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform