Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
XP is just a number
 
PerlMonks  

Re: Perl Code To Control Industrial Applications?

by zentara (Archbishop)
on Feb 11, 2014 at 11:42 UTC ( #1074396=note: print w/ replies, xml ) Need Help??


in reply to Perl Code To Control Industrial Applications?

If I was to setup something like this from scratch, meaning not using other people's kits or whatever; and if you really want to keep computer control in a central location, like a laptop; I would look to get a USB breadboard

Then once you have the idea of how to read/write to it, you can get going. It probably does the same thing the old parallel printer port interfaces did, just write values in C, to a specific memory address. I'm sure Perl can do that.

Then, make up your control interface using something like Tk, SDL, Wx, Gtk3, or whatever Perl GUI you like.

Here for example is a simple dial guage which you can either use to set temperature, or read it's current value.

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; my $gray50_width = 2; my $gray50_height = 2; my $gray50_bits = pack "CC", 0x02, 0x01; $mw->DefineBitmap('mask' => 2,2, $gray50_bits); $mw->fontCreate('medium', -family=>'courier', -weight=>'bold', -size=>int(-14*14/10)); my $c = $mw->Canvas( -width => 200, -height => 200, -bd => 2, -relief => 'sunken', -background => 'black', )->pack; $c->createLine(100,100,10,100, -tags => ['needle'], -arrow => 'last', -width => 5, -fill => 'hotpink', ); my $gauge = $c->createOval( 10,10, 190,190, -fill=> 'lightblue', -outline => 'skyblue', -width => 5, -tags => ['gauge'], -stipple => 'mask', ); my $hub = $c->createOval( 90,90, 110,110, -fill => 'lightgreen', -outline => 'seagreen', -width => 2, -tags => ['hub'], ); $mw->bind('<B1-Motion>' => sub{ my $ev = $c->XEvent; &update_meter($ev->x,$ev->y); }); my $text = $c->createText( 100,50, -text => 180, -font => 'medium', -fill => 'yellow', -anchor => 's', -tags => ['text'] ); $c->raise('needle','text'); $c->raise('hub','needle'); MainLoop; sub update_meter { my($x,$y) = @_; # transform coords center to 100,100 $x = $x - 100; $y = 100 - $y; my $cos = $x/($x**2 + $y**2)**(.5); my $sin = $y/($x**2 + $y**2)**(.5); my $x1 = 100.0 + 90.0 * $cos; my $y1 = 100.0 - 90.0 * $sin; $c->coords('needle', 100,100, $x1, $y1); #see perldoc -f cos my $angle = sprintf('%.2d', 180 / 3.1416 * atan2( sqrt(1 - $cos * $ +cos), $cos )); if( $y < 0){ $angle = 359 - $angle } $c->itemconfigure($text,-text => $angle); }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh


Comment on Re: Perl Code To Control Industrial Applications?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1074396]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-04-17 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (458 votes), past polls