title: Reading from already open COM (serial) port?
body: <p>I am trying to control a bench multimeter (GW Instek GDM-8251A) from excel/vba.
  I could not find a description of the protocol so I need to reverse engineer it.</p>
  
  <p>The communication method is serial over usb.</p>
  
  <p>So I have loaded in VBA the module from the following page with offers functions for talking to the COM ports using the windows API.</p>
  
  <p><a href="http://www.thescarms.com/vbasic/commio.aspx" rel="nofollow noreferrer">http://www.thescarms.com/vbasic/commio.aspx</a></p>
  
  <p>Which had been recommended from a previous <a href="https://stackoverflow.com/questions/569698/what-is-the-best-way-to-access-a-serial-port-from-vba">SO thread</a></p>
  
  <p>So the plan was to open the supplied DMMVIEWER application and listen on the traffic to and from the device.</p>
  
  <p>However the issue is that when I run the CommOpen function, which itself calls the CreateFile win32 API, I get the following error if the DMMVIEWER is already running.</p>
  
  <p>The exact parameters are as follows</p>
  
  <pre><code>CreateFile(strPort, GENERIC_READ Or _
          GENERIC_WRITE, 0, ByVal 0&amp;, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
  </code></pre>
  
  <p>or exactly this</p>
  
  <pre><code>CreateFile( "COM4", -1073741824 , 0 , 0 3 ,128 ,0)
  </code></pre>
  
  <p>This returns the following error.</p>
  
  <pre><code>COM Error: Error (5): CommOpen (CreateFile) - Access is denied.
  </code></pre>
  
  <p>I have the alternative of using wireshark in usb capture mode, but then all the USB overhead is making it even harder to understand the underlying protocol.</p>
  
  <p>Also doing this from excel/vba makes it much easier to experiment sending data and seeing what happens.</p>
  
  <p>So my question is this. How can I open a COM port in a non-exclusive read mode so that I can sniff serial traffic ?</p>
  
  <p>Thanks !</p>
  
  <p>I plan to release my findings about the protocol and the VBA code to the sigrok.org project BTW.</p>
  
  <p>(BTW I tried freeserialanalyzer.com but it was extremely limited 15 day trial and limited to 5 captures, which wasn't even enough to configure the capture properly, also this software is so expensive that I couldn't even find the price, probably like 800$. I also tried realterm, which can save serial stream to text, however the sniffing an existing connection requires a special driver which I couldn't find and apparently requires a donation. I tried portmon but the capture option remained grayed out)</p>