Script Basic Programming for Web Devices and Custom Gateways
Script Basic is an implementation of old fashioned "standard" Basic, the way it was before visual everything. It is ideal for creating applications that need to interface a device with a proprietary ASCII protocol to an open control system (Modbus or BACnet). Script Basic is available in Internet I/O Models IB-100 and IB-110, AddMe Jr. Basic, AddMe Jr. Data Manager, Babel Buster SP Custom, Babel Buster Pro V210, Babel Buster Pro V230.
Script Basic is entirely self-contained within the embedded server. It has a full set of math functions along with a rich set of character string manipulation functions. This implementation of Basic uses structured code rather than line numbers, resulting in more manageable code.
The one feature that makes the Control Solutions implementation of Script Basic really useful is file I/O, and the special files in particular. This is the mechanism for communication with an external serial ASCII device, or with an external TCP device connected via a socket connection. This is where you tame the wild side of proprietary.
Communicating with a proprietary device is of little use if you cannot translate the data to something accessible to an open system. This is where the second most useful feature of the Control Solutions implementation of Script Basic comes into play. Numeric data may be exchanged between your Basic program and Modbus registers or BACnet objects (as applicable for the product). Write data to the open system, or read data from the open system, using a standardized register access.
File I/O - Includes COM port I/O
ScriptBasic handles the files the same way as any other BASIC type language. You open a file, read from it, write to it and finally close the file. To make a jumpstart see a simple example:
open "myfile.txt" for output as 1
print#1,"This is the first line of myfile\n"
open "myfile.txt" for input as 1
line input #1, a
This simple program opens the file named `myfile.txt' in the current directory, prints a single line into it, and closes the file. Next time it opens the file for reading, reads a line from it, closes the file and prints the line read from the file to the screen.
When you open a file you have to have a file number that you want the file associated with. In the example above this number is 1. This is called many times the "file number". Whenever you do something with an opened file you have to use the file number.
You may open two "special" files for file access. These are a TCP socket, and the serial communications port (if supported by hardware, which it is on AddMe Jr. Basic).
This example will open the COM port and simply echo each line entered back to the port:
open "COM:38400" for comm as 1
line input #1, mystring
print #1, mystring
This example will open a TCP socket and query a remote web server, and print the page returned by the server to the virtual terminal page:
on error goto ErrorLabel
open "192.168.1.112" for socket as 1
print #1, "GET /UE/QueryCGI?reg1 HTTP/1.1\r\n"
print #1, "Host: icandoit\r\n"
print #1, "User-Agent: Control Solutions i.Board\r\n"
print #1, "Accept: text/xml,text/html\r\n"
print #1, "Keep-Alive: 300\r\n"
print #1, "Connection: keep-alive\r\n"
print #1, "\r\n"
while not eof(1)
line input #1, a
print "Server unreachable\n"
Script Basic is automatically included, preloaded, in the device when you order the applicable hardware model. You can obtain a copy of Script Basic to run on your PC for general testing. You will not have access to the Modbus registers or serial port found in the Control Solutions hardware, but if you find a way to emulate those, you can do a lot of other testing on your PC. Visit the Script Basic Wiki, or the original Script Basic site.
Copyright 2016 Control Solutions, Inc. All Rights Reserved.