Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CreateFile WriteFile ReadFile with USB Port
Message
From
17/10/2006 11:49:33
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
CreateFile WriteFile ReadFile with USB Port
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01162598
Message ID:
01162598
Views:
233
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
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Next
Reply
Map
View

Click here to load this message in the networking platform