title: Serial COM Port not opening
body: <p>I am trying to open the serial COM PORT in a Win32 Application. The port is opening correctly but I can send a receive bytes just if I previously opened it using Teraterm or Hyperterminal.</p>
  
  <p>If I deactivate and activate the COM port from Device Manager (so the port is freshly unused) I need to simply open the COM port with Teraterm or Putty and afer I closed it  and then run my software I can send and receive properly at anytime. </p>
  
  <p>I am using Embarcadero X3 with FileMonkey to make the application compatible with MACOSX and Win32 at the same time. FileMonkey does not suuport VCL.</p>
  
  <p>The same code is working fine on Builder 6 c++ using VCL but it should not influence it in anyway. My code is really simple.</p>
  
  <p>This is a very weird behavior. Seems like I need to INIT the COM (I am using FTDI converter) before I can use it and when the PC restarts or I deactivate and activate back the COM from Device Manager it seems this INIT is vanished and I simply need to open up the COM to revive it using another Serial Software and then use my software.</p>
  
  <p>Note: Once the port is INIT I have the full control from my software. I am sure my code is truly opening the COM port because the COM appears busy once the iNIT is done if I try to use it with other softwares. So no flase alarm and more the application is working on the other side so far.</p>
  
  <p>I have this problem since long and I now decided to solve it! </p>
  
  <p>This is my code:</p>
  
  <pre><code>// GLOBAL VARIABLES
  HANDLE hComm = NULL;
  COMMTIMEOUTS ctmoNew = {0}, ctmoOld;
  
  DCB dcbCommPort; 
        hComm = CreateFile("COM2",
  
                        GENERIC_READ | GENERIC_WRITE,
                        0,
                        0,
                        OPEN_EXISTING,
                        0,
                        0);
  
      if(hComm == INVALID_HANDLE_VALUE)
       {
  
          Application-&gt;Terminate();
       }
  
      GetCommTimeouts(hComm,&amp;ctmoOld);
      ctmoNew.ReadTotalTimeoutConstant = 100;
      ctmoNew.ReadTotalTimeoutMultiplier = 0;
      ctmoNew.WriteTotalTimeoutMultiplier = 0;
      ctmoNew.WriteTotalTimeoutConstant = 0;
      SetCommTimeouts(hComm, &amp;ctmoNew);
      dcbCommPort.DCBlength = sizeof(DCB);
      GetCommState(hComm, &amp;dcbCommPort);
      BuildCommDCB("115200,N,8,1", &amp;dcbCommPort);
      SetCommState(hComm, &amp;dcbCommPort);
  </code></pre>