The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Device::Opto22 - Perl Object to communicate with Opto22 Brains via Memory-mapped protocol


        use Device::Opto22;
        my $brain_ip = '';
        my $sock  = new Device::Opto22( PeerAddr => "$brain_ip",PeerPort => '2001' );
        my $rtn = $sock->send_PUC();
        # Read Opto22 scratch pad tables
        my $int_table_sz = 15;     # number of entries to read in integer scratch pad table
        my $flt_table_sz = 18;     # number of entries to read in float scratch pad table
        my @int_lst = $sock->get_scratchpadint($int_table_sz);
        my @flt_lst = $sock->get_scratchpadfloat($flt_table_sz);


This Module communicates with an Opto22 Brain/Controller via OptoMMP a memory-mapped protocol based on the IEEE 1394 standard. This module can be used to create custom software applications for remote monitoring, industrial control, and data acquisition using Opto22 modular components.

There is an underlying module that is used.


Methods include:

  • send_PUC()

    Send Power Up Control

            my $rtn = $sock->send_PUC();

    Returns 1 on success and nothing on failure

  • get_scratchpadint()

  • get_scratchpadfloat()

    Get Integer/Float Scratchpads

            my @lst = $sock->get_scractchpading($number_of_items_get);

    Returns a list of items requested or nothing on failure

  • get_eu_lst()

    Get Analog Bank Data in Engineering Units

            my @eu_lst  = $sock->get_eu_lst() 

    Returns list of measured engineering unit values in memory map and nothing on failure

  • get_digital_lst()

    Get Digital Bank Data

            my @dig_lst = $sock->get_digital_lst()

    Returns all list of all 64 digital points. Nothing of failure.

  • wr_digital_pnt

    Write digital point


    Inputs are channel to effect and a true value for $turn_on to activate channel or nothing to turn channel off.

  • serial_chat(@data)

  • serial_send($data)

  • serial_rcv()

        Send and/or Receive data from serial module 
            $sock->serial_send("*0100DB\r\n");     # ask for data in the pressure sensor buffer
            my $engr_value = $sock->serial_rcv();  # rcv buffer data

    Communicate to the serial device. Note you will have to send \r\n characters if needed.

  • error_msg

    Get error message on failure

        unless ( $rtn ) { die $sock->error_msg; } 

Note: The Opto22 Brains are in Big-endian format. The module translates this into common Little-endian format. If you are trying this module out on a Big-endian machine you will need to edit the source code as required.


For more detailed information on Opto22 components and OptoMMP see...


Written and maintained by: Steve Troxel and Duane Nightingale (email troxel "at"


Copyright (C) 2010

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.