How do I use Perl to communicate with my Remote IO Module?


Download (1.7 kB)

This article describes how to communicate with a Brainboxes Ethernet IO Module (or Remote IO module) using the Perl programming language.


  • A computer with the Perl Runtime
  • The Brainboxes Perl Module (download from this page)

Sample Code

Create a subdirectory in your Perl package library directory (may be something like C:perlsitelib) called ‘Brainboxes’, and then save the file ‘’ there.  You can then run the script ‘’ which demonstrates the usage of that class.

If you are unable to add Brainboxes/ to your existing Perl installation, for example because you don’t have the necessary permission, you can set up your own library directory anywhere you like.  Create a directory for the library, add a ‘Brainboxes’ subdirectory to put ‘’ in, and add a ‘use lib’ ( command at the start of the script to add your library to the search path.

The script ‘’ demonstrates the usage of the Brainboxes::AsciiIo class.  Before you run it, edit the IP address on line 6 to be the address of a Brainboxes Ethernet IO Module on your network.  Also edit the TCP port number if you have changed it from the default of 9500.  The output of the program should look something like this:

Sending command '$01M'
  Response was '!01ED-588'
Sending command '~**'
  No response expected
Sending command '@01'
  Response was '>00FF'
Sending command '@02'
  No response received!
Sending command '$016'
  Response was '!00FF00'

The code below is available to download as a zip from the top of the page.

use Brainboxes::AsciiIo;

use strict;
use warnings;

my $remote = Brainboxes::AsciiIo->new({ipaddr => '', port => 9500, timeout => 5});

for my $command ('$01M', '~**', '@01', '@02', '$016') {
    # send the above commands in sequence
    # the '@02' command will probably get no response, unless you have a slave device connected to the gateway port

    print "Sending command '$command'n"; binmode STDOUT;

    if (substr($command, 1, 2) eq '**') {
        # this command is not one which we expect to get a response to
        print "  No response expectedn";
        binmode STDOUT;
    else {
        # this command is one which we SHOULD get a response to
        my $rxdata = $remote->command_response($command);

        if (defined $rxdata) {
            print "  Response was '$rxdata'n";
        else {
            print "  No response received!n";
        binmode STDOUT;