Search  
Wednesday, May 23, 2012 ..:: Forum ::.. Register  Login
 Forum Minimize
Pentru a putea posta mesaje trebuie să vă înregistraţi.
Notă: Mesajele cu conţinut jignitor sau ilegal (inclusiv cereri de soft piratat) nu sunt acceptate şi vor fi şterse imediat .

Pentru a primi raspunsuri rapide si corecte, scrieti in mesaj ce intentionati sa faceti, ce mesaj de eroare primiti, in ce context si in urma caror actiuni. De asemenea, mentionati versiunea de FoxPro in care lucrati!
Dacă nu specificați versiunea, se consideră VFP 9.0 SP2.

SearchForum Home
  Visual FoxPro  Win32 API  ReadFile() Writ...
 ReadFile() WriteFile() USB Device
 
 10/18/2006 4:04:08 PM
User is offlineholzert
3 posts


ReadFile() WriteFile() USB Device
 (United States)
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  && I never receive data or am not capturing it correctly
		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

  Visual FoxPro  Win32 API  ReadFile() Writ...

Search  Forum Home         

 Google Ads Minimize

    

Copyright 2002-2010 Profox   Terms Of Use  Privacy Statement