Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Tcl Environment Path

tcl

#!/usr/bin/tclsh

puts $env(PATH)

Tcl Version

tcl

#!/usr/bin/tclsh

puts $tcl_version

Execute Tcl Online

tcl

#Filename: sample15.tcl

#**************AODV ROUTING PROTOCOL***************************#
# Simulator Instance Creation
set ns [new Simulator]

#Fixing the co-ordinate of simutaion area
set val(x) 500
set val(y) 500
# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 10 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 500 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# general operational descriptor- storing the hop details in the network
create-god $val(nn)

# configure the nodes
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON

# Node Creation

for {set i 0} {$i < 10} {incr i} {

set node_($i) [$ns node]
$node_($i) color black

}

for {set i 0} {$i < 10} {incr i} {

$node_($i) set X_ [expr rand()*$val(x)]
$node_($i) set Y_ [expr rand()*$val(y)]
$node_($i) set Z_ 0

}
for {set i 1} {$i < 10} {incr i} {
# Defining a transport agent for sending
set udp [new Agent/UDP]

# Attaching transport agent to sender node
$ns attach-agent $node_($i) $udp

# Defining a transport agent for receiving
set null [new Agent/Null]

# Attaching transport agent to receiver node
$ns attach-agent $node_(0) $null

#Connecting sending and receiving transport agents
$ns connect $udp $null

#Defining Application instance
set cbr [new Application/Traffic/CBR]

# Attaching transport agent to application agent
$cbr attach-agent $udp

#Packet size in bytes and interval in seconds definition
$cbr set packetSize_ 512
$cbr set interval_ 0.1

# data packet generation starting time
$ns at 1.0 "$cbr start"

# data packet generation ending time
#$ns at 6.0 "$cbr stop"

}

my_first

tcl

set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
set tracefile [open out.trace w]
$ns trace-all $tracefile
set file2 [open out.nam w]
$ns namtrace-all $file2
set winfile [open WinFile w]
proc finish {} {
    global ns file2
    global tracefile
    $ns flush-trace
    close $tracefile
    close $file2
    exec nam out.nam &
    exit 0
}
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 2Mb 10ms DropTail
$ns duplex-link-op $n0 $n1 orient right-down
$ns at 125.0 "finish"
$ns run

test

tcl

puts "Hello World!"

Execute Tcl Online

tcl

set A "my ip address is 192.168.1.1/32 and my default gateway is 192.168.1.0"
regexp {\S+\s\S+\s\S+\s\S+\s(\d+.\d+.\d+.\d)?\/(\d+)\s\S+\s\S+\s\S+\s\S+\s\S+\s(\d+.\d+.\d+.\d)$} $A a b c d
#puts "full: $a"
puts "ip address: $b"
puts "prefix: $c"
puts "default gateway: $d"

Execute Tcl Online

tcl

#
# Tcl script to generate CNC g-code from Eagle Cam files
#
#

rename puts original_puts

proc puts {args} {
    if {[llength $args] == 1} {
            return "[lindex $args 0]"
        } else {
                eval original_puts $args
        }
}



# 
set ScriptName "cam2tap.tcl"
set outfl [open $ScriptName w]


puts $outfl { 

   puts stdout "#Setup object propertys"
   puts {set ProjectName "Test3"}
   puts {set ProjectExt "flatcam"}
   
   puts {set gbrExt "gbr"}
   puts {set excExt "exc"}
   puts {set geoExt "geo"}
   puts {set cncExt "cnc"}
   puts {set tapExt "tap"}
   
   puts {set etachExt "etch"}
   puts {set millExt "mill"}
   puts {set textExt "text"}
   puts {set drillExt "drill"}
 
   
   puts "#Setup CAM file name -  input data fom Eagle"
   puts {set TopTextFileName     [format %s.top.text.%s $ProjectName $gbrObjExt]}
   puts {set BottomTextFileName  [format %s.bot.text%s $ProjectName $gbrObjExt]}
   puts {}
   
   puts "#FlatCam object"
   puts {set gbrObjName [format %s_%s $ProjectName $gbrObjExt]}
   puts {set excObjName [format %s_%s $ProjectName $excObjExt]}
   puts {set geoObjName [format %s_%s $ProjectName $geoObjExt]}
   puts {set cncObjName [format %s_%s $ProjectName $cncObjExt]}
   puts {}
   
   puts "#Setup G-code file name - output data to grblControl"
   puts {set TopEtachGcodeFileName     [format %s.top.%s.%s $ProjectName $etachExt $TapExt]}
   puts {set BottomEtachGcodeFileName  [format %s.bot.etch.%s $ProjectName $TapExt]}
   puts {set geoObjName [format %s_%s $ProjectName $geoObjExt]}
   puts {set cncObjName [format %s_%s $ProjectName $cncObjExt]}
   puts {}
   
    puts {set_sys units MM}
    puts {set_sys_excellion_zeros T}
    puts "# Starts a new project. Clears objects from memory."
    puts {new}
    puts ""
    
    
    
    puts "#"
    puts "# Isolation Routing proc"
    puts "#"
    puts "proc isolate_path layer  {"
    puts " # Opens a Gerber file."
    puts { set in [format %s.%s.etch.%s $ProjectName $layer  $gbrExt]}
    puts { set out [format %s_%s_etch_%s $ProjectName $layer $gbrExt]}
    puts { open_gerber $in  –outname $out }
    puts " # Creates isolation routing geometry for the given Gerber."
    puts { set in  $out }
    puts { set out [format %s_%s_etch_%s $ProjectName $layer $geoExt]}
    puts { isolate $in -dia 0.2 -passes 3 -overlap 0.15 -combine 1 -outname $out}
    puts " # Generates a CNC Job from a Geometry Object."
    puts { set in  $out }
    puts { set out [format %s_%s_etch_%s $ProjectName $layer $cncExt]}
    puts { cncjob $geoObjName -z_cut 0.1  -z_move 15.0 -feedrate 180.0 \
                            -tooldia 0.2 -spindlespeed 1000 -multidepth 0 -depthperpass 0.0 \
                            -outname  $ObjName}
    puts " # Saves G-code of a CNC Job object to file."
    puts { write_gcode $ObjName [format %s.%s.etch.%s $ProjectName $layer  $tapExt]}
    puts "}"


    puts "#"
    puts "# Drill holes proc"
    puts "#"
    puts "proc drill_holes {"
    puts { set in  [format %s.drill.%s $ProjectName $excExt]}
    puts { set out [format %s.drill.%s $ProjectName $excExt]}
    puts {open_excellon [format %s.drill.%s $ProjectName $excExt] }
    puts "# Generates a CNC Job from a Geometry Object."
    puts { set in  $out }
    puts { set out [format %s_%s_etch_%s $ProjectName $layer $cncExt] }
    puts { cncjob $in -z_cut 0.1  -z_move 15.0 -feedrate 180.0 \
                            -tooldia 0.2 -spindlespeed 1000 -multidepth 0 -depthperpass 0.0 \
                            -outname  $out}
    puts "# Saves G-code of a CNC Job object t o file."
    puts { set in  $out }
    puts { set out [format %s_%s_%s $ProjectName $millExt $tapExt] }
    puts { write_gcode $in $ou }
    puts "}"
    
    puts "#"
    puts "# Drill spot holes proc"
    puts "#"
    puts "proc drill_spot {"
    puts { set in  [format %s.drill.%s $ProjectName $excExt]}
    puts { set out [format %s.drill.%s $ProjectName $excExt]}
    puts {open_excellon [format %s.drill.%s $ProjectName $excExt] }
    puts "# Generates a CNC Job from a Geometry Object."
    puts { set in  $out }
    puts { set out [format %s_%s_etch_%s $ProjectName $layer $cncExt] }
    puts { cncjob $in -z_cut 0.1  -z_move 15.0 -feedrate 180.0 \
                            -tooldia 0.2 -spindlespeed 1000 -multidepth 0 -depthperpass 0.0 \
                            -outname  $out}
    puts "# Saves G-code of a CNC Job object t o file."
    puts { set in  $out }
    puts { set out [format %s_%s_%s $ProjectName $millExt $tapExt] }
    puts { write_gcode $in $ou }
    puts "}"
    
    puts "#"
    puts "# Board cutouts proc"
    puts "#"
    puts "proc cut_outline {"
    puts " # Opens a Gerber file."
    puts { set in  [format %s.%s.%s $ProjectName $millExt $gbrExt] }
    puts { set out [format %s_%s_%s $ProjectName $millExt $gbrExt] }
    puts { open_gerber $in -follow 1 –outname $out }
    puts " # Create geometry from Gerber Object"
    puts { set in  $out }
    puts { set out [format %s_%s_%s $ProjectName $millExt $geoExt] }
    puts { follow $in -outname $out }
    puts " # Generates a CNC Job from a Geometry Object." 
    puts { set in  $out }
    puts { set out [format %s_%s_%s $ProjectName $millExt $cncExt] }
    puts { cncjob $in -z_cut 1.8 -z_move 15.0 -feedrate 60.0       \
                    -tooldia 1.5 -spindlespeed 1000 -multidepth 0 \
                    -depthperpass 0.0 -outname  $out }
    puts " # Saves G-code of a CNC Job object to file."
    puts { set in  $out }
    puts { set out [format %s_%s_%s $ProjectName $millExt $tapExt] }
    puts { write_gcode $in $out }
    puts "}"
    
    puts "#"
    puts "# Engrave text proc"
    puts "#"
    puts "proc engrave_text layer {"
    puts " # Opens a Gerber file."
    puts { set in  [format %s.%s.text.%s $ProjectName $layer $textExt] }
    puts { set out [format %s_%s_text_%s $ProjectName $layer $textExt] }
    puts { open_gerber $in -follow 1 –outname $out }
    puts " # Create geometry from Gerber Object"
    puts { set in  $out }
    puts { set out [format %s_%s_text_%s $ProjectName $layer $geoExt] }
    puts { follow $in -outname $out }
    puts " # Generates a CNC Job from a Geometry Object." 
    puts { set in  $out }
    puts { set out [format %s_%s_text_%s $ProjectName $layer $cncExt] }
    puts { cncjob $in -z_cut 0.2 -z_move 15.0 -feedrate 60.0       \
                    -tooldia 1.5 -spindlespeed 1000 -multidepth 0 \
                    -depthperpass 0.0 -outname  $out }
    puts " # Saves G-code of a CNC Job object to file."
    puts { set in  $out }
    puts { set out [format %s_%s_text_%s $ProjectName $layer $tapExt] }
    puts { write_gcode $in $out }
    puts "}"
    
    
    puts "#"
    puts "# ......... proc"
    puts "#"
    puts "proc etach layer {"
    puts { isolate_path $layer }
    puts { engrave_text $layer }
    puts { if $layer == "bot" : }
    puts {   drill_spot }
    puts "}"
    
    
    
    
    
    
    
    
    puts ""

    puts { set step "Create alignment drill" }
    puts { cut_outline }
    puts { drill_aligment }   
    
    puts { set step "Top side isolation routing and text engrave" }
    puts { isolate_path "top" }
    puts { engrave_text "top" }


    puts { set step "Turn the board around" }
    
    puts { set step "Bottom side isolation routing, text engrave and spot drill" }
    puts { isolate_path "bot" }
    puts { engrave_text "bot" }
    puts { drill_spot }
    
    puts { set step "Create alignment drill" }

    puts { set step "Create drill holes" }
     
    puts { set step "Cuting the board" }
     
    puts "# Saves the FlatCAM project to file.."
    puts { save_project [format %s.%s $ProjectNam $ProjectExt] }
    puts ""
   
    exit 0
   
}

flush $outfl
close $outfl


#
# Define run comand 
#

proc run args {
   foreach arg $args {
      eval { puts stdout [exec [info nameofexecutable] $arg ] }
   }
}


run cam2tap.tcl
   
   exit 0
   
   
}

flush $outfl
close $outfl


#
# Define run comand 
#

proc run args {
   foreach arg $args {
      eval { puts stdout [exec [info nameofexecutable] $arg ] }
   }
}


run cam2tap.tcl

Execute Tcl Online

tcl

puts "Hello World!"
puts "Hello World!"
puts "Hello World!"
if 0 {
    this is a multiline \
    comment. no content of this will\
    be printed
}
puts "Hello\nconsole"
set myvariable {arun mohit tushar ram munir}
puts [lindex $myvariable 3]
append myvariable " " "manoj"
lappend myvariable "mrityunjay"
puts [lindex $myvariable 6]
puts [lindex $myvariable 5]
append myvariable " " "ram"
lappend myvariable "shyam"
puts [llength $myvariable]
set value1 [lindex $myvariable 7]
puts $value1
set value2 [lindex $myvariable 8]
puts $value2
if {$value1 == $value2} {
    puts "matched"
} else {
    puts "unmatched"
}
set mymarks(english) 90
set mymarks(maths) 98
set mymarks(physics) 90
set mymarks(chemistry) 78
set mymarks(biology) 70
puts [array names mymarks]
puts $mymarks(maths)
set language(0) TCL
set language(1) C
set language(2) perl
set language(3) verilog
set language(4) python
puts $language(4)
puts [array size language]
for {set index 0} {$index < [array size language]} {incr index} {
    puts "language($index): $language($index)"
}
foreach indexs [array names mymarks] {
    puts "mymarks($indexs):$mymarks($indexs)"
}
set tobby "helarious"
puts [string length $tobby]

proc helloworld {a {b 12}} {
    puts "Hello World"
    puts [expr $a + $b]
}

helloworld 7 8
helloworld 8

regexp -nocase {([A-Z]*.([A-Z]*))} "Tcl Tutorial" a b c  
puts "Full Match: $a"
puts "Sub Match1: $b"
puts "Sub Match2: $c"
set tcl_precision 12
set num3 [expr 59.67]
set value4 [split $num3 .]
lassign $value4 \
        real decimal
puts $real
set finalvalue $real
puts $finalvalue
puts [expr {$finalvalue + 1}]

puts "ASHOK REQUIREMENT CHECK"
regexp {([0-9]*\.([0-9]*))} "59.64" a b c  
puts "Full Match: $a"
set myvalue [ split $a .]

lassign $myvalue \
        realvalue decimalvalue
puts $realvalue
set  vrealvalue $realvalue
if {$real == $realvalue} {
    puts "matched number"
} else {
    puts " unmatched numbers"
}
puts [expr {$vrealvalue + 1}]
set data {cricket football drawing movies music food}
set hobbies [join $data ", "]
puts "i like $hobbies"

Execute Tcl Online

tcl

puts "Hello World!"
puts "Hello World!"
if 0 {
    this is a multiline \
    comment. no content of this will\
    be printed
}
puts "Hello\nconsole"
set myvariable {arun mohit tushar ram munir}
puts "\n"
puts [lindex $myvariable 3]
append myvariable " " "manoj"
lappend myvariable "mrityunjay"
puts "\n"
puts [lindex $myvariable 6]
puts "\n"
puts [lindex $myvariable 5]
puts "\n"
puts [llength $myvariable]
puts "\n"
set mymarks(english) 90
set mymarks(maths) 98
set mymarks(physics) 90
set mymarks(chemistry) 78
set mymarks(biology) 70
puts [array names mymarks]
puts "\n"
puts "\n"
puts "\n"

puts $mymarks(maths)
puts "\n"
set language(0) TCL
set language(1) C
set language(2) perl
set language(3) verilog
set language(4) python
puts $language(4)
puts "\n"
puts [array size language]
puts "\n"
for {set index 0} {$index < [array size language]} {incr index} {
    puts "language($index): $language($index)"
}
foreach indexs [array names mymarks] {
    puts "mymarks($indexs):$mymarks($indexs)"
}
set tobby "helarious"
puts [string length $tobby]
#set datain [gets $argv1]
puts [ lindex $argv 0]
if {[string match "yes" $argv]} {
    puts "its yes"
} else {
    puts "its no"
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.