title: Accessing COM-port with Windows 10
body: <p>I have some stupid code to access a Windows COM-port (just some pseudo-code of the most relevant functions):</p>
  
  <pre><code>// open device:
  COMMTIMEOUTS timeouts;
  DCB          ComSettings;
  
  memset(&amp;ComSettings,0,sizeof(ComSettings));
  ComSettings.DCBlength=sizeof(DCB);
  *fd=CreateFile(serialParams&gt;port,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
  GetCommState(*fd,&amp;ComSettings);
  ComSettings.BaudRate=9600;
  ComSettings.ByteSize=8;
  ComSettings.Parity=NOPARITY;
  ComSettings.fParity=0;
  ComSettings.StopBits=ONESTOPBIT;
  ComSettings.fOutX=FALSE;
  ComSettings.fInX=FALSE;
  ComSettings.fBinary=TRUE;
  ComSettings.fDtrControl=DTR_CONTROL_DISABLE;
  ComSettings.fRtsControl=RTS_CONTROL_DISABLE;
  ComSettings.fAbortOnError=FALSE;
  
  SetCommState(*fd,&amp;ComSettings);
  
  timeouts.ReadIntervalTimeout        =MAXDWORD;
  timeouts.ReadTotalTimeoutMultiplier =0;
  timeouts.ReadTotalTimeoutConstant   =0;
  timeouts.WriteTotalTimeoutMultiplier=0;
  timeouts.WriteTotalTimeoutConstant  =250;
  
  SetCommTimeouts(*fd, &amp;timeouts);
  </code></pre>
  
  <p>Reading of data from serial port is done with</p>
  
  <pre><code>ReadFile()
  </code></pre>
  
  <p>and writing with</p>
  
  <pre><code>WriteFile()
  </code></pre>
  
  <p>In my particular case the device is a USB gadget which connects as serial interface and where speed-settings and other things do not really matter.</p>
  
  <p>This code is working fine with all Windows variants including 8.1 but for Windows 10 some users report there is no communication possible with the device. Unfortunately I do not have the related Win10 version for testing.</p>
  
  <p>So my question: are there some issues/important changes in Windows 10 which could cause such a behaviour or require some changes in serial port communications?</p>
  
  <p>Thanks!</p>
  
  <p>****** <strong>Update</strong> ******************************************************************</p>
  
  <p>Just as update to this: function SetCommState() fails with an error 87 (ERROR_INVALID_PARAMETER). Here it does not matter if I set own parameters, if I use the data received from GetCommState() or if I completely initialise and configure the DCB-structure. So...is this a known bug in SetCommState() of Win 10?</p>
  
  <p>Just to note: it fails only in 4 of 5 cases, so it is not a systematic error, but a random one!</p>