Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need to read string from serial port for bar code app
Message
From
02/05/2002 09:07:19
 
 
To
01/05/2002 11:56:11
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00651375
Message ID:
00651783
Views:
18
David,

If your are willing to try MSCOMM32.OCX and the VFPCOM utility, the following might work for you.
#DEFINE eol CHR(13)+ CHR(10)
SET SAFETY OFF
SET RESOURCE OFF
_SCREEN.VISIBLE = .F.

PUBLIC cinbuffer
cinbuffer = ""

loserin = NEWOBJECT("MSCOMMLib.MSComm")
loinhandler = NEWOBJECT("InComm")
lovfpcom = NEWOBJECT("VFPCOM.ComUtil")
lovfpcom.bindevents(loserin,loinhandler)

* Adjust to suit port requirements
WITH loserin
  .commport = 2
  .settings = '9600,N,8,1'
  .handshaking = 2
  .rthreshold = 1
  .sthreshold = 0
  .rtsenable = .T.
  .portopen = .T.
ENDWITH

* Set up loop here to test cinbuffer for eol
* If cinbuffer contains eol, process data,
* clear cinbuffer, and wait for next line
DO WHILE !FILE("c:\stop.txt")
	IF eol$(cinbuffer)
		* process data
		* clear cinbuffer
	ENDIF
	* fastdoevents() by DF a better choice in VFP6
	doevents
ENDDO
DO cleanup

DEFINE CLASS incomm AS CUSTOM
  PROCEDURE oncomm
    DO CASE
      CASE loserin.commevent <> 2
        * Error handling?
      CASE loserin.commevent = 2
        LOCAL numchars
        WITH loserin
          cinbuffer = cinbuffer + loserin.INPUT
        ENDWITH
    ENDCASE
  ENDPROC
ENDDEFINE

PROCEDURE cleanup
  lovfpcom.unbindevents(loserin,loinhandler)
  WITH loserin
    IF .portopen = .T.
      .rtsenable = .F.
      .portopen = .F.
    ENDIF
  ENDWITH
  ON KEY LABEL esc
  RELEASE cinbuffer
  CLEAR ALL
  SET SAFETY ON
  SET RESOURCE ON
  CANCEL
ENDPROC
You will need to adjust your port settings and add appropriate processing in the DO loop. To kill the thing, fire up notepad and save anything to c:\stop.txt and it will exit. As you are using VFP6, see http://www.geocities.com/ResearchTriangle/9834/qgen006.htm for David F's fastdoevents replacement for the above 'doevents' to speed up the processing.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform