Jim,
This looks like it will do the trick. Thanks! A couple of questions though:
1) Where can I get more documentation on the mscomm32.ocx properties and methods? Is the same as the "Microsoft communication Control version 6.0 - activex control.
2) Where can I get more documentation on the vfpcom properties and methods? Where is this class/utility defined?
3) I assume that I should make calls to the incomm class's oncommm method, inside the loop. I am assuming based on the code that the loserin object's input property holds the stream of characters. The documentation for the activex control says that:
input is write only and that it:
'returns and removes a string of characters from the receive buffer'
Do you have to clear loserin.input, or does it automatically get cleared when you read it?
4) I know that doevents is supposed to 'execute all pending windows events'. Could you explain what it is doing in this context here?
TIA
>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.