The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Plasmatronics - Plasmatronics PL regulator controller

SYNOPSIS

        use Device::Regulator::Plasmatronic;
        my $r = Device::Regulator::Plasmatronic;
        print "Current state of charge = " . $r->pl_dsoc . "\n";

DESCRIPTION

This is an interface library via the serial port to a Plasmatronics Regulator. (http://www.plasmatronics.com.au/)

MAJOR LIMITATIONS

Serial Port

I have to replace the serial port driver - currently I use the unix only version, but I have written

Hard Coded Multiplier

The multiplier used for voltages etc is hard coded (currently 4 = 48 Volt system). This can be read from the system, so I will have to do that as part of the initialisation.

Combined Values

Load and other things combine values from multiple locations to allow for larger numbers. I know that I have got this wrong in a number of places. Work to be done to test these for large numbers (eg: > 25 Amps etc).

FUTURE

Fix Limitations

As above, look at each limitation and try and fix it up.

CGI Scripts

Write a number of example CGI scripts

Graphing

Include a graph of the history, or even daily history of the system.

Learning Kit

Put together the whole kit of files above so that it can be used in learning environments etc to demonstrate logging, power use etc.

My house has most lights and equipment controlled by the computer, which means combined with current load we get a really good idea how much power is used when things are switched on. This also means we can work out how much power is used by which piece of equipment (over time), and monitor the standard load (eg: what is on all the time like the Fridge).

TOOLS

I have documented here the tools that come with this, although they are not part of this library, it is a convenient place to put them.

plbackup / plrestore

This allows you to backup all the data currently in the regulator. This is very handy if you want to work on the regulator which involves disconnecting the power. You then loose all the data for the current day. This allows you to keep that information, not even loosing any data (except for the period it is off).

plhistory

Display the history.

plload

A simple example of some load variables displayed. A good one to look at on how you would write your own code.

pllogger

This writes all daily entries to a log file, good for long term logging accross long periods. You could adapt this to log any data in the system at any interval.

plloopback

Just test the loopback. You can run this to make sure the unit and code is working. Handy to put in a test script, you could for example trigger an alarm if the systems goes down.

plread / plwrite

Read and write to any variable in the system. Your raw access tool.

pltest

Another test code - not really necessary but I use it mostly to generally test my changes.

pltime

Read and write the time on the system. You can setup a job to set the time correctly from your server on regular basis, or call it after a plrestore.

EXAMPLE CODE

Initialisation

        my $pl = Plasmatronics->new();
        if ($pl->pl_loopback) {
                print "Cool\n";
        } else {
                print "Not so cool\n";
        }

Read

        # Init above
        print "Current load = " . $pl->pl_load . "\n";

Write

        # Change the hour
        print "New hour = " . $pl->pl_hour(15) . "\n";

Full Example Used for remote display

        # This example could be used for an app, cgi or remote display

        use Plasmatronics;

        my $pl = Plasmatronics->new() || die "Can't connect to PL";

        my $soc = $pl->pl_dsoc;
        print $soc . "%\n";
        my $load = $pl->pl_load;
        my $charge = $pl->pl_charge;
        print "OUT $load, IN $charge\n";

DATA FILE

The data file (plasmatronics.dat) contains all the clever information.

So why a data file and not hard coded. Well theoretically I want to be able to write alternate versions of this software in other languages (eg: Java, Python, or even a windows DLL/OLE). By keeping any of the non language specific intelligence in the data file, this can be shared, it is also a much neater way of doing development.

Parameters

        - Short Name    
        - Number        
        - Full description      
        - Divide by (number)    
        - Multiply by (number or BM)    
        - Unit  
        - ShiftLeft by (other name or NA)       
        - Write flag    
        - Non NV Backup/Restore (should it be backed up)

The combination of these allows us to do most of the intelligent calculations in the data file.

Mapping to methods

Each of the short names maps to the equivellent method starting with 'pl_'. The nice part about this is it means you can write code with that name that is used in place of the generic code. This is kind of useful when you want to do more complicated calculations which can not be covered in the data file.

METHODS

Here are the methods...

data

Read or write to a processor or nvram location.

Returned values are always adjusted to make your life easier, but that is not so easy for writting, so that has not yet been implemented.