Language Reference - Appendix

COM Ports and Serial Devices

Formats

1.

Open Device in Windows:

OPEN (chan[,fileopt])"port:"

2.

Open Device in Windows:

OPEN (chan,fileopt,OPT=string$)"port:"

3.

Open Device in UNIX:

OPEN (chan[,fileopt])dev_path$

Where:

chan

Channel or logical file number to assign to the file.

dev_path$

Path to a UNIX device file.

fileopt

File options. Supported options for opening a COM port include:

BSZ=num

Block size

 

ERR=stmtref

Error transfer

 

ISZ=num

Open file in binary mode

 

NBF=num

Dedicated number of buffers

OPT=string$

Options for Windows Only (See Windows OPT= Settings)

port:

Port ID (e.g. OPEN(1,settings$)"COM2:").

string$

String defining the characteristics of the connection.

stmtref

Program line number or statement label to which to transfer control.

Description

You can OPEN a COM port for direct serial communication and gain access to special serial devices, including label printers, weigh scales, modems, and access card readers.

Some devices, such as modems, involve two-way communications where you can set up tasks such as background processes to monitor the port with ACK-NAK and/or READ-do processing. Other devices, such as label printers, use one-way serial communication; e.g. in PRINT statements.

Format 1

Open Device in Windows

OPEN (chan[,fileopt])"port:"

When you OPEN a serial device in Windows, PxPlus uses the current Windows "mode" settings for the port.

Format 2

Open Device in Windows

OPEN (chan,fileopt,OPT=string$)"port:"

Use this format in Windows to open a serial device for direct access.

For Windows only, you can include OPT=string$; e.g. in OPEN(1,OPT=settings$)"COM2:", the string variable in the OPT= option contains settings for the attributes.

Note:
If the OPT= option is omitted from the communications settings, PxPlus will default to the setup in the Windows Control Panel.

Windows OPT= Settings

The settings for the OPT= option use the following attributes and format. Note that flow_rate is optional.

OPT="baud_rate,parity,data_bits,stop_bits[,flow_rate]"

Where:

baud rate

Valid range is 300 to 115200.

data_bits

Use one of three valid values: 1, 7 or 8.

flow_rate

(Optional) Valid values include:

x - XON/XOFF software flow
p - RTS/CTS physical/hardware flow

(Omit the value for "None")

parity char

Use one of three alpha characters:

N - None
O - Odd parity
E - Even parity

stop_bits

Use one of the valid values: -1 (minus one), 0 (zero), 1, 1.5, 2.

Example:

The setting$ assigned in the Windows example below are for the serial communications attributes: baud rate, parity (n=none), data bits (8), stop bit (1) and flow rate (xon/xoff switch).

12540 let setting$="9600,n,8,1,x"
12550 let printer=hfn
12560 open (printer,isz=1,opt=setting$,err=13000)"COM2:"
12570 print (printer)"Title"

Format 3

Open Device in UNIX
 
OPEN (chan[,fileopt])dev_path$

When you OPEN the serial device using this format in UNIX, the port is opened with the current characteristics. To change the settings, you can either set line characteristics at the OS level before starting PxPlus or use an INVOKE directive after you open the device:

INVOKE "stty 38400 -IXANY IXON IXOFF ... </dev/tty2A"

Note:
WindX Tip - While it is possible to open a serial device on the client PC by using the [WDX] tag, this is not recommended. Instead, use a CALL from the host to a [WDX] sub-program on the remote client PC. Design your sub-program to open and control the device and its settings. You can return your results to the host via your CALL's parameters.

See [WDX] Direct Action to Client Machine.

See Also

OPEN Open a File for Processing