LabWindows/CVI

Content Type
Programming Language
Current manual

OpenCom

int OpenCom (int portNumber, char deviceName[]);

Purpose

Opens a COM port using the default settings for the port parameters. If you want to set port settings, call OpenComConfig instead.

You can set parameters such as baud rate, data bits, parity, stop bits and flow control through the COM port configuration of the operating system.

OpenCom uses 512 bytes of the buffer for the input queue and 512 bytes for the output. OpenCom assumes the default baud rate, parity, stop bits, data bits, port address, and handshake mode established through the COM port configuration of the operating system. The timeout for I/O operations is 5 seconds. Refer to SetXMode, SetCTSMode, SetComTime, and OpenComConfig if you want to change these defaults.

If the specified port is already open, OpenCom closes the port and then opens it again.

Parameters

Input
Name Type Description
portNumber int A number that indicates the COM port on which to operate.

This number maps to the COM port specified by the deviceName parameter. The portNumber 1, for example, may not necessarily map to COM1.

(Linux) The portNumber 1, for example, may not necessarily map to /dev/ttyS0.

Valid Range: 1—1,000
deviceName char [] The name of the COM port in ASCII string format.

For example, deviceName can be "COM1" for COM port 1 under Windows using comm.drv.

(Linux) For example, deviceName can be "/dev/ttyS0" for COM port 1.

comm.drv, which comes with Windows, recognizes COM1 through COM4 only. Refer to the documentation for your Expanded Com Port Board for Device Names beyond COM4.

If you pass a NULL pointer or an empty string for deviceName, the library uses device names depending on the portNumber you specify. The following table shows the syntax for opening ports one through four. You can follow this model to open higher-numbered ports.

portNumber deviceName under Windows deviceName under Linux
1 "COM1" "/dev/ttyS0"
2 "COM2" "/dev/ttyS1"
3 "COM3" "/dev/ttyS2"
4 "COM4" "/dev/ttyS3"

Return Value

Name Type Description
returnValue int The result of this function call. This code is a negative value that specifies the type of error that occurred.

Additional Information

Library: RS-232 Library

Include file: rs232.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Was this information helpful?

Log in to get a better experience