version 3
SEND PACKET ({docRef; }packet)
Parameter | Type | Description | |
docRef | DocRef | Document reference number, or | |
Current channel (serial port or document) | |||
packet | String | String or Text to be sent |
Description
SEND PACKET sends a packet to a serial port or to a document. If docRef is specified, the packet is written to the document referenced by docRef. If docRef is not specified, the packet is written to the serial port or document previously opened by the SET CHANNEL command. A packet is just a piece of data, generally a string of characters.
Before you use SEND PACKET, you must open a serial port or a document with SET CHANNEL, or open a document with one of the document commands.
When writing to a document, the first SEND PACKET begins writing at the beginning of the document unless the document was opened with Append document. Until the document is closed, each subsequent packet is appended to any previously sent packets.
Version 6 Note: This command is still useful for a document opened with SET CHANNEL. On the other hand, for a document opened with Open document, Create document and Append document, you can now use the new commands Get document position and SET DOCUMENT POSITION to get and change the location in the document where the next writing (SEND PACKET) or reading (RECEIVE PACKET) will occur.
Important: SEND PACKET writes Mac OS ASCII data on both Windows and Macintosh platforms. Mac OS ASCII data uses eight bits. Standard ASCII uses only the lower seven bits. Many devices do not use the eighth bit in the same way as does Windows/Macintosh. If the string to be sent contains data that uses the eighth bit, be sure to create an ASCII map to translate the ASCII characters, and execute USE ASCII MAP before using SEND PACKET. You can also use the Mac to Win function (for more information, refer to the example for this function). Protocols like XON/XOFF use some low ASCII codes to establish communication between machines. Be careful to not send such ASCII codes, as this may interfere with the protocol or even break communication.
Example
The following example writes data from fields to a document. It writes the fields as fixed-length fields. Fixed-length fields are always of a specific length. If a field is shorter than the specified length, the field is padded with spaces. (That is, spaces are added to make up the specified length.) Although the use of fixed-length fields is an inefficient method of storing data, some computer systems and applications still use them:
$vhDocRef := Create document ("") ` Create a document If (OK=1) ` Was the document created? For ($vlRecord; 1; Records in selection ([People])) ` Loop once for each record ` Send a packet. Create the packet from a string of 15 spaces containing the first name field SEND PACKET ($vhDocRef; Change string(15 * Char(Space); [People]First;1)) ` Send a second packet. Create the packet from a string of 15 spaces containing the last name field ` This could be in the first SEND PACKET, but is separated for clarity SEND PACKET ($vhDocRef; Change string (15 * Char(Space); [People]Last; 1)) NEXT RECORD([People]) End for ` Send a Char(26), which is used as an end-of-file marker for some computers SEND PACKET ($vhDocRef; Char(SUB ASCII Code)) CLOSE DOCUMENT ($vhDocRef) ` Close the document End if
See Also
Get document position, RECEIVE PACKET, SET DOCUMENT POSITION.