LogMeTT.com • How to connect to USB Serial COM port?
Page 1 of 2

How to connect to USB Serial COM port?

Posted: Wed Aug 31, 2016 7:58 pm
by JamesL
So I wrote this up to connect to the first COM Port that has a valid connection and link. It starts from COM6 all the way to COM20.

If you try do a New Connection (Alt + N), choose Serial, and click on the drop down Port, it lists some options:
[img]Serial%20COM.png
[/img]

I want it automatically connect to COM port 10 because it is the only USB Serial Port. Is there any good way to do this?

I wrote this macro which connects to the first valid COM port that has a valid connection and link, and it starts from COM6 all the way up to COM20:


Re: How to connect to USB Serial COM port?

Posted: Thu Sep 01, 2016 3:31 pm
by JamesL
In this case, the USB serial adapter has COM port 10, but this is not always the case.

My computer has 5 default valid COM channels (COM1- COM5), but I can't assume that will be true for other people who will be running the macro.

I would prefer to have something that goes from COM1 to COM256 (MaxComPort=256 in TERATERM.ini), and selects the first valid COM port that has the USB Serial Port description, as seen in the selection menu.

Re: How to connect to USB Serial COM port?

Posted: Fri Sep 02, 2016 4:44 pm
by IshmaelCallMe
Probably easiest to try each COM port and then stay with the first one that actually responds with a login prompt (or whatever)

Re: How to connect to USB Serial COM port?

Posted: Tue Sep 06, 2016 6:34 pm
by JamesL
robably easiest to try each COM port and then stay with the first one that actually responds with a login prompt (or whatever)


Unfortunately the computers I'm working with have 5 default COM channels, COM1 through COM5 but this is not always the case. Sometimes you get a COM 6 or even COM 8 to replace one of the usual COM(1-5) channels.

Also, only one of the usual 5 COM ports is connected to a device that has serial output, but somehow they end up with a testlink result of 2. The extra USB serial COM port does not initially have any serial device attached to it (when the script runs).

Re: How to connect to USB Serial COM port?

Posted: Mon Sep 12, 2016 2:12 pm
by IshmaelCallMe
I am sure you could do it with an AutoIt script, but I don't think a pure TeraTERM script would be able to do what you describe then.

Re: How to connect to USB Serial COM port?

Posted: Mon Sep 12, 2016 6:49 pm
by JamesL
Not sure AutoIt would work, unless it could somehow read the "USB Serial Port" from the New Connection menu. Also recently found out that:

does the same thing as File > New Connection (Alt + N)

does the same thing as Setup > Serial Port

Re: How to connect to USB Serial COM port?

Posted: Mon Sep 12, 2016 7:29 pm
by IshmaelCallMe
Yep, just verified that Autoit can indeed read the "USB Serial Port" from the New Connection menu. It can only read the currently selected one, so it would have to scroll thru them all, but a script could do that faster than a user can see it happen.

Re: How to connect to USB Serial COM port?

Posted: Mon Sep 12, 2016 7:32 pm
by JamesL
It might be helpful if I could look at the source code for the Tera Term Macros.

Re: How to connect to USB Serial COM port?

Posted: Mon Sep 12, 2016 7:56 pm
by IshmaelCallMe
http://logmett.com/tera-term-source-code
https://osdn.jp/projects/ttssh2/scm/

Re: How to connect to USB Serial COM port?

Posted: Tue Sep 13, 2016 2:10 pm
by JamesL
Thanks for the info. Now I just gotta figure out how to use AutoIt to detect the USB Serial Port text as well as realize that (in this case) the COM port number we want is 10, which should just be some simple text parsing.

Re: How to connect to USB Serial COM port?

Posted: Tue Sep 13, 2016 3:17 pm
by IshmaelCallMe
Probably easiest is to use the callmenu to bring up the new connection dialog box. Then, this seems to work for me for the autoit script:



You can use this to call the AutoIt script from the TeraTERM script:



Or, probably simpler to just use the AutoIT script to start TeraTERM and also bring up the new connection window. Then just have a shortcut on the desktop for your users to start the AutoIT script.

Re: How to connect to USB Serial COM port?

Posted: Tue Sep 13, 2016 3:48 pm
by JamesL
Thanks!

Does that select the USB Serial Port COM channel from the New Connection window?

I would prefer using callmenu to open up the New Connection window only to identify the COM that corresponds to USB Serial Port.

Then I would use callmenu again to open up the Serial port setup window and actually switch to the correct USB COM. That way Tera Term macro logging still works.

Re: How to connect to USB Serial COM port?

Posted: Tue Sep 13, 2016 4:17 pm
by JamesL
Also looks like AutoIt can read from the window. Is there some way to extract the COM port number associated with USB Serial Port (in this case 10)?

Re: How to connect to USB Serial COM port?

Posted: Tue Sep 13, 2016 5:29 pm
by JamesL
The AutoIt script would have to somehow transfer the information about which COM port number corresponds to USB Serial Port back to the macro that called it. So in this case AutoIt would have to communicate "10" to the macro that calls it. Is there a way to do this?

Re: How to connect to USB Serial COM port?

Posted: Tue Sep 13, 2016 5:39 pm
by JamesL
Actually if AutoIt could select the right COM port from the Serial port setup window, that would be fine too

Re: How to connect to USB Serial COM port?

Posted: Tue Sep 13, 2016 10:32 pm
by IshmaelCallMe
The script as given should auto select the first port with "USB Serial Port" in it. You can always start the log with the "logopen" TeraTERM script command, or set auto logging in the ini file. You will have to have AutoIT installed on each PC, or compile the AutoIT script into a exe and distribute (and call) the exe.

Re: How to connect to USB Serial COM port?

Posted: Tue Sep 13, 2016 10:38 pm
by IshmaelCallMe
You might want to add some error checking such that if it doesn't find a appropriate port it will error out. Right now it will just loop forever. I will leave that as an exercise .... :smile:

Hint: See if it gets the exact same text twice in a row.

Re: How to connect to USB Serial COM port?

Posted: Wed Sep 14, 2016 2:18 pm
by JamesL
It would be much much better and simpler if we could just make AutoIt select the right COM port from the Serial port setup window:

File > New Connection (Alt + N)
Also selecting a COM from the New Connection opens up another Tera Term window, which is not at all desirable for me. I'd much prefer to have one Tera Term window open for each run of the test. Yes, there's probably a way to have AutoIt launch another macro for the new [USB Serial Port's] Tera Term COM window to log appropriately, but that includes making another macro just for scripting. This would add unnecessary complexity.

Setup > Serial Port
This doesn't open up any new Tera Term window, it just switches the COM in your currently open Tera Term window.

Re: How to connect to USB Serial COM port?

Posted: Wed Sep 14, 2016 5:08 pm
by IshmaelCallMe
Even simpler, dump http://www.naughter.com/enumser.html into a file and parse it, then open the correct COM with the 'connect' macro command.

Re: How to connect to USB Serial COM port?

Posted: Wed Sep 14, 2016 6:25 pm
by JamesL
ven simpler, dump http://www.naughter.com/enumser.html into a file and parse it, then open the correct COM with the 'connect' macro command.


So that would allow me to switch COM ports in the same Tera Term window, just like what the Serial port setup window does?

You said something about using the 'connect' macro command? How would I communicate to the macro which COM port number corresponds to the USB Serial Port?

Re: How to connect to USB Serial COM port?

Posted: Wed Sep 14, 2016 7:48 pm
by IshmaelCallMe
Yes, it will allow connection in the current TeraTERM window

Dump output of above tool into a file.
Use macro to read and parse file.
Macro opens correct COM with connect.

Re: How to connect to USB Serial COM port?

Posted: Fri Sep 16, 2016 3:25 pm
by JamesL
Is there a way to do it using only AutoIt and the Tera Term macro? I'd prefer not to use enumser

Re: How to connect to USB Serial COM port?

Posted: Fri Sep 16, 2016 4:43 pm
by boris
Check is this is something that can help http://logmett.com/support-forums/3/nee ... HELL#p8935

Re: How to connect to USB Serial COM port?

Posted: Fri Sep 16, 2016 9:35 pm
by JamesL
heck is this is something that can help http://logmett.com/support-forums/3/nee ... HELL#p8935


That only gives me a list of "COMx", where x is the COM numbers that show up in Setup > Serial port

Re: How to connect to USB Serial COM port?

Posted: Fri Sep 16, 2016 11:45 pm
by IshmaelCallMe
s 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.