OpenComConfig
- Updated2023-02-21
- 4 minute(s) read
int OpenComConfig (int portNumber, char deviceName[], long baudRate, int parity, int dataBits, int stopBits, int inputQueueSize, int outputQueueSize);
Purpose
Opens a COM port and sets port parameters. If inputQueueSize or outputQueueSize is between 1 and 29, OpenComConfig forces it to 30.
OpenComConfig disables XON/XOFF mode and CTS hardware handshaking. Refer to the SetXMode, SetCTSMode, and SetComTime function descriptions if you want to change these defaults.
If the specified port is already open, OpenComConfig closes the port and then opens it again. Refer to the CloseCom function description for more information.
Use the Control Panel to set the port hardware I/O address and interrupt level.
You can use nonstandard baud rates. All baud rate values are interpreted literally by the comm driver.
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 to open, passed as an ASCII string. 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.
|
|||||||||||||||
baudRate | long | The baud rate for the selected port. Default Value: 9600 baud Valid Values: 110, 150, 300, 600, 1,200, 2,400, 4,800, 9,600, 14,400, 19,200, 28,800, 38,400, 56,000, 57,600, 115,200, 128,000, and 256,000.
|
|||||||||||||||
parity | int | The parity mode for the selected port. Default Value: 0—no parity Valid Values 0 = no parity 1 = odd parity 2 = even parity 3 = mark parity 4 = space parity |
|||||||||||||||
dataBits | int | The number of data bits for the selected port. Default Value: 7 data bits Valid Values: 5,6,7 or 8 data bits |
|||||||||||||||
stopBits | int | The number of stop bits for the selected port. Default Value: 1 stop bit Valid Values: 1 or 2 stop bits |
|||||||||||||||
inputQueueSize | int | The size of the input queue for the selected port. If you specify 0, OpenComConfig uses 512. If you specify a value greater than 0 but less than 30, OpenComConfig uses 30. There is no maximum limitation on the queue size. However, some serial drivers have a maximum of 32,767 and give undefined behavior when you use a larger queue size. NI recommends that you use a queue size no greater than 32,767. LabWindows/CVI passes this number to the Windows serial driver, which might use a different number. For example, the Microsoft serial driver imposes a minimum input queue size of 4,096 and requires that the input queue size be an even number. If you pass an odd number for inputQueueSize, LabWindows/CVI rounds it to the next highest even number. |
|||||||||||||||
outputQueueSize | int | The size of the output queue for the selected port. If you specify 0, OpenComConfig uses 512. If you specify a value greater than 0 but less than 30, OpenComConfig uses 30. If you specify a negative value for outputQueueSize, the output queue is not used and the data is written to the port directly. There is no maximum limitation on the queue size. However, some serial drivers have a maximum of 32,767 and give undefined behavior when you use a larger queue size. NI recommends that you use a queue size no greater than 32,767. (Linux) OpenComConfig ignores outputQueueSize. The serial driver determines the queue size.
|
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