<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Rif.: Finding COM port  number  programatically. in LabWindows/CVI</title>
    <link>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3193318#M71663</link>
    <description>&lt;P&gt;Hi Mr. Eren BALCI,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes you are right. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.ni.com/i/smilies/16x16_smiley-happy.gif" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;Is some one here has some example prog/doc ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks and Regards,&lt;/P&gt;
&lt;P&gt;Rahul.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Sep 2015 09:02:22 GMT</pubDate>
    <dc:creator>RBD</dc:creator>
    <dc:date>2015-09-18T09:02:22Z</dc:date>
    <item>
      <title>Finding COM port  number  programatically.</title>
      <link>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3192159#M71645</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I am sure, many developer might have faced this similar issue.&amp;nbsp; If any one knows the answer please share with me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that when a device (serial or USB) is plugged into a computer, the computer automatically assigns a COM port number and next time if we pluged in the same device and if the previously assigned COM port is already engaged it will assign another COM port.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously I cannot change my program all the time.&amp;nbsp; What is the generic way to find the COM port assigned to a partcular device programatically ?&lt;/P&gt;
&lt;P&gt;NOTE : I am not using NI-VISA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to find out the COM number programatically and&amp;nbsp; update in my program.&amp;nbsp; Please help me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks and regards,&lt;/P&gt;
&lt;P&gt;Rahul.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 10:38:34 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3192159#M71645</guid>
      <dc:creator>RBD</dc:creator>
      <dc:date>2015-09-16T10:38:34Z</dc:date>
    </item>
    <item>
      <title>Rif.: Finding COM port  number  programatically.</title>
      <link>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3192817#M71658</link>
      <description>&lt;P&gt;I suppose the correct procedure is to register for a &lt;A href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363480(v=vs.85).aspx" target="_blank"&gt;WM_DEVICE_CHANGE&lt;/A&gt; OS message: if wParam&amp;nbsp;equals to &lt;A href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363205(v=vs.85).aspx" target="_blank"&gt;DBT_DEVICEARRIVAL&lt;/A&gt;&amp;nbsp;then you can decode lParam in a &lt;A href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363246(v=vs.85).aspx" target="_blank"&gt;DEV_BROADCAST_HDR&lt;/A&gt;: you'll probably find it to be &lt;A href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363248(v=vs.85).aspx" target="_blank"&gt;DBT_DEVTYP_PORT&lt;/A&gt;, in which case you can go further (but I can't help you anymore) and look for the port associated to the device.&lt;/P&gt;
&lt;P&gt;You can look at the sample code published &lt;A href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363215(v=vs.85).aspx" target="_blank"&gt;here on MSDN&lt;/A&gt; that can serve as a framework to elaborate on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All this imples to have the interface to Win32 API (formerly known as Win SDK) installed and some familiarity with OS programming.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 13:45:05 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3192817#M71658</guid>
      <dc:creator>RobertoBozzolo</dc:creator>
      <dc:date>2015-09-17T13:45:05Z</dc:date>
    </item>
    <item>
      <title>Rif.: Finding COM port  number  programatically.</title>
      <link>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3193289#M71662</link>
      <description>&lt;P&gt;If I understood everybody correctly, that would work only if the port swap occurs while the program is running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I think what he refers is the case that, the users may plug the USB-serial device to one of the many port available on a computer and this changes their COM port number.&lt;/P&gt;
&lt;P&gt;He wants the program, probably&amp;nbsp;during&amp;nbsp;startup, to automatically discover the COM port number a specific USB-serial device is assigned to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;Am I right?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;If yes, you need to read all hardware devices attached and get the&amp;nbsp;attributes of one that you will be able to discriminate with a unique identifier.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;This also requires making good use of Win32 API.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;So, good luck &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 08:12:00 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3193289#M71662</guid>
      <dc:creator>ebalci</dc:creator>
      <dc:date>2015-09-18T08:12:00Z</dc:date>
    </item>
    <item>
      <title>Rif.: Finding COM port  number  programatically.</title>
      <link>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3193318#M71663</link>
      <description>&lt;P&gt;Hi Mr. Eren BALCI,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes you are right. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.ni.com/i/smilies/16x16_smiley-happy.gif" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;Is some one here has some example prog/doc ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks and Regards,&lt;/P&gt;
&lt;P&gt;Rahul.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 09:02:22 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3193318#M71663</guid>
      <dc:creator>RBD</dc:creator>
      <dc:date>2015-09-18T09:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Finding COM port  number  programatically.</title>
      <link>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3193974#M71668</link>
      <description>You need to use the win sdk (win32 Ali) features and enumerate the registered com port. Once you have a list of ports you can look at their properties to find your usb device. &lt;BR /&gt;&lt;BR /&gt;Search the forum for comport enumeration, this was discussed at some stage. If you're still stuck for samples send me a pm.</description>
      <pubDate>Sun, 20 Sep 2015 19:17:43 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3193974#M71668</guid>
      <dc:creator>Jattie</dc:creator>
      <dc:date>2015-09-20T19:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding COM port  number  programatically.</title>
      <link>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3194043#M71670</link>
      <description>&lt;P&gt;You could start by examining &lt;A href="https://forums.ni.com/t5/LabWindows-CVI/Check-com-port/m-p/221306#M16380" target="_blank"&gt;this library provided by msaxon&lt;/A&gt;: it enumerates com ports found in the system; you can probably elaborate on the code to add informations you want to get the desired com port.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2015 07:32:55 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/3194043#M71670</guid>
      <dc:creator>RobertoBozzolo</dc:creator>
      <dc:date>2015-09-21T07:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Finding COM port  number  programatically.</title>
      <link>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/4092978#M88410</link>
      <description>&lt;P&gt;For LabWindows/CVI you need go to:&lt;/P&gt;
&lt;P&gt;-Tools and create .NET controller,&lt;/P&gt;
&lt;P&gt;-select&amp;nbsp; "System" in the list and a location and a name to place the controller you will create under the Target Instrument box, click ok&lt;/P&gt;
&lt;P&gt;-A window warning you about it will take a long time to compile the CVI wrapper will appear, click Yes&lt;/P&gt;
&lt;P&gt;-A list of identifiers will appear, check only the System.IO.Ports and click OK&lt;/P&gt;
&lt;P&gt;-An instrument will be generated that will appear under the Instrument option in the menu, if it doesn't appear there you can select the Load option and load the instrument recently created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you can use the System_IO_Ports_SerialPort_GetPortNames() function to know the number and names of all the serial ports available in the computer.&lt;/P&gt;
&lt;P&gt;//-------------------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;char **port_names;&lt;/P&gt;
&lt;P&gt;int number_of_ports;&lt;/P&gt;
&lt;P&gt;int INSTATUS=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Initialize_System();&lt;/P&gt;
&lt;P&gt;INSTATUS = System_IO_Ports_SerialPort_GetPortNames(&amp;amp;port_names, &amp;amp;number_of_ports, NULL);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;//-------------------------------------&lt;/P&gt;
&lt;P&gt;//here the code to parse the data from the port_names variable using the number_of_ports count&lt;/P&gt;
&lt;P&gt;//--------------------------------------&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use CDotNetFreeMemory() to free the memory used by the port_names variable strings.&lt;/P&gt;
&lt;P&gt;CloseSystem();&lt;/P&gt;
&lt;P&gt;//--------------------------------------------------------------------------------------------&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 18:51:35 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabWindows-CVI/Finding-COM-port-number-programatically/m-p/4092978#M88410</guid>
      <dc:creator>CGui</dc:creator>
      <dc:date>2020-10-21T18:51:35Z</dc:date>
    </item>
  </channel>
</rss>

