Go to front page
Products Support Purchase Search Contact
prod prod
Products
This page as a PDF - How to use NX1500 remote I/O over the Internet using Linux and Perl

How to use NX1500 series remote I/O over the Internet using Linux and Perl

Screen shots.

Screenshot 1: all off
Screenshot 2: mixed IO
Screenshot 3: mixed IO

Requires.
Linux distribution running Apache web server and Perl5 and above.
Example produced on Redhat Linux 7.3 running Apache web server version 1.3.23 and Perl version 5.006001 on standard 1.2GHz Celeron PC hardware.

Introduction.
Demonstration: Access remote input / output ports on Nexion modems using a web browser front end and a Linux / Perl back end.

Accessing hardware on a Unix / Linux computer is relatively easy due to the use of the /proc file system. Each hardware device is ‘virtualised’ as a unique file name and included in the file system. Most often, to access a hardware device is as simple as opening it’s ‘virtual file’ and read / writing to it the same as you would any normal file.

Comm. Port.
Permissions to the chosen comm. port must be relaxed so that the web server can access it. Comm. ports are in the /dev/ directory and to set Com2 with read / write access for the ‘Others’ group; enter the following at a command line.

chmod 646 /dev/ttyS1

Any GETTY process running against the comm. port must be stopped since control must be available to the web server / Perl script.

GETTY processes are normally run from /etc/inittab and take the form similar to:

xxx:2345:respawn:/sbin/mgetty ttySx

There must be no such entry for the comm. port you wish to control.

Perl script.
Save the script in /var/www/cgi-bin and make it executable by typing the following at a command line:

chmod 755 /var/www/cgi-bin/control.pl

Adjust the port number and the modem address in the first few lines as described in the code.

When the script is run without parameters (new session) it will read the current I/O settings of the modem via the configured comm. port and display the results on a web page. This same page can then be used to switch output ports on the modem. Current input settings are automatically returned also.

#!/usr/bin/perl -w
# ----------------------------------------------------------
# com1 = /dev/ttyS0, com2 = ttyS1
$port = "/dev/ttyS1";

$modemAddress = "1,2,4";

# these are the AT commands for remote IO
$readInputs = "at%iir1";
$readOutputs = "at%ior1";
$writeOutputs = "at%iow";
$ctrlValue=0;
$modemAddress = "," . $modemAddress . "\r";
# ----------------------------------------------------------
&PrintHeader;
&ReadParse;
&ProcessInput;
&InitPort;
# if no data then this is first run / page load - read only 
if ($in) {
# write outputs
$atString = $writeOutputs . $ctrlValue . $modemAddress;
&SendModem;
}
# read outputs
$atString = $readOutputs . $modemAddress;
&SendModem;
&GetValues;
&DecodeValue;
# read inputs
$atString = $readInputs . $modemAddress;
&SendModem;
&GetValues;
&DecodeValue;

Snip ……

Download.
Download the tgz of the example perl script and all images here.
   
     
go back