4D v13.4RECEIVE PACKET |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v13.4
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 in Unicode mode (theoretical value) or 32,000 characters in non-Unicode mode (in this case, to specify the maximum number of characters, you can pass the MAXTEXTLENBEFOREV11 constant in numBytes. Compatibility note: In earlier versions of 4D (prior to version 11), databases usually worked with the ASCII character set (Mac-Roman), where each character is coded on one byte (8 bits). The numBytes parameter directly indicated the number of characters to be received. Beginning with version 11, databases work in Unicode mode (UTF-8 character set by default). In this mode, certain characters are coded on two bytes, like accented characters for example. The correspondence between the number of characters/number of bytes can thus vary. In this case, to control the number of characters received, it is preferable to either specify a character set of the Mac-Roman type via the USE CHARACTER SET command, or to use BLOBs or yet again to use the stopChar parameter. 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. Note: In non-Unicode mode (compatibility mode), when you use the RECEIVE PACKET command to read characters from a Windows document and do not want to use ASCII maps to convert Windows characters into Mac OS characters, you can use the Win to Mac function. 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
INDEX HISTORY
Modified: 4D v11 SQL SEE ALSO
Get document position TAGS BOM*** |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||