Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


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.

↑ Back to the top


Cause

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

↑ Back to the top


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.

↑ Back to the top


Status

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

↑ Back to the top


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.

  1. Add the following code to the General Declarations section of Form1:
            Private Declare Function DefineDosDevice Lib "kernel32" Alias _
    "DefineDosDeviceA" (ByVal dwFlags As Long, ByVal lpDeviceName _
    As String, ByVal lpTargetPath As String) As Long
    Const DDD_RAW_TARGET_PATH = &H1
  2. Add another Command button to Form1.
  3. Add the following code in the Click event of Command2:
    DefineDosDevice DDD_RAW_TARGET_PATH, "COM5", "\Device\Serial0"
  4. Change the code on Command1 to open COM5:
    MSComm1.CommPort = 5
  5. Run the program, click Command2, and then click Command1.

Steps to Reproduce the Behavior

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

↑ Back to the top


References

For more information, see the DefineDosDevice function documentation in the Microsoft Developer Network (MSDN) under Platform SDK.

↑ Back to the top


Keywords: kberrmsg, kbmodem, kbprb, kbserial, kb

↑ Back to the top

Article Info
Article ID : 318832
Revision : 1
Created on : 1/7/2017
Published on : 6/19/2014
Exists online : False
Views : 297