问题
1) Is there any freeware which combine tcl editor and compiler (or interpenter)?
2) After opening of the serial connection (COM1) using fconfigure , how can I send via the connection, a string of several words? I need to connect to some HW and I want to be able running a scripts on its CLI.
Thanks
回答1:
- Is there any freeware which combine tcl editor and compiler (or interpenter)?
The Tcl source code is thoroughly openly available. Download and build to get an “interpreter” (actually, it bytecode compiles everything internally). You can get a pre-built distribution of Tcl with a majority of Linux distributions (I forget whether it is installed by default) or by finding a “tclkit” (Google for it) which is a single-file run-immediately distribution of Tcl and Tk (for GUI). There's also the ActiveTcl distribution by ActiveState for major platforms; it's slightly commercial (but zero cost), but very good (I use it and many other Tcl users do too).
I use Emacs to edit Tcl, but anything that can edit plain text files will do fine. I know that both vim and Eclipse have Tcl support.
The only full Tcl compilers are commercial. The only one of those that I would really recommend is part of the TDK, a product of ActiveState. (I know several of the guys there, but have no commercial affiliation at all.) If you don't need code obfuscation — e.g., because you're writing open-source software — then don't bother with compiling; the built-in compiler inside a standard Tcl build is just fine. (It compiles stuff to bytecode faster than you can load bytecode out of a file. Which is odd, but nice.) AS also do a product called Komodo which is supposed to be a very good Tcl IDE (plus a few other languages) but I've yet to try it myself.
- After opening of the serial connection (COM1) using fconfigure , how can I send via the connection, a string of several words? I need to connect to some HW and I want to be able running a scripts on its CLI.
Serial ports are opened with open
(duh!), configured with fconfigure
(or chan configure
if you've got a new enough Tcl; it's the same command really) and written to with puts
. I warn that I've got no idea what the right settings for your serial devices are:
set serPort [open "COM1" r+]
fconfigure $serPort -mode 9600,n,8,1
puts $serPort "Yo there, serial device!"
You'd then read a line from the device like this:
set line [gets $serPort]
And close down the port once you're done like this:
close $serPort
There's probably more things you need to know. Just ask further questions on this site and someone will try to help.
回答2:
Although I haven't tried the full IDE, I really like the free version of Active State's Komodo Edit, and use it in combination tclshkit to make executables on Windows.
I had some luck using Expect with serial ports to program Cisco switches. The pattern matching abilities of Expect made it pretty simple... the following example works on Windows, I haven't tried the same thing on a *nix box yet:
package require Expect
set com "COM1"
if { [ catch { set serial [ open "$com:" "RDWR" ] } ] } then {
puts "Error! Cannot open $com!"
exit 1
}
fconfigure $serial -mode 9600,n,8,1
spawn -leaveopen $serial
send "somecommand\r"
expect "someprompt"
close $serial
来源:https://stackoverflow.com/questions/9022535/free-compiler-or-interpreter-for-tcl-and-tcl-serial-port-com1-commands