• Support
  • Articles
  • Resources
  • Products

How to connect to USB Serial COM port?

Moderator: boris

  • 1
  • 2

29 postsPage 2 of 2

Moderator, LogMeTT and TTLEditor developer

Joined: Sat Jan 08, 2005 2:52 pm
by boris » Sat Sep 17, 2016 12:01 am
Well, I just suggested to "dig" into the direction of using PowerShell.

Below line executed from PowerShell

Code: Select all

  1. Get-WmiObject -Query 'SELECT Name, Description from Win32_PnPEntity WHERE Name LIKE "%USB-to-Serial%"' | Select-Object Name | sls COM 

gave me such result:
Prolific USB-to-Serial Comm Port (COM4)

Start from executing

Code: Select all

  1.  Get-WmiObject -Query 'SELECT Name, Description from Win32_PnPEntity

Scroll through the result printout and find your USB device. Modify LIKE pattern in the 1st command to match your device's name.

Redirect the result into text file and then you can open the text file from macro and extract the port #.
Best regards,

Joined: Wed Aug 31, 2016 7:20 pm
by JamesL » Mon Sep 19, 2016 8:29 pm
IshmaelCallMe wrote:
JamesL wrote:Is there a way to do it using only AutoIt and the Tera Term macro? I'd prefer not to use enumser

Well, sure. Modify the AutoIt script above to close the window instead of hit "OK" at the end. Then have it wait for the serial port setup dialog box and select the appropriate COM port that it parsed out of what it got from controlgettext.

The TeraTerm script will first start the AutoIt script, open the New Connection, then the serial port setup dialogs. It will depend on the AutoIt script to close each of them.

Sorry but I'm not at all familiar with AutoIt. It's also unlikely that I'll ever use it again. How would I determine the COM port number associated with the text "USB Serial Port", and then write this to a file that's in the same directory as the macro?

Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Tue Sep 20, 2016 2:48 pm
I suppose I could do consulting work on the side if you wish this written for you, if you don't have the time to attempt it yourself. Let me know if you are interested.

Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Wed Sep 21, 2016 1:51 pm
I needed a break from my regular stuff so I went ahead and did it. Required a little more than I thought, but it works.

Code: Select all

  2. $hwin = WinWait('Tera Term: New connection')
  3. ControlSend($hwin, '', 'Button10', '!e!r')
  4.     $tmp = WinGetText($hwin)
  5.     If StringInStr($tmp, 'USB Serial') Then
  6.         $ret = StringRegExp($tmp, @LF & 'COM[0-9]+:', 1)
  7.         WinClose($hwin)
  8.         $hwin = WinWait('Tera Term: Serial port setup')
  9.         Do
  10.             $tmp = WinGetText($hwin)
  11.             If StringInStr($tmp, StringTrimRight($ret[0], 1)) Then
  12.                 ControlClick($hwin, '', 'Button2')
  13.                 Exit
  14.             EndIf
  15.             ControlSend($hwin, '', 'ComboBox1', 'c')
  16.         Until Not StringCompare($tmp, WinGetText($hwin))
  17.         MsgBox(0, 'ERROR', $ret[0] & ' Not found')
  18.         Exit
  19.     EndIf
  20.     ControlSend($hwin, '', '', 'c')
  21. MsgBox(0, 'ERROR', 'No available USB serial port found')

To run it, you need to pop up the serial port setup box first

Code: Select all

  2. callmenu 50350
  3. callmenu 50110

Donate money to a local charity for my fee, if you wish! :)
Display posts from previous:
Sort by:
  • 1
  • 2

29 postsPage 2 of 2

Users browsing this forum: No registered users