Microsoft KB Archive/318832

= PRB: Run-Time Error 8015 If You Try to Open the Serial Port with Microsoft Comm Control =

Article ID: 318832

Article Last Modified on 11/3/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q318832



SYMPTOMS
If you try to open the serial port with Microsoft Comm Control, you may receive the following error message:

Run-time error '8015': Could not set comm state, there may be one or more invalid communications parameters.



CAUSE
This behavior can occur if a serial printer driver is using the serial port that you are trying to open.



RESOLUTION
To resolve this behavior, disable the serial printer or attach it to another port. If you are using Microsoft Windows 2000 or Microsoft Windows XP, create a virtual COM port.



STATUS
This behavior can occur if the serial printer driver is not working correctly, and is not a problem with the MSComm32 Control.



MORE INFORMATION
To work around this behavior, create a new virtual COM port and use it instead of COM1.

WARNING: If anything else prints on the printer attached to COM1, your program may not work as expected.   Add the following code to the General Declarations section of Form1: Private Declare Function DefineDosDevice Lib &quot;kernel32&quot; Alias _ &quot;DefineDosDeviceA&quot; (ByVal dwFlags As Long, ByVal lpDeviceName _           As String, ByVal lpTargetPath As String) As Long Const DDD_RAW_TARGET_PATH = &H1  Add another Command button to Form1.  Add the following code in the Click event of Command2: DefineDosDevice DDD_RAW_TARGET_PATH, &quot;COM5&quot;, &quot;\Device\Serial0&quot;   Change the code on Command1 to open COM5: MSComm1.CommPort = 5  Run the program, click Command2, and then click Command1.</li></ol>

Steps to Reproduce the Behavior
<ol> Install a Generic Text printer, and then connect it to COM1 instead of LPT1.</li> Start a new Standard EXE project in Microsoft Visual Basic. By Default, Form1 is created.</li> Add the Microsoft Comm Control to the project.</li> Add a new MSComm1 control on Form1.</li>  Add a new Command button on Form1, and then insert the following code in the Click event: MSComm1.CommPort = 1 MSComm1.Settings = &quot;9600,N,8,1&quot; MSComm1.Handshaking = comNone MSComm1.InBufferSize = 1024 MSComm1.OutBufferSize = 512 MSComm1.RThreshold = 0 MSComm1.SThreshold = 0 MSComm1.InputLen = 0 MSComm1.PortOpen = True </li> Run the program, and then click Command1.</li></ol>

<div class="references_section">