Sarian Basic MODBUS Support Library
===================================

This folder contains a set of scripts that implement
an API to provide MODBUS Application Protocol support for
applications written in Sarian ScriptBasic.

This version implements the command set supported by the
Advantys OTB Ethernet Remote I/O module.

The files are described below:

MBIO.SB - contains the MODBUS Application Protocol Implementation
-------

    This Library currently supports the following commands:

        0x03: Read Holding Registers
        0x06: Write Single Register
        0x10: Write Multiple Registers
        0x11: Report Slave ID
        0x16: Mask Write Register
        0x17: Read/Write Multiple Registers
        0x2B/0x0E: Read Device Identification


MBTCP.SB - contains the MODBUS TCP/IP messaging implementation
--------

    This is used by the Application Protocol to carry out transactions over TCP/IP.

MBTEST.SB - a test application which exercises the above libraries.
---------

    To run the test application, load all of the files onto the Sarian and
	type the following command at the command line interface:

        bas mbtest.sb <IP Address>

	Where <IP Address> is the IP address of the OTB module.

	The application loops forever. To stop it, use the command:

		basic 0 kill

DEMO4.SB - a program for use on the Sarian MODBUS demonstration box
--------
    This requires MBIO.SB and MBTCP.SB.
    The program monitors a voltage level and two buttons, and controls
    a fan and button indicator lights.
    It also sends an SMS alert to the number configured in "basic 0 string1" whenever
    the voltage threshold is passed.
    It also posts current status information to the Sarian web data collection server every 10 secs.
    To turn off web reporting, press both buttons together: they should remain off for 2 secs.
    To turn web reporting back on, again press both buttons together. They should remain on for 2
    secs to indicate that web reporting is switched on.

Ethernet configuration
======================

The Sarian needs to know the IP address of the OTB module, and must be configured
so that TCP/IP packets can be routed to it. Typically, this would be done by
configuring the OTB to use DHCP and configuring the Sarian as a DHCP server.
Alternatively, the OTB could be configured to use a fixed IP address based on
its MAC address. In this case the Sarian should be configured with an IP address
on the same sub-network.

Multiple OTB Modules
====================

The current example only demonstrates communication with a single OTB module.
To communicate with more than one module, the application would need to maintain
an open socket for each module. In general, the steps to be carried out by the
application are as follows:

At initialisation:
	open one socket for each OTB module
	call "setevent" for each socket

To send commands to a particular OTB module:
	Assign the global variable "TransactionIP" to the IP address of the OTB module
	Send command(s) to the OTB module using the library functions

Note that is has not yet been possible to test multiple OTB modules in this way.


