COMM OPEN statement

Purpose | Open a serial port.
Syntax | COMM OPEN "COM n" AS [#] hComm [CHR = ANSI|WIDE]
Remarks | Opens a serial port to begin communications, creating a relationship between a file number and a specific serial port device.
COM n | Identifies the serial port number, for example, COM1, COM4, etc. A colon must not follow the port specification. See Restrictions below.
hComm | A numeric expression specifying an unused PowerBASIC file number, in the range of 1 to 32767. This is typically provided by the FREEFILE function. The Number symbol (#) prefix is optional, but recommended for clarity. If the port was not opened successfully, the ERR system variable will contain the error code. Before actual communications through the port can commence, you must configure the communication parameters by using a COMM SET statement for each parameter.
Restrictions | A colon may not be used in the port name, as was common in DOS code. COMM OPEN cannot use an operating system file handle, nor open a port that is already in use. When opening ports above COM9, Windows requires the port name to be specified using the following syntax: COMM OPEN "\\.\COM15" AS #hComm
See also | Serial Communications, COMM CLOSE, COMM function, COMM LINE, COMM PRINT, COMM RECV, COMM RESET, COMM SEND, COMM SET, COMM TIMEOUT, FREEFILE, OPEN
Example | DIM hComm AS LONG hComm = FREEFILE COMM OPEN "COM1" AS #hComm COMM OPEN "COM2" AS #5