Article ID: 154741
Article Last Modified on 1/27/2005
* Transmitter Code.
* INIT event of Comm OLE control
* 28800 baud, no parity, 8 data, and 1 stop bit.
* In RS-232, maximum speed of 28800 baud can be used
This.Settings = "28800,N,8,1"
This.InputLen = 1
This.CommPort = 1
This.PortOpen = .T.
* ONCOMM event of Comm OLE Control
* The following code is needed to make sure that next set of characters
* can be transmitted (CommEvent = 2 is triggered from the receiver side)
IF This.CommEvent = 2
This.input
IF gnTop <= gnEnd
gcString = FREAD(gnFileHandle, 1) && Store to memory
q=asc(gcstring)
* change ASCII to character (size of 3) to preserve the lead char
thisform.olecontrol1.output = str(q,3)
gnTop = gnTop + 1
ENDIF
ENDIF
* INIT event of form
PUBLIC gnFileHandle
PUBLIC gnEnd
PUBLIC gnTop
PUBLIC q
* You should replace 'c:\sample.hlp' with your own binary file
STORE FOPEN('c:\sample.hlp') TO gnFileHandle && Open the file
STORE FSEEK(gnFileHandle, 0, 2) TO gnEnd && Move pointer to EOF
STORE FSEEK(gnFileHandle, 0) TO gnTop && Move pointer to BOF
gntop=1
q=""
-----------------------
Property of OleControl1
RThreshold = 1 * triggers when at least one char is on the buffer
SThreshold = 3
-----------------------
* Receiver Code.
* INIT event of OleControl1
* 28800 baud, no parity, 8 data, and 1 stop bit.
This.Settings = "28800,N,8,1"
This.InputLen = 3
This.CommPort = 1
This.PortOpen = .T.
* OnComm event
IF This.CommEvent = 2 AND This.InBufferCount > 0
qq=CHR(VAL(This.Input))
=FWRITE(gnFileHandle,qq)
this.output = CHR(26)
ENDIF
* INIT event of form
PUBLIC gnFileHandle
* You should replace 'c:\sample.hlp' with your own file name
IF FILE('c:\sample.hlp') && Does file exist?
gnErrFile = FOPEN('c:\sample.hlp',12) && If so, open read-write
ELSE
gnErrFile = FCREATE('c:\sample.hlp') && If not, create it
ENDIF
= FCLOSE(gnErrFile) && Close the file
STORE FOPEN('c:\sample.hlp',1) TO gnFileHandle && Open the file
* CLICK event of button
*This tells the transmitting side to start sending the file
Thisform.Olecontrol1.output = CHR(26)
-----------------------
Property of OleControl1
RThreshold = 3
-----------------------
The event-driven technique generates an OnComm event when there are
characters waiting in the input buffer. Also, the CommEvent property will
contain a numeric 2. For the OnComm event to be triggered, you must set the
Rthreshold property to a value other than zero (its default). The most
common setting for the RThreshold property is 1, meaning that the OnComm
event is triggered if a minimum of one character is waiting in the input
buffer. In this article, 3 is being used as a value of RThreshold property
because 3 characters at a time are being sent.
Keywords: KB154741