Application notes
Version 8 dated 15.03.00
185
Siemens Information and Communication Products
8.4.2.10
int OpenComm(lpszDevControl, cbInQueue, cbOutQueue)
LPCSTR lpszDevControl;/* address of device-control information */
UINT cbInQueue;
/* size of receiving queue
*/
UINT cbOutQueue;
/* size of transmission queue
*/
The OpenComm function opens a communications device.
int OpenComm(lpszDevControl, cbInQueue, cbOutQueue
Parameter
Description
lpszDevControl
Points to a null-terminated string that specifies the device in the form COMn or LPTn, where n is
the device number.
cbInQueue
Specifies the size, in bytes, of the receiving queue. This parameter is ignored for LPT devices.
cbOutQueue
Specifies the size, in bytes, of the transmission queue. This parameter is ignored for LPT devices.
Return value
≥
0 the return value identifies the open device if the function is successful.
Otherwise < 0
Errors:
If the function fails, it may return one of the following error values:
Value Meaning
IE_BADID the device identifier is invalid or unsupported.
IE_BAUDRATE the device’s baud rate is unsupported.
IE_BYTESIZE the specified byte size is invalid.
IE_DEFAULT the default parameters are in error.
IE_HARDWARE the hardware is not available (is locked by another device).
IE_MEMORY the function cannot allocate the queues.
IE_NOPEN the device is not open.
IE_OPEN the device is already open.
If this function is called with both queue sizes set to zero, the return value is:
IE_OPEN if the device is already open or
IE_MEMORY if the device is not open.
Example
The following example uses the OpenComm function to open communications port 1:
idComDev = OpenComm("COM1", 1024, 128);
if (idComDev < 0)
{ ShowError(idComDev, "OpenComm");
return 0;
}
err = BuildCommDCB("COM1:9600,n,8,1", &dcb);
if (err < 0)
{ ShowError(err, "BuildCommDCB");
return 0;
}
err = SetCommState(&dcb);
if (err < 0)
{ ShowError(err, "SetCommState");
return 0;
}