1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PORT is not opening in DOS mode

Discussion in 'C' started by thangaduraibeece, Jul 5, 2008.

  1. thangaduraibeece

    thangaduraibeece New Member

    Joined:
    Jul 4, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    i tried to run a c program in DOS mode.But when i run the c file,its showing the warning that the "port COM1 can not be opened and do you want to close the application or Ignore the application".When i ignore the warning,the program runs but the communication what i am expecting is no there....
    Could any one help me on this...
     
  2. XXxxImmortalxxXX

    XXxxImmortalxxXX New Member

    Joined:
    Jun 27, 2007
    Messages:
    569
    Likes Received:
    18
    Trophy Points:
    0
    dont know if this is what your needing but here

    Hi,

    Look to see if some other application is using the port. The most common
    cause of this problem is Windows itself. When Windows boots, it attempts to
    identify (PnP) connected devices, including the posibility of a serial mouse
    on Com1. If it "thinks" that it has detected a mouse, Windows assigns a
    mouse driver to the port -- this means that the port CANNOT be used by any
    other application!

    What causes this? The way that Windows attempts to locate a mouse is by
    toggling DTR and RTS during boot. It looks for serial data after this
    toggle. And, unfortunately, Windows is not very smart about this. If it
    sees ANY data (even data with framing, parity, or overrun errors), is still
    says, "Mouse. Assign driver!" If you have some sort of device on Com1 that
    spits out data at regular intervals, without a specific command, you system
    will be subject to this problem.

    The only real solution (the work arounds published in KB articles on the
    subject simply do not work, IME), is to make sure that any device on Com1 is
    disabled, or is not connected, until after Windows has finished PnP device
    identification.

    Dick

    posted by dick on the site

    http://bytes.com/forum/thread524785.html
     
  3. thangaduraibeece

    thangaduraibeece New Member

    Joined:
    Jul 4, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Dear Dick,

    I din't connect serial mouse on Comm1 and i am connecting it in USB port.But even then i am facing such error.I am using the following code for the port initialisation at every start up.
    /***************Code*********************************************/
    Code:
    void ConfigurePort (void)
    {
      int c;
    
      outportb(PORT1 + 1 , 0); 		/* Turn off interrupts - Port1 */
      oldport1isr = getvect(INTVECT); 	/* Save old Interrupt Vector for */
    
      setvect(INTVECT, PORT1INT); 		/* Set Interrupt Vector Entry */
      /* COM1 - 0x0C */
      /* COM2 - 0x0B */
      /* COM3 - 0x0C */
      /* COM4 - 0x0B */
      /* PORT 1 - Communication Settings */
    
      outportb(PORT1 + 3 , 0x80); 		/* SET DLAB ON */
      outportb(PORT1 + 0 , 0x0C); 		/* Set Baud rate - Divisor Latch Low Byte */
      /* Default 0x03 = 38,400 BPS */
      /* 0x01 = 115,200 BPS */
      /* 0x02 = 56,700 BPS */
      /* 0x06 = 19,200 BPS */
      /* 0x0C = 9,600 BPS */
      /* 0x18 = 4,800 BPS */
      /* 0x30 = 2,400 BPS */
    
      outportb(PORT1 + 1 , 0x00); 		 /* Set Baud rate - Divisor Latch High Byte */
      outportb(PORT1 + 3 , 0x1B);            /* 8 Bits, Even Parity, 1 Stop Bit */
      outportb(PORT1 + 2 , 0x00);            /* FIFO Control Register */
      outportb(PORT1 + 4 , 0x0B); 		 /* Turn on DTR, RTS, and OUT2 */
      outportb(0x21,(inportb(0x21) & 0xEF)); /* Set Programmable Interrupt */
      /* Controller */
      /* COM1 (IRQ4) - 0xEF */
      /* COM2 (IRQ3) - 0xF7 */
      /* COM3 (IRQ4) - 0xEF */
      /* COM4 (IRQ3) - 0xF7 */
      outportb(PORT1 + 1 , 0x01); 		/* Interrupt when data received */
    }
    
    /************************End*************************************/
     
    Last edited by a moderator: Jul 5, 2008

Share This Page