Tutorial :howt to access COM port via script


I need to access COM port (console) via script to access our DSL modem. It should access in such a way that I can read all the messages printed on the console and i should also send commands to the console via script .

Please let me know if it is possible in TCL or php . Platform : Windows XP.

Also is there any way I can access the com port through script and console software such as teraterm simultaneously ?

Regards, Mithun


It is possible to use TCL to access a serial (COM) port using the standard TCL input and output commands. The main ones that you need to look at are the open and fconfigure commands. A google search for 'tcl open com1' will bring back lots of examples.

One thing worth noting is that the open and fconfigure commands changed in recent versions of TCL, TCL 8.5 I think, so depending on the version of TCL and age of the example some rework might be needed.


You just need to open the com1: device and fconfigure it to use the communications settings that the other side expects. For example:

set fd [open "com1:" r+]  fconfigure $fd -mode 9600,n,8,1  

Be aware that it can be messy to use event-driven IO with serial ports on all platforms.


Sounds like a job for Expect.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »