4D v14.3

SET CHANNEL

Home

 
4D v14.3
SET CHANNEL

SET CHANNEL 


 

SET CHANNEL ( port ; settings ) 
Parameter Type   Description
port  Longint in Serial port number
settings  Longint in Serial port settings
SET CHANNEL ( operation ; document ) 
Parameter Type   Description
operation  Longint in Document operation to perform
document  String in Document name

The SET CHANNEL command opens a serial port or a document. You can open only one serial port or one document at a time with this command. To close an opened serial port, pass SET CHANNEL (11).

Historical Note: This command was originally the first 4D command used for working with serial ports and documents on disks. Since that time, new commands have been added. Today, you will typically work with documents on disk using the commands Open document, Create document and Append document. With these commands, you can read and write characters to and from documents using Create document or RECEIVE PACKET (these commands work with SET CHANNEL, too). However, if you want to use the commands SEND VARIABLE, RECEIVE VARIABLE, SEND RECORD and RECEIVE RECORD, you must use SET CHANNEL to access the document on disk.

The description of SET CHANNEL is composed of two sections:

  • Working with Serial Ports
  • Working with Documents

The first form of the SET CHANNEL command opens a serial port, setting the protocol and other port information. Data can be sent with SEND PACKET, SEND RECORD or SEND VARIABLE, and received with RECEIVE BUFFER, RECEIVE PACKET, RECEIVE VARIABLE or RECEIVE RECORD.

The first parameter, port, selects the port and the protocol. You can address up to 99 serial ports (one at a time).
The following table lists the values for port:
Value for portDescription
0Printer port (Macintosh) or COM2 (PC) with no protocol
1Modem port (Macintosh) or COM1 (PC) with no protocol
20Printer port (Macintosh) or COM2 (PC) with sofware protocol such as XON/XOFF
21Modem port (Macintosh) or COM1 (PC) with sofware protocol such as XON/XOFF
30Printer port (Macintosh) or COM2 (PC) with hardware protocol such as RTS/CTS
31Modem port (Macintosh) or COM1 (PC) with hardware protocol such as RTS/CTS
101 to 199Serial communication with no protocol
201 to 299Serial communication with software protocol such as XON/XOFF
301 to 399Serial communication with hardware protocol such as RTS/CTS

Important: The value you pass in port must refer to an existing serial COM port recognized by the operating system. For example, in order to be able to use the values 101, 103 and 125, the serial ports COM1, COM3 and COM25 must have been set up correctly.

In a standard configuration Mac OS and Windows support two serial ports: on Mac OS, the modem port and the printer port; on Windows, the COM1 and COM2 ports. However, additional serial ports can be added by the use of extension boards. Originally, 4D only adressed two standard serial ports and it was only later that the support of additional ports was implemented. For compatibility reasons, both addressing systems were kept.

  • If you want to address a standard serial port (printer/COM2 or modem/COM1), you can either pass in the port parameter one of the following values 0, 1, 20, 21, 30 and 31 (that corresponds to the old addressing method), or a value greater than 100 (please see the following explanation).
  • If you want to address additional serial ports, you need to pass the value N+100 (where N is the value of the port to address). You may also consider adding 100 or 200 to the value mentioned above (N+100), if you want to select respectively a software or a hardware protocol.

If you want to use the printer/COM2 port with no protocol, you can use one of the following syntaxes:

 SET CHANNEL(0;param)

or

 SET CHANNEL(102;param)

If you want to use the modem/COM1 port with the XON/XOFF protocol, you can use one of the following syntaxes:

 SET CHANNEL(21;param)

or

 SET CHANNEL(201;param)

If you want to use the COM 25 port with the RTS/CTS protocol, you need to use the following syntax:

 SET CHANNEL(325;param)


The settings parameter sets the speed, number of data bits, number of stop bits, and parity. You determine the value for settings by adding the speed, data bits, stop bits, and parity values as listed in the following table. For example, to set 1200 baud, 8 data bits, 1 stop bit, and no parity, you would add 94 + 3072 + 16384 + 0 = 19550. You would then use 19550 as the value of the setup parameter.
Value to accumulateDescription
in settings parameter
Speed 380 300
(in baud) 189 600
941200
62 1800
46 2400
30 3600
22 4800
14 7200
10 9600
4 19200
2 28800
1 38400
0 57600
1022115200
1021230400
Data bits 0 5
2048 6
1024 7
3072 8
Stop bits 16384 1
–32768 1.5
–16384 2
Parity 0 None
4096 Odd
12288Even

Tip: The various numeric values to be accumulated and passed in port and settings (but not including the values for COM1...COM99) are available as predefined constants in the theme Communications within the Design environment Explorer windows. For COM1...COM99, use numeric literals.

The second form of the SET CHANNEL command allows you to create, open, and close a document. Unlike the System Documents commands, it can open only one document at a time. The document can be read from or written to.

The operation parameter specifies the operation to be performed on the document specified by document. The following table lists the values of operation and the resulting operation with different values for document. The first column lists the allowed values for operation. The second column lists the allowed values for document. The third column lists the resulting operation.

For example, to display an Open File dialog box to open a text file, you would use the following line:

 SET CHANNEL(13;"")
Operation Document Result
10 StringOpens the document specified by String.
If the document doesn’t exist, the document is opened and created.
10 "" (empty string) Displays the Open File dialog box to open a file.
All file types are displayed.
11 none Closes an open file.
12 "" (empty string) Displays the Save File dialog box to create a new file.
13 "" (empty string) Displays the Open File dialog box to open a file. Only text file types are displayed.

All of the operations in this table set the Document system variable if appropriate. They also set the OK system variable to 1 if the operation was successful. Otherwise, the OK system variable is set to 0.

See examples for the commands RECEIVE BUFFER, SET TIMEOUT and RECEIVE RECORD.

 
PROPERTIES 

Product: 4D
Theme: Communications
Number: 77

The OK variable is changed by the commandThis command modifies the system Document variable

 
HISTORY 

Created: < 4D v6

 
SEE ALSO 

Append document
Communications
Create document
GET SERIAL PORT MAPPING
Open document
RECEIVE BUFFER
RECEIVE PACKET
RECEIVE RECORD
RECEIVE VARIABLE
SEND PACKET
SEND RECORD
SEND VARIABLE
SET TIMEOUT

 
ARTICLE USAGE

4D Language Reference ( 4D v11 SQL Release 6)
4D Language Reference ( 4D v12.4)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v13.5)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)