COMOPEN
The COMOPEN instruction initializes a communications device. The communications device may be a local port, a Windows or Linux socket, or an RMS pipe. The instruction uses the following format:
|
|
|
|
|
Where:
label
Optional. A Program Execution Label.
comfile
Required. A previously defined COMFILE definition.
parameters
Required. A formatted Character String Variable or Literal that initializes the communications device.
Flags Affected: NONE
Note the following:
If {comfile} is currently open, a COMCLOSE is performed prior to the COMOPEN.
For local communication port, the {parameters} string is a comma-delimited list. The following format is required for proper initialization:
The device number is the first parameter. It must be in the range of one (1) through fifteen (15) inclusive that correspond to COM1 through COM16.
The baud rate is the second parameter. It must be one of the following values: 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 56000, 57600, 115200, 128000, and 256000.
The number of bits in the character is the third parameter. It must be 7 or 8.
The parity of the transmitted character is the fourth parameter. It must be one of the following values: N, E or O that correspond to None, Even or Odd.
The number of stop bits is the fifth parameter. It must be one (1) or two (2).
Under PLBWIN and PLBCON, the {parameters} string parsing has been modified to allow fields that are omitted and default values used. At a minimum, the port number must be specified.
The default {parameter} values when using the PLBCON runtime are as follows:
|
Baud |
9600 |
|
Data bits |
8 |
|
Parity |
None |
|
Stop Bits |
1 |
The PLBWIN runtime uses the current Windows configuration values as the default settings. The initial values are defined using the Control Panel. After a communications port is used by any application, the settings are left in the state applied by that application.
Under Windows, an additional character may be added to the end of {parameters} for flow control. The flow control character may be an 'H' for hardware flow control or 'X' for XON/XOFF flow control.
For sockets, the {parameters} string is a comma-delimited list. The following format is required for proper initialization:
The protocol is the first parameter. This value must always be “S” for Sockets to be created as an IPV4 connection. This value must be "S6' for Sockets to created as an IPV6 connection.
The open mode is the second parameter. The value may be “O” for open or “C” for create.
The address is the third parameter . This value is the local TCP/IP address. If the first parameter value is "S", the local TCP/IP address must be an IPV4 address format or a URL that resolves to an IPV4 address. If the first parameter value is "S6", the local TCP/IP address must be an IPV6 address format or a URL that resolves to an IPV6 address. Any other value will cause an I97 error. This value is only required for the Open mode and is disregarded if the mode is Create and the first parameter is "S".
The socket number is the fourth parameter.
The transmission mode is the fifth parameter. This value is “C” for cooked or “R” for raw. Cooked mode will add a four (4) byte internal header to each message. This header ensures that if the message is split into multiple parts, it is reassembled correctly at the receiving end. The default mode is (R)aw.
The input buffer size is the sixth parameter. The default size of the buffer is 1,024 bytes.
The output buffer size is the seventh parameter. The default size of the buffer is 1,024 bytes.
Socket communications do not support UDP.
For Datapoint RMS pipes, the {parameters} string is a comma-delimited list. The following format is required for proper initialization:
The protocol is the first parameter. The value must always be "P" for RMS Pipes.
The open mode is the second parameter. The value may be "O" for open or "C" for create.
The pipe name is the third parameter. This value is the RMS style name of the pipe.
The close mode is the fourth parameter. This value is "D" for delete or "U" for unchanged. The default mode is (U)nchanged.
The transmission mode is the fifth parameter. This value is "C" for cooked or "R" for raw. Cooked mode will add or remove an end of record to each message. The default mode is (C)ooked.
The buffer size is the fifth parameter. The default size of the buffer is 1,024 bytes.
An I97 error is generated if the parameter list is not in the correct format or some other type of error occurs while trying to open the communications device. The extended error code is set to the parameter causing the problem. For example, if the baud rate specified is incorrect for a local communication port open, the extended error code is set to two (2).
For a Linux runtime, the {parameters} can be a file or device name that is opened directly and used by COMREAD and COMWRITE instructions.
Example:
If the first parameter value is "S6" (10.7), the following examples show allowed IPV6 URI formats.
Opens a socket connection to a local IPV6 address.
Opens a socket connection to an IPV6 URL that resolves to an IPV6 address.
Creates a listening socket for a local IPV6 address.
See Also: Example Code, Communication I/O Instructions
![]() |