4D v14.3RECEIVE PACKET |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
RECEIVE PACKET
RECEIVE PACKET
RECEIVE PACKET reads characters from a serial port or from a document. If docRef is specified, this command retrieves data from a document opened using Open document, Create document or Append document. If docRef is omitted, this command retrieves data from the serial port or the document opened using SET CHANNEL. Whatever the source, the characters read are returned in receiveVar, which must be a Text, String or BLOB variable. If the characters have been sent by the SEND PACKET command, the type must correspond to that of the packet sent. Notes:
To read a particular number of characters, pass this number in numBytes. If the receiveVar variable is of the Text type, in a single call you can read up to 2 GB of text (theoretical value). To receive data until a particular string (composed of one or more characters) is encountered, pass this string in stopChar (the string is not returned in receiveVar). In this case, if the character string specified by stopChar is not found:
During execution of RECEIVE PACKET, the user can interrupt the reception by pressing Ctrl-Alt-Shift (Windows) or Command-Option-Shift (Macintosh). This interruption generates an error -9994 that you can catch with an error-handling method installed using ON ERR CALL. Usually, you will only have to handle interruption of a reception when communicating over a serial port. When reading a document, the first RECEIVE PACKET begins reading at the beginning of the document. The reading of each subsequent packet begins at the character following the last byte read. Note: This command is useful for document opened with SET CHANNEL. On the other hand, for a document opened with Open document, Create document or Append document, you can use the Get document position and SET DOCUMENT POSITION commands to get and change the location in the document where the next writing (SEND PACKET) or reading (RECEIVE PACKET) will occur. When attempting to read past the end of a file, RECEIVE PACKET will return with the data read up to that point and the variable OK will be set to 1. Then, the next RECEIVE PACKET will return an empty string and set the OK variable to zero. The following example reads 20 characters from a serial port into the variable getTwenty: RECEIVE PACKET(getTwenty;20) The following example reads data from the document referenced by the variable myDoc into the variable vData. It reads until it encounters a carriage return: RECEIVE PACKET(myDoc;vData;Char(Carriage return)) The following example reads data from the document referenced by the variable myDoc into the variable vData. It reads until it encounters the </TD> (end of table cell) HTML tag: RECEIVE PACKET(myDoc;vData;"</TD>") The following example reads data from a document into fields. The data is stored as fixed-length fields. The method calls a subroutine to strip any trailing spaces (spaces at the end of the string). The subroutine follows the method: $vhDocRef :=Open document("";"TEXT") ` Open a TEXT document The spaces at the end of the data are stripped by the following method, called Strip: For($i;Length($1);1;-1) ` Loop from end of string to start After a call to RECEIVE PACKET, the OK system variable is set to 1 if the packet is received without error. Otherwise, the OK system variable is set to 0. |
PROPERTIES
Product: 4D
HISTORY
Modified: 4D v11 SQL SEE ALSO
Get document position TAGS BOM ARTICLE USAGE
4D Language Reference ( 4D v14 R2) Inherited from : RECEIVE PACKET ( 4D v12.4) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||