View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Vladimir Lettiev > Net-IEC104-0.03 > Net::IEC104



Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  


Net::IEC104 - Perl implementation of IEC 60870-5-104 standard (server and client)


    use Net::IEC104;
    use Time::HiRes;

    sub send_all_data {
        my $self = shift;
        my %DATA = (TI=>{},TS=>{},TII=>{});

        $DATA{TI}->{1}  = [12.34,gettimeofday]; # Tele Information (real value of physical measurement)
        $DATA{TS}->{2}  = [0,gettimeofday];     # Tele Signalization (boolean value)
        $DATA{TII}->{3} = [34567,gettimeofday]; # Tele Information Integral (32-bit counter)

        return %DATA;

    my $srvr_sock = Net::IEC104->new(



This module implement IEC 60870-5-104 standard (also known as IEC 870-5-104). IEC 870-5-104 is a network access for IEC 60870-5-101 using standard transport profiles (TCP/IP), its application layer is based on IEC 60870-5-101. IEC 60870-5-104 enables communication between control station and substation via a standard TCP/IP network. The TCP protocol is used for connection-oriented secure data transmission.

Current implementation supports only ASDU NN 30,35,36,37,100,103. Its enough for now.


Net::IEC104->new(...) accept following variables:

* type - type of station, must be one of "slave" (controlled station) or "master" (control station). Default "slave"

* ip - ip address to listen on (for slave) or connect to (for master). Default ""

* port - port of connection. Default 2404

* ca - common address. Default 1

* write_callback - (slave only) ref to callback function, that returns a list with two vars: reference to class and hash with data. Hash format is as following: %HASH = ("TI" => { address=>[value,timestamp,microseconds], ... },"TS" => { address=>[value,timestamp,microseconds], ... },"TII" => { address=>[value,timestamp,microseconds], ... }); This function called when slave receive common interogation request from master (ASDU=100).

* read_callback - (master only) ref to callback function, that receive a list (same format as for write_callback)

* w - W constant (default 8)

* k - K constant (default 12)

* ts_func_num - (slave only) ASDU number used for TS data, default 30. If 0 - TS never send

* ti_func_num - (slave only) ASDU number used for TI data, default 36. If 0 - TI never send

* tii_func_num - (slave only) ASDU number used for TII data, default 37. If 0 - TII never send

* t0 - t0 timeout constant (30 sec)

* t1 - t1 timeout constant (15 sec)

* t2 - t2 timeout constant (10 sec)

* t3 - t3 timeout constant (20 sec)

* persist - (master only) 0 - do not reconnect after disconection, 1 - reconnect after disconnection


connect() - master only method. Connect to slave. After succeful connection, its activate transmission (STARTDT) and send common interogation request to slave (ASDU=100).

listen() - slave only method. Start listen for masters connections.

send(CA,%HASH) - slave only method. Send spontaneous data to all masters connected to server with common address CA. %HASH format same as for write_callback function.

main_loop() - start event cycle. ( stub that call Lib::Event::even_mainloop() )


None by default.



    use Net::IEC104;

    # Print to stdout all received data;
    sub take_data_cb {
        my $self = shift;
        my %hash = @_;
        foreach my $key (keys %hash) {
            print $key,"\n";
            foreach my $addr (keys %{$hash{$key}}) {
                print "\t";
                print "address:\t",      $addr, "\n\t";
                print "value:\t",        $hash{$key}->{$addr}->[0], "\n\t";
                print "seconds:\t",      $hash{$key}->{$addr}->[1], "\n";
                print "microseconds:\t", $hash{$key}->{$addr}->[2], "\n";

    my $master = Net::IEC104->new(
                type => "master",
                ip   =>,
                port => 2404,
                ca   => 1,
                w    => 8,
                k    => 12,
                persist => 1,
                read_callback => \&take_data_cb,


Idea and design of implementation of library based on OpenMRTS project ( written by Sitkarev Grigoriy.


Vladimir Lettiev, <>


Copyright (C) 2008-2011 by Vladimir Lettiev

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: