#!perl # # Under the Apache Software License v2 / dirkx(at)webwaving(dot)org # # Quick and dirty hack to create the start of a UI for any random # connected Ethercat units. Only does simple I/O and analog for now. # As that was all I needed. $t = localtime(time); open(STDOUT,">panel.xml"); open(WIRING,">wiring.hal"); open(XML,">ethercat-conf.xml"); print "\n"; print WIRING "# generted $0 / $t\n"; open(STDIN," lcec_configgen --typedb=false|"); while() { # Remove lines that confuse lcec_config its parser. next if m/dir=""/; next if m/BLANK/; print XML; chomp; $name = $1 if m/name="(\w+)"/; $t{$name}= $1 if m/ EOM for $card (sort { $A = $1 if $a =~ m/(\d+)/; $B = $1 if $b =~ m/(\d+)/; return $A <=> $B; } keys %t) { print <<"EOM"; RIDGE6 EOM $N = @{$h{$card}}; $i = 0; $j = 0; for $pin (@{$h{$card}}) { $i++; # ch-4-value 5-output 7-input if ($pin !~ m/(\d+)-(\w+)/) { warn "Skipping '$pin'\n"; next; }; $n = $1; $dir = $2; next if $dir eq 'status'; print " \n" if $j % 8 == 0; print " \n"; print " " if not $j & 8; print "\"$card.$pin\"" if ($dir eq 'input'); print "\"$card.$pin\"" if ($dir eq 'output'); print "\"$card.$pin\"\"+4.1f\"" if ($dir eq 'value'); print WIRING "net $card-$pin lcec.0.$card.$pin => hmi.$card.$pin\n" if ($dir eq 'input'); print WIRING "net $card-$pin lcec.0.$card.$pin <= hmi.$card.$pin\n" if ($dir eq 'output'); print "" if $j & 8; print "\n \n"; print " \n" if $j % 8 == 7 || $i == $N; $j++; }; print " \n"; print " \n"; print " \n"; }; print " "; close(XML); close(WIRING); close(STDOUT); open(HAL,">panel.hal"); print HAL <<"EOM"; # Generated $0 / $t loadusr lcec_conf ethercat-conf.xml loadrt lcec loadusr -Wn hmi pyvcp -c hmi panel.xml loadrt threads name1=ethercat-thread period1=1000000 addf lcec.read-all ethercat-thread addf lcec.write-all ethercat-thread source wiring.hal show pin EOM close(HAL); warn("# Now do: halrun -I panel.hal\n");