COM Ports and Serial Devices |
1. |
OPEN (chan[,fileopt])"port:" | |
2. |
OPEN (chan,fileopt,OPT=string$)"port:" | |
3. |
OPEN (chan[,fileopt])dev_path$ |
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:
| |||||||||||||||
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. |
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.
OPEN (chan[,fileopt])"port:"
When you OPEN a serial device in Windows, PxPlus uses the current Windows "mode" settings for the port.
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.
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:
| ||
parity char |
Use one of three alpha characters: N - None | ||
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"
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"
OPEN Open a File for Processing