Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

OpenCom

LabWindows/CVI 8.5 Help
November 2007

NI Part Number:
370051K-01

»View Product Info

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 integer A number that indicates the COM port on which to operate.

This number maps to the COM port specified by deviceName in the call to OpenCom or OpenComConfig. 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 string 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
result integer The result of this function call. This code is a negative value that specifies the type of error that occurred.

Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit