1. SYSTEM OVERVIEW

Welcome to the world of home and building automation. An automated building is a foreign concept to many people used to living in a world of manual control. The idea of lights turning on and off by themselves, drapes automatically opening or closing, or chimes ringing in response to a car in the driveway may take some getting used to. However, once you've lived with the conveniences for even a short time, you quickly come to rely on them.

The Circuit Cellar Home Control System II and SpectraSense 2000 are new-generation control systems with roots in industrial control. With the XPRESS (eXpandable, Programmable, Real-time Event Supervisory System) programming language, the HCS/SS gives users unprecedented control over their environment.

A basic HCS/SS setup consists simply of a Supervisory Controller (SC). The base HCS II SC gives the user 16 digital inputs, 8 digital outputs, and 8 channels of 8-bit analog-to-digital conversion. The SpectraSense includes 24 inputs, 24 outputs, and 8 channels of analog-to-digital conversion with dynamic scaling. Optional plug-in expansion boards increase the direct digital I/O to 64 inputs and 64 outputs.

By adding one or more COMM-Link modules, the system's reach increases by leaps and bounds. Up to 31 COMM-Link modules may be connected to the system using inexpensive twisted-pair wiring. A single twisted pair (up to 4000 feet long) run throughout the house is all that's needed to tie the system together.

Among the COMM-Link modules, the PL-Link is used to communicate with X-10 devices connected to the power line. The MCIR-Link allows you to issue commands to the HCS/SS using a standard trainable hand-held IR remote control. It also enables the HCS/SS to send infrared commands to virtually any piece of consumer electronics equipment. The LCD-Link gives the user a gateway to the HCS/SS with its 4-line by 20-character display and four push-button inputs. Each DIO-Link has 8 bits of digital I/O: four inputs and four outputs. The DIO+-Link similarly has 4 digital inputs and 4 digital outputs, but they include buffers and drivers. The DIO+-Link also has 1 analog input channel. Finally, the ADIO sports 16 digital inputs, 8 digital outputs, 8 channels of 8-bit A/D conversion, and 4 channels of 8-bit D/A conversion. Up to 8 of each kind of module may be connected to the network (up to the system-wide limit of 31 modules total). Only one PL-Link may be used in a system, however. A PL-Link is unnecessary with the SpectraSense since the X-10 interface is already on the main board.

An IBM PC or compatible computer is used for initial setup and programming of the HCS/SS. When all is working as expected, the PC may be removed from the system until the next time a change is required. The HCS/SS doesn't tie up your expensive (and power hungry) PC. 

Definition of Terms

Here's a list of terms used throughout this manual you should understand before you proceed.

Supervisory Controller (SC) - the main board that controls the whole HCS II or SpectraSense 2000.

COMM-Link - a generic term used to describe any of the HCS II network modules, which include the PL-Link, IR-Link, MCIR-Link, LCD-Link, DIO-Link, DIO+-Link, and ADIO-Link.

Local Input (or Direct Input) - any digital input connected directly to the SC or Buffer Terminator (BUF-Term) board (which conditions those signals).

Local Output (or Direct Output) - any digital output connected directly to the SC or Buffer Terminator (BUF-Term) board.

Netbit - any digital input or output connected to any COMM-Link network module.

Edge - an on-to-off or an off-to-on transition on any digital input.

RS-485 - an interface standard used as the basis for the HCS/SS network. It defines the use of a single twisted-pair cable to carry all system communications.

XPRESS - eXpandable, Programmable, Real-time Event Supervisory System; the programming language used by the HCS/SS.


2. GETTING STARTED

If you're like most people, you don't have the patience to read the entire manual before setting up the system to see it work. To satisfy your impatience, we've provided quick setup instructions so you can get your system working in just a few minutes. When you're ready to install the system for real, read the remaining chapters before proceeding

Just a note of warning: Do not make any connections other than the ones we suggest below until after you've read the rest of the manual. Failure to heed this warning may result in damage to one or more HCS/SS components or to your own equipment. Such damage is not covered under any kind of warranty.

HCSII Quick Setup

The minimal setup we assume here is an HCS180 or HCS2-DX Supervisory Controller (SC), a BUF-Term parallel buffer board, and a PL-Link module. You should also have a push button or a sensor with a normally open output.

SpectraSense Quick Setup

The minimal setup we assume here is the basic SpectraSense 2000 package system. You should also have a push button or a sensor with a normally open output. As you see, set up is considerably easier with the SpectraSense than with the HCS II.

Quick Program

Type the sample program shown below into a plain text file on your PC using a text editor or a word processor in text-only mode. In some word processors, you must make a special effort to request that the program save your file as plain ASCII text. Call the file EVENTS.HCS. Be sure your word processor does not add any extra control characters or formatting commands.

         !
! Sample HCS/SS control program
!
! For SS, change the next line to SC = SpectraSense
CONFIG SC = HCS180
! For SS, eliminate the next line
CONFIG PL-Link = 1
Display Modules = L
! For SS, change the next line to Input(160)
DEFINE Sensor = Input(0)
DEFINE Lamp1 = Module(L1)
DEFINE Lamp2 = Module(L2)
DEFINE LampDelay = Timer(1)
BEGIN
IF Sensor=ON THEN
Lamp1 = ON
END
IF Sensor=OFF THEN
Lamp1 = OFF
END
IF Sensor=EDGE AND Sensor=ON THEN
Lamp2 = ON
LampDelay = ON
END
IF LampDelay>=5 THEN
Lamp2 = OFF
LampDelay = OFF
END

The program simply watches the input and turns the first lamp on when the input goes on, then off when the input goes off. It also turns the second lamp on when the input goes on, but turns the lamp off five seconds later regardless of the state of the input.

When you're done creating the file, exit the text editor and type COMPILE. The XPRESS compiler checks your program for proper syntax and creates a binary equivalent called EVENTS.BIN. If COMPILE finds any typing errors, fix them and compile the program again.

After a successful compile, type HOST to enter the host program. You should get a screen full of windows that display various system status information. Press the "C" key followed by "T" to set the SC's time and date. Then, press "F" followed by "L" to load your compiled program into the SC. When HOST tells you the load is successful, your program is running and should respond to your sensor or push button as described above.

If HOST tells you that the SC isn't responding to either command, there is probably a problem with the serial connection between your PC and the SC. Double check all connections.

The PL-Link must also be active on an HCS II system for any X-10 commands to be sent to the power line. Make sure the Network Mods window shows a "*" next to the PL-Link label. If either " - " or "E" show up, double check your network connections.

Your HCS/SS is now operational. Feel free to experiment by modifying the sample program for other behaviors. Be sure to recompile the program each time you make a change. When you're ready to begin the actual installation of your system, read the rest of this manual before making any more connections.


3. System Design

The HCS/SS provides you with an incredible amount of flexibility in how you set up your system. We recommend you take some time to consciously design your overall system rather than randomly run wires and make connections. Take a few moments to think about how you want your system to operate.

X-10 signals travel over existing power lines, so additional wire isn't necessary. While the X-10 system is perfect for turning lights on and off, it can be somewhat unreliable and slow for other types of communication such as sending sensor status back to the SC.

It's always a good rule of thumb to run twice as much wire as you think you'll need. Eight-conductor (four twisted pair) cable is a good choice if you're pulling wire anyway. You may also be able to run a group of sensors back to a single DIO-Link or ADIO-Link, requiring just one twisted pair to be run back to the SC. For example, if you have three bedrooms grouped at one end of the house, you could run all the sensors from those three rooms back to a single DIO-Link located centrally to the rooms.

Responses to sensors connected directly to the SC are almost instantaneous when controlling an output connected directly to the SC. Inputs and outputs traveling across the network slow the response down a bit. For example, in a typical setup, sending an X-10 command in response to an input on the SC may take half a second, but turning on an output on a DIO-Link in response to an input connected to a DIO-Link may take up to two or three seconds.

Sensors that require an immediate response should have wires run back to the SC for direct (or local) connection. An example of such a sensor might be a motion sensor at the top of a stairway. How useful is a light that doesn't come on until you're halfway down the stairs? On the other hand, a 1- or 2-second delay won't make any difference if you're sounding a chime in response to a car in the driveway.

Locating the Supervisory Controller

The SC should be placed in a central location close to an AC outlet (ideally near the fuse box or breaker panel). Easy access to a telephone line may also be necessary for future COMM-Link modules.

Many people prefer to mount a sheet of plywood on the wall in the basement or garage where the SC is to be installed. The SC may be mounted on the wood at chest level to make working on it easier. Additional expansion boards that are to be located nearby (such as a PL-Link) may also be mounted right on the wood. Buffer boards and connector strips are easy to mount and make running wires from place to place clean and easy.

Alternatively, you might mount the SC and any buffers and connectors inside a standard metal alarm-type box with a door on it. The SpectraSense 2000 already comes packaged in such an enclosure.

Don't forget you'll need to connect a PC to the SC for programming, so there should be either a PC nearby, a portable PC (such as a laptop) available, or a serial cable run from the SC to your PC. Keep in mind that if you run cable for an RS-232 connection, the cable should be less than 50 feet long and kept away from noise sources like blower motors, oil burner transformers, and power lines in general. 

Power Supplies

The original HCS180 and ADIO-Link require +5 V while the newer HCS2-DX and the other COMM-Link modules all accept any DC voltage between 9 and 18 V. A single power supply may be used to power the whole system, or separate power supplies for each COMM-Link may be used. If you're using a BUF-Term parallel buffer board with your SC, you may run a 9 - 18-V power supply into it and it will provide regulated 5 V for the SC, allowing the use of a single 12-V (or similar) power supply for the whole setup. The SpectraSense comes with its own power supply.

If you elect to use a single power supply for the system, you might run the power in the same cable as the main network to make powering network modules easy. In such a setup, you'd have to run at least four-conductor (two twisted pair) cable to each node location. Be sure to allow about 200 mA at 12 V for the SC and BUF-Term combination, plus an additional 200 mA for each COMM-Link module on the network.

For an example setup consisting of an SC, BUF-Term, and three COMM-Links, your power supply should be capable of supplying at least 800 mA at 12 V. In such a case, it would be prudent to make sure the supply is good for at least 1 or 1.5 A to allow for future expansion.

The memory on the SC is battery backed, so in the event of a power failure, your XPRESS program won't be lost. When power is restored, the SC will continue to execute your XPRESS program as if power had never been lost. Be aware, however, that other devices in the house that aren't battery backed (such as X-10 modules) may need to be manually reset after a power outage. 

Setting Up the Network

In a very basic HCS/SS setup where only an SC is used with direct inputs and outputs, a network isn't necessary because there aren't any network modules to connect.

In an only slightly more complicated system where the only network module is a PL-Link, all that's really necessary is a six-inch piece of cable to connect the PL-Link to the SC. No additional cable needs to be run and the wiring to the PL-Link can be virtually anything.

In systems where the network extends beyond six inches, some care must be taken when selecting and running the cable to ensure error-free operation of the network. 

Selecting Cable

The most important factor in selecting a cable is to be sure it contains twisted pairs. Most common 4-conductor telephone cable runs the wires in parallel and is not suitable for use in this system. The minimum cable must contain two twisted wires (a single twisted pair). The wires may be solid or stranded, and are typically 22 gauge down to 26 gauge. If you are running power to the modules, then cable with two twisted pairs (four wires) is necessary. If you're installing new cable anyway, we recommend you run cable containing at least four twisted pairs (eight wires) to account for expansion. The emerging CEBus home automation standard also calls for Category 5, four-twisted-pair cable, so you'll be ready for future CEBus devices as well.

 Running Cable 

The network topology is left up to you to decide. A single cable run may be made throughout the house, where the cable starts at the SC, then goes from one room to the next. This configuration is the easiest to run and requires the least amount of cable. A problem with this approach is the possibility that a wire in the cable could break somewhere in the middle of the run, cutting off all devices downstream of the break from the rest of the system.

The alternative we recommend is to run separate cables from the SC to each room in the house. Some larger rooms may require multiple cable runs. While this approach takes more time in the beginning and requires more cable, it offers a good deal more flexibility, and troubleshooting is easier when you can isolate individual rooms. As above, the CEBus specification calls for separate cable runs from a central location to each room, so you're once again preparing for the future in more ways than one.

You may also find it easier to connect sensors directly to the SC if you run separate cables to each room. For example, if you run four-twisted-pair cable to each room, you can use two of the pairs to carry the network and power to, say, a DIO-Link that has window and door sensors tied to it, and the other two pairs to carry contact closures from a pair of motion detectors back to the SC for direct connection.

When installing the network cabling, be sure the cable is at least six inches away from any AC power cable. Never install network cable in the same conduit as AC power-line cable. If the network cable must cross the path of an AC cable, be sure the two paths cross at right angles. 

Analog and Digital I/O

The digital I/O ports on the HCS180, HCS2-DX, LCD-Link, DIO-Link, and ADIO-Link are low-current, TTL-compatible ports. In almost all installations, additional buffers and drivers are necessary when making connections to these ports. Under no circumstances should the ports be used (when configured as outputs) to drive lamps, relays, bells, or other devices directly. Sensors may be connected directly to the ports when used as inputs, but extreme care must be taken to ensure the voltage on the inputs doesn't drop below 0 V or go above 5 V.

To protect your HCS II hardware, we strongly advise the use of our BUF-Term parallel buffer board. Each input buffer on the board withstands voltages from - 30 V up to +30 V and each output driver handles 500 mA at 50 V (with 20% duty cycle) or 175 mA at 50 V (with 100% duty cycle). The digital inputs and outputs on the SpectraSense already use such buffers and drivers.

Similar precautions must be taken when dealing with the analog I/O on the SC and ADIO-Link. The analog inputs must be constrained to a range of 0 - 5 V, while the outputs must be buffered before they can be used to drive any device. Because the requirements of an analog interface usually differ for every installation, we currently don't have any off-the-shelf analog buffer boards. Be sure to contact Circuit Cellar technical support if you're at all unsure about how to make analog connections in your application.

Damage to boards caused by unbuffered inputs or outputs is not covered under warranty!

Refer to the individual hardware manuals for the SC, BUF-Term, and COMM-Links for details on connector pinouts and interface limitations. Appendix B lists the ports on each of the boards; whether they are assigned to be inputs, outputs, or both; and how they are referenced from within an XPRESS program. 

Signal Polarity

In the XPRESS language, an unbuffered digital input or output at 0 V is considered OFF while an input or output at 5 V is considered ON. Buffers and interface circuitry may ultimately invert inputs or outputs so the ON and OFF labels end up reversed. For example, a simple transistor driver on an output driving a light may work by turning the light on when the output goes to 0 V and off when the output goes to 5 V. In such a case, the XPRESS statement "Output(x) = ON" actually turns the light off.

Similarly, a normally open contact closure might have one contact connected to ground while the other contact is connected to a system input with a pull-up resistor. When the sensor is inactive (or open), the input reads ON. When the sensor closes and grounds the input, the input goes OFF.

You must take all such polarity reversals into account when writing your program. To make a program easier to read, you might use the following definitions:

      DEFINE OnN = ON ! Normal "on" state
      DEFINE OffN = OFF ! Normal "off" state
      DEFINE OnI = OFF ! Inverted "on" state
      DEFINE OffI = ON ! Inverted "off" state
    

For all inputs and outputs that use normal (or noninverted) states, you would use the "OnN" and "OffN" pair in your program. For inputs and outputs that get inverted by buffers, use the "OnI" and "OffI" pair. 

Response Time

Response time to inputs (analog and digital) depends a great deal on whether the input goes over the network and, if so, how complicated the network is. Sensors that need immediate attention should be connected to the SC. Response time to such inputs can be almost instantaneous. When inputs must go over the network, response times range from about half a second for a simple network to several seconds for a more complicated network.

Analog and digital output response time behaves similarly. Outputs connected to the SC change immediately in response to a XPRESS statement evaluating true, while outputs connected to the network require from half a second to several seconds to be changed depending on network complexity. 

X-10 Power-Line Communications

The X-10 system communicates without additional wiring by sending messages through the home's power lines. The world of AC power was never designed for data and is a harsh, difficult environment in which to send packets of information. While the vast majority of X-10 installations work flawlessly, any number of factors in the home can combine to make such communication unreliable in some cases. 

Signal Bridiging

If you find you can control some X-10 modules reliably, but can't reach others, you're probably having trouble communicating between 110-V legs.

Power enters the house through three wires: two "hot" wires and one neutral wire. The voltage between the two hot wires is 220 V, while the voltage between either hot wire and the neutral wire is 110 V. Appliances such as electric stoves and clothes dryers that use 220 V are connected to both hot wires. The rest of the house is usually wired so half the outlets are connected to one hot wire and the other half are connected to the second hot wire.

X-10 transmissions that originate on one hot wire (or "leg") usually must exit the house, go all the way to the pole on the street, then back to the house to get to the other leg. Most of the time the data packet won't survive such a trip and is lost. The electric stove and clothes dryer mentioned above can often provide a shortcut between legs so the packet can get across, but the shorcut is only there when the appliance is on.

Leviton Manufacturing makes a signal bridge module which can be installed in the fuse box or breaker panel, that provides a continuous path for packets to travel from one leg to the other. Contact Circuit Cellar for information on how to obtain this module. We recommend only a qualified electrician install this device.

Multiple Transmitters

If you find that commands sometimes don't get through when you're using an X-10 manual control unit, your commands may be colliding with those being sent by the HCS/SS. When a group of people are talking and two speak at the same time, understanding what either said is usually impossible. Similarly, when the HCS/SS is transmitting and you try to transmit at the same time, both messages are usually lost.

Unfortunately there isn't much that can be done (short of you never using a manual X-10 controller). In most installations, the HCS/SS is seldom transmitting, so the chances of a collision are low. If you leave X-10 refresh turned on (see the Refresh command in Chapter 7), your chances of a collision are much greater. In general, if you leave refresh off when you're home, and only turn it on when you're away, collisions shouldn't be a problem.

Initial Start Up

When all the HCS/SS hardware is in place, connect the RS-232 cable from the SC to COM1 or COM2 of the host PC. Type the following program into a file using a text editor (as described in Section 4.1) and save it as EVENTS.HCS. Modify the Config statements to reflect the proper number of each kind of COMM-Link module you have connected (e.g., if you don't have an LCD-Link in your system, change the "1" to a "0" in the LCD-Link configuration statement).

CONFIG SC = HCS180 ! or SpectraSense
CONFIG PL-Link = 1
CONFIG IR-Link = 1
CONFIG LCD-Link = 1
CONFIG DIO-Link = 1
CONFIG ADIO-Link = 1
Display Modules = A,B,C
BEGIN
IF Reset THEN
Refresh = 0
END<

Compile the above program using COMPILE as described in Section 4.1.

Run the HOST program as described in Section 4.2 and press the "F" key followed by "L" to load your XPRESS program. If HOST responds with a "sad" tone and a message indicating a timeout, press "F" and "L" again. If the program still won't load, double check the serial connection between the SC and the PC. When the program transfer completes with a "happy" tone, you should immediately see the current status of any network modules, X-10 modules, direct inputs, and direct outputs you've defined in your XPRESS program.

All network modules that are powered up and properly connected to the network should show a "*" in the network status window indicating the module is active. A " - " indicates the module isn't responding at all. It may not be powered up properly or may not be connected to the network correctly. An "E" indicates errors are occurring during network communication. Check all network wiring to be sure the cable doesn't run near any sources of electrical noise (including AC power lines) and check network termination on all COMM-Links. Also, make sure the network connections on the module aren't reversed.

If the X-10 status window doesn't list housecodes A, B, and C, then there is a problem with the PL-Link connections. You should also see either a " - " or a "!" in the network status window next to the PL-Link label. Check the PL-Link's connections as described in Section 2.1.

Now, check any direct inputs connections. The current status of each input is updated once per second in the input window. For example, if you have a motion detector in the room where you're working connected to one of the direct inputs, you should see the input state change whenever you move.

You won't be able to check any output connections until you've written a program to control those outputs.

When the system seems to be working correctly, you may begin writing your first custom XPRESS program. Refer to Chapters 6 and 7 for details about XPRESS.

 HOST displays HCS/SS system status information in individual windows on the PC's screen. Each type of information has its own window. The size and position of all windows may be changed using a mouse or the keyboard as described above. The content of each window depends on what hardware was defined at the top of the XPRESS program being run.

The X-10 module status window displays the housecodes called out using the DISPLAY configuration keyword in the XPRESS program. Any modules that are on or dimmed (regardless of dim level) are designated by a "1" on the screen. Modules that are off or not used show up as "0" on the display.

The network-module status window displays the status of only those network modules defined by CONFIG statements in the XPRESS program. The following summarizes the three possible status indicators:

* : module active and responding normally

- : module didn't responded when polled by the SC

E : response from module contained an error and was discarded

An occasional " - " indicates there might be some noise on the network and shouldn't be a concern. Any module showing a consistent " - " should be checked out. Similarly, an occasional "E" indicates some noise on the network and can usually be safely ignored. Consistent errors indicate a problem with the network.

Digital inputs and outputs and netbits are displayed in groups of 24 horizontally (though a row may not contain a full 24 bits). A "1" indicates the bit is on and a "0" indicates the bit is off. The starting bit number for each row is shown at the left of each row. The numbers across the top of the rows are offsets from that starting bit number. For example, the first row might have "000" at the left, indicating the leftmost bit in the row is 0, followed by 1, then 2, and so forth. If the next row has "016" at its left, then the bit numbers in that row are 16, 17, 18, and so forth.

Which inputs, output, and netbits are displayed depends on the hardware defined with the CONFIG statement in the XPRESS program. For example, if one ADIO-Link is defined as present in the system, netbits 96 - 119 are displayed on the HOST screen automatically.

Analog input and outputs are displayed similarly, but with just two values (analog inputs) or four values (analog outputs) per row.


4. SOFTWARE ON THE PC

A PC-compatible computer is used to program and monitor the HCS/SS. Once the system is working, the PC may be disconnected or shut off until changes are needed. While the PC software works on most any PC compatible, we recommend at least an 8-MHz PC or an AT-class machine. The software works with a single floppy disk drive and either color or monochrome display.

There are two programs used on the PC: COMPILE and HOST. COMPILE is used to compile XPRESS programs from their original source form to a binary representation used by the SC. HOST is used to set the time, send XPRESS programs to the SC, display system status, clear the system log memory, and transfer logged data from the SC to a disk file on the PC. 

COMPILE

XPRESS programs may be written using any text editor capable of producing flat ASCII (or text) files. If you're using a fancy word processing program (such as Word Perfect, Microsoft Word, WordStar, Volkswriter, or any of the hundreds of others), be sure you save your code as a plain text file that contains no control characters or formatting commands. Make absolutely certain there is a carriage return after the last line of your XPRESS program. It is a good idea to leave a few blank lines at the end of the code to be sure.

Before your XPRESS program can be sent to the SC, the program must be compiled. The compiling process checks your program for correct syntax and value ranges and creates a binary file containing the raw code for the SC.

The form of the COMPILE command line is as follows (items in braces are optional):

COMPILE {filename}

where: filename is optionally the name of your source file

If the filename isn't given, COMPILE assumes the source file is called EVENTS.HCS. If the extension isn't given, COMPILE assumes an extension of .HCS. The following are valid command lines:

COMPILE compiles the code found in EVENTS.HCS

COMPILE MYPROG compiles the code found in MYPROG.HCS

COMPILE PROG2.TXT compiles the code found in PROG2.TXT

COMPILE always creates a binary file called EVENTS.BIN. The HOST program expects your compiled XPRESS program to be in EVENTS.BIN, so be sure not to change the name of the file.

When errors are found during compilation, COMPILE will tell you what kind of error was found and what line it was on. It then displays the offending piece of code.

COMPILE alerts you to several kinds of errors. Syntax errors are usually typographical errors: a misspelled command or a missing statement. A single syntax error may result in more than one error message because COMPILE continues processing your program even after the error occurs. Often fixing a single error will eliminate multiple error messages.

Value errors are often more subtle. They occur when a value you've specified in a comparison or an assignment is too large or too small. For example, if you accidentally specify a time of 28:30 instead of 18:30, COMPILE flags a value error because the hours may only be between 0 and 23.

COMPILE also checks for unbalanced parentheses and IF/END pairs. 

HOST

The HOST program is used to send compiled XPRESS programs to the SC and to display overall system status. HOST displays everything in a text-based windowing environment and works equally well on graphics and text-only systems, and on color and monochrome systems. You should connect the SC to either COM1 or COM2 on your PC before running HOST.

The form of the HOST command line is as follows (items in braces are optional):

HOST {/COM1|/COM2|COM3|COM4} {/M} {//}

where: /COM1 tells HOST to use COM1

/COM2 tells HOST to use COM2

/COM3 tells HOST to use COM3

/COM4 tells HOST to use COM4

/M forces HOST into monochrome mode (display just black and white; usually used on systems with color adapter cards and monochrome monitors)

// displays a short help screen and exits

Examples of valid HOST command lines include:

HOST start HOST in its default mode

HOST /COM2 start HOST using COM2

HOST /M start HOST in monochrome mode

HOST /M /COM2 start HOST in monochrome mode using COM2

HOST // tell HOST to display a short help screen and exit

The default mode for HOST is to use COM1 and full-color windows.

When HOST is started, it initializes all the windows, puts a command bar at the top of the screen, and displays a window containing information about itself. The information window disappears after a few seconds.

A Microsoft-compatible mouse may optionally be used to select commands and to move, resize, and close any of the on-screen windows. Be sure the correct mouse driver software is installed and the mouse is plugged in before running HOST. In the absence of a mouse, the keyboard may be used to perform all the same functions.

The current active window is highlighted by a bright white frame around it. To select a new window, press the Tab key until the desired window is highlighted. Using a mouse, simply click anywhere inside the desired window to make it active.

The active window may be moved on the screen by using the arrow keys (either the grey keys or those on the keypad). Using a mouse, place the cursor anywhere on the top bar of the window and drag it while holding the left mouse button.

The active window may be resized by using the arrow keys while holding the Shift key. Using a mouse, place the cursor on the lower-right corner of the window and drag it while holding the left mouse button. The correct spot on the lower-left corner is indicated by a single line (as opposed to the double line around the rest of the window).

HOST Commands

There are six main pull-down menus displayed across the top of the HOST screen:

! program information

File commands dealing with the PC's disk

Command commands that may be sent to the SC

Log commands dealing with data logging

Window open (or reopen) any closed windows

Modem commands dealing with an optional modem 

To use those pull-down menus, press the key that corresponds to the red letter in the menu name (pressing Alt isn't required). Using a mouse, simply click anywhere on the menu name.

To select a command in the menu (once the menu is displayed), press the key that corresponds to the red letter in the command name. Using a mouse, click anywhere on the command name. It isn't possible to drag the cursor down through the commands. You must perform separate clicks to select the menu, then the command.

To open a window that is closed, select the window name from the Window menu (see below).

The screen setup is saved in a disk file when HOST is exited so the screen retains its look from session to session. To restore the default window sizes and placement, simply delete the HOST.CFG file from the disk.

The following sections further describe the commands in each pull-down menu. 

!Menu

About… Display information about the HOST program including its version number. The display window is automatically closed after a few seconds.

 

File Menu

Load Load a new XPRESS program from disk and send it to the SC. The command expects to find your compiled XPRESS program in a file called EVENTS.BIN. If that file can't be found, an error message is displayed. Errors are also displayed if your XPRESS program was compiled with the wrong version of COMPILE (COMPILE's version must match the version of the EPROM installed in the SC) or if your compiled program is too big to fit in the SC's memory.

Quit Quit HOST. Your screen is restored to the state it was in when HOST was started.

 

Command Menu

Set Time Read the current time and date from the PC's internal clock and set the SC's clock/calendar accordingly. Be sure you set the PC's clock and calendar to the correct time and date before running HOST.

Set Input… Override a system digital input and force it to either a high (1) or a low (0) value. To reset the input to normal operation, select Transparent. This command is used to test sections of XPRESS code from the HOST screen without having to physically toggle a system input to initiate an action.

Set Output… Set a system digital output to either a high (1) state or a low (0) state.

Set X-10… Send an X-10 command to the power line.

Set ADC… Override a system analog input and force it to a specific value. To reset the analog input to normal operation, select Transparent. Any value in the range of 0 - 4095 may be set on any analog input channel regardless of the resolution of the ADC normally associated with that channel. When set to Transparent, the channel resolution reverts to reflect the hardware present.

Set DAC… Set a system analog output. Since the only analog outputs are on ADIO-Links, this command only applies to applications that contain at least one ADIO-Link.

Set Netbit… Set a system netbit to either a high (1) or a low (0) state.

Voice… Send a text string to be spoken to the text-to-speech synthesizer board. The HCS-Voice1 board must be installed in the system for this command to work. See the Say command for more details on forming the text string. Press Return alone to exit this command.

Network… Send a text string to the system RS-485 network. This command should only be used by people who are familiar with constructing commands for network modules. The command should start with the module address, followed by the command. The SC takes care of adding the proper header byte and checksum.

Log Menu

Clear Clear the log memory. The log memory should always be cleared by using either this command or the ClearLog XPRESS command before any logging takes place. This command also gives you a way to wipe out any old data and start logging new data at a known time.

Size        Displays the number of data entries in log memory. The value is in the range of 0 - 4095.

Dump Dump logged data from the SC's memory to a disk file on the PC. The data is always stored in a file called LOGDATA.BIN. If you want to save any old data previously dumped to disk, be sure to rename the old data file before performing a new dump. See Chapter 8 for more information on data logging.

 

Window Menu

Any screen window that is closed may be opened by selecting it from the Window menu. What information is displayed in each window is indirectly controlled by what hardware is defined at the start of the XPRESS program being run.

Note that the Message window is automatically opened if it is closed and a console message is received from the SC. See the description of the Console command in Chapter 6 for more details.

 

Modem Menu

Init… Set a new modem initialization string. The default string used by HOST is AT&FLT&K3&Q5. If your modem requires something different to work properly, you may use this command to define a new init string. The string is saved in the HOST.CFG file upon exit from HOST, so you only have to set the init string once. Be sure to start the command with "AT" as shown above.

Dial… Instruct the modem to dial a phone number and attempt to connect to a remote HCS/SS. Spaces, hyphens, and parentheses in the phone number are ignored. HOST uses tone dialing by default. To use pulse dialing, include a "P" at the start of the phone number. Insert commas anywhere in the phone number to include 2-second pauses. It is normal for some modems to pause briefly after dialing the first digit before continuing with the rest of the number.

Hangup Instruct the modem to break an existing modem connection and hang up the phone line.

If there is a problem with the connection between the PC and the SC, HOST times out during most of the commands that require a response from the SC. If a timeout occurs, a "sad" beep sounds and a message pops up informing you of the timeout and asking you to try again. If the timeouts persist, check the physical connection between the PC and the SC.

Successful transfers of information during most commands result in a "happy" beep and a message that informs you of the success. 

HOST Windows

HOST displays HCS/SS system status information in individual windows on the PC's screen. Each type of information has its own window. The size and position of all windows may be changed using a mouse or the keyboard as described above. The content of each window depends on what hardware was defined at the top of the XPRESS program being run.

The X-10 module status window displays the housecodes called out using the DISPLAY configuration keyword in the XPRESS program. Any modules that are on or dimmed (regardless of dim level) are designated by a "1" on the screen. Modules that are off or not used show up as "0" on the display.

The network-module status window displays the status of only those network modules defined by CONFIG statements in the XPRESS program. The following summarizes the three possible status indicators:

* : module active and responding normally

- : module didn't responded when polled by the SC

E : response from module contained an error and was discarded

An occasional " - " indicates there might be some noise on the network and shouldn't be a concern. Any module showing a consistent " - " should be checked out. Similarly, an occasional "E" indicates some noise on the network and can usually be safely ignored. Consistent errors indicate a problem with the network.

Digital inputs and outputs and netbits are displayed in groups of 24 horizontally (though a row may not contain a full 24 bits). A "1" indicates the bit is on and a "0" indicates the bit is off. The starting bit number for each row is shown at the left of each row. The numbers across the top of the rows are offsets from that starting bit number. For example, the first row might have "000" at the left, indicating the leftmost bit in the row is 0, followed by 1, then 2, and so forth. If the next row has "016" at its left, then the bit numbers in that row are 16, 17, 18, and so forth.

Which inputs, output, and netbits are displayed depends on the hardware defined with the CONFIG statement in the XPRESS program. For example, if one ADIO-Link is defined as present in the system, netbits 96 - 119 are displayed on the HOST screen automatically.

Analog input and outputs are displayed similarly, but with just two values (analog inputs) or four values (analog outputs) per row.


5. MODEMS AND CALLER ID

It is sometimes not convenient (or possible) to have a PC close to the HCS/SS to check its status, load a new XPRESS program, or dump logged data to disk. It is possible to connect a high-speed modem to the HCS/SS and access it using a PC with a modem from anywhere there is a telephone.

When connected by modem, all of HOST's capabilities are available exactly as if the PC and HCS/SS were directly connected.

For example, a professional installer may want to offer a service where he updates a customer's XPRESS program upon request (for a fee, of course). Rather than drive to the customer's location to load the updated program into the HCS/SS, he can simply call the customer's HCS/SS from his office and do it remotely.

Likewise, an HCS/SS may be installed in a remote location to perform control functions and log status information. Rather than go all the way out to the site, it's possible to call the HCS/SS, dump the logged data to disk for further processing, and then clear the log memory for new entries.

Most name-brand modems that support speeds of 9600 bps (V.32) or faster (V.32bis and V.34) should work just fine.

HCS/SS Modem Connection

The HCS/SS needs an external modem fitting the above description. To connect the modem to the HCS/SS, you must use a null-modem cable that swaps pins 2 and 3. A typical 25-pin null-modem cable also swaps pins 4 and 5 and pins 6 and 20. At the very minimum, pins 2 and 3 should be swapped, pins 4 and 5 should be tied together on the PC end, and pins 6, 8, and 20 should be tied together on the PC end.

Two XPRESS commands set up the modem on the HCS/SS end. ModemRings tells the modem how many rings should go by before it answers the phone. ModemInit sets up a custom modem initialization string. The default initialization string built into the HCS/SS should work fine for most modems, so do not use ModemInit unless the built-in string doesn't work with your modem. See Chapter 7 for more details on these two XPRESS commands.

You must load the initial XPRESS program (containing the ModemRings command) into the HCS/SS using a PC connected directly to the HCS/SS. Once that program has been loaded, simply unplug the PC and plug in the modem (using the null-modem cable). The HCS/SS automatically senses the presence of the modem and initializes it accordingly.

To reconnect the PC directly to the HCS/SS, simply unplug the modem and plug in the PC (using the straight-through cable). If nothing appears on the HOST screen after reconnecting the PC, press Enter and the display should become active.

PC Modem Connection

Once the HCS side has been set up, it's time to connect a modem to the PC that will be used to call the remote HCS. Simply connect any modem that matches the description given above to the PC. When using an internal modem, no cabling is necessary. When using an external modem, use a straight-through serial cable to make the connection.

Next, run HOST, making sure to tell it which COM port the modem is connected to (if other than COM1). The status windows open on the screen, but no data is displayed. Select the Modem menu, then the Dial command. You will be prompted for a phone number. Enter the phone number the HCS/SS is connected to.

HOST uses tone dialing by default. If you must use pulse dialing, add a "P" to the start of the phone number you enter. Spaces, hyphens, and parentheses in the phone number are ignored. Commas may be used to insert 2-second delays in the dialing sequence.

HOST then calls the number you entered and attempts to connect with the remote HCS/SS. If successful, data is displayed on the screen just as if the PC and the HCS/SS were connected directly. All of HOST's functions are available for use when connected via modems. When you want to disconnect from the remote HCS/SS, select the Modem menu and the Hangup command. 

Caller ID

Certain modems on the market today also support Caller ID. Caller ID is a service provided by your local phone company. When active, a packet of data is sent by the phone company between the first and second rings. This packet includes the date and time of the call plus the full 10-digit phone number of the calling party. Some phone companies also include the name of the calling party.

The HCS/SS can receive the Caller ID data from modems that support this feature and pass it along to your XPRESS program for further action. (Note that your local phone company must offer Caller ID service in your area and you must pay them a monthly fee to receive it. Contact your local phone company for more information.) The HCS/SS only processes the date, time, and number data. Any name data is ignored and is not available to XPRESS.

At this time, we have tried the Caller ID support of only Supra modems (specifically, the SupraFAXModem 144LC). Other brands do support the feature, but we can't guarantee they will work properly with the HCS/SS. In general, any modem that uses the Rockwell modem chipset and whose manual specifically states that it supports Caller ID should work. NOT ALL MODEMS THAT USE THE ROCKWELL CHIPSET ARE CAPABLE OF RECEIVING CALLER ID DATA. If your modem's manual makes no mention of the feature, then your modem almost certainly doesn't support it. The Caller ID feature in Practical Peripherals modems is not supported at this time.

To use the HCS/SS Caller ID support, connect a modem with Caller ID as described in Section 5.1 and include the command "CallerID = ON" in your XPRESS program. When the phone rings, the Caller ID data is available to your XPRESS program shortly after the first ring. You may then have the HCS/SS log the call, display the information, or even speak the name of who is calling. See the Caller ID commands in Chapter 7 for more details.


6. XPRESS PROGRAM STRUCTURE

The HCS/SS is programmed using a language called XPRESS. It is an easy-to-use language similar to BASIC, but tailored to the needs of home and building automation. You needn't be an expert programmer to use XPRESS, but knowledge of rudimentary programming concepts is helpful.

XPRESS programs consist of three sections: configuration, continuous control, and sequential control.

The configuration section defines what processor board is being used as the SC, what hardware is on the SC, how many of each kind of COMM-Link is present on the network, and what X-10 housecodes should be displayed by the HOST program. It also contains all the label definitions.

The two control sections make up the bulk of the XPRESS program and consist of a series of IF/THEN/ELSE statements. The IF portion is made up of any number of system conditions combined using Boolean operations. When the IF portion is true, the list of actions in the THEN portion is carried out. When the condition is false, any actions in the optional ELSE portion are executed instead.

The continuous control section contains any code that must always operate in a continuous fashion without pauses or delays. The sequential control section contains code that may pause waiting for user input or some action to complete. Most of your code will go in the continuous section. Program statements that only work in the sequential section (e.g., DialTone, SayW, and Wait) are clearly marked in the next chapter.

The Begin keyword denotes the end of the configuration section and the start of the control sections. The Sequential keyword indicates the end of the continuous control section and the start of the sequential section.

The following is a basic outline of the structure of an XPRESS program:

CONFIG …
DISPLAY … Configuration section
DEFINE …
BEGIN
IF|IFA {NOT}<expr1> <op> {NOT}<expr2> ... THEN
<action1>; <action2>

ELSE Continuous section
<action1>; <action2>

END
SEQUENTIAL
IF|IFA {NOT}<expr1> AND|OR {NOT}<expr2> ... THEN
<action1>; <action2>

ELSE Sequential section
<action1>; <action2>

END

Throughout the program, case is ignored (i.e., upper- and lower-case letters are treated identically). Tabs and spaces may be used freely. With the exception of text strings and mathematical equations, multiple lines may be used for expressions. Multiple actions may be placed on a single line by separating them with semicolons.

Comments may be placed anywhere in the program by preceding them with an exclamation point. After the exclamation point, the rest of that line is considered a comment. 

IF Expressions

All actions are based on conditions tested in IF statements. An IF statement contains one or more expressions separated by AND or OR and may be preceded by NOT. Evaluation proceeds in strict left-to-right order. Parentheses may be used to prioritize evaluation order.

Expressions are made up of two system values separated by an operator. Valid operators include "=", "<>", ">", "<", ">=", and "<=". Whereever a system value is called for in the next chapter (denoted by <val>), any of the following may be used:

constant (0 - 32767), ON, TRUE, OFF, FALSE, Variable(n),
ADC(n), Timer(n), IRcode(c), Random(n), Hour, Minute,
Second, Day, Month, Year, DOW, Rings, CIDnew, CIDmonth,
CIDday, CIDhour, CIDminute, CIDarea, CIDexch,
CIDnumber
The following may also be used as system values, but only in the sequential section:
DTMFdigit, DTMFnumber, DialTone, CallProgress
Other keywords can only be tested against specific conditions (which are outlined in the next chapter) and include:
Input, Output, Time, Netbit, Module, Reset
Examples of valid IF statements include:
IF Timer(4)>=5 THEN ...
IF Hour=5 AND Minute>15 THEN ...
IF ADC(8)>Variable(2) OR (Random(50)<>10 AND
Input(4)=ON) THEN ... 

IF/IFA Differences

Two kinds of IF statements are supported in XPRESS: IF and IFA. When an IF statement is evaluated as true, its THEN portion is executed. On subsequent passes through the XPRESS program, if the condition in that IF statement continues to evaluate true, the THEN portion is skipped (it is executed exactly once for each occurrance of a true condition). The THEN portion is only executed again when the condition evaluates false and then true again.

On the other hand, when the condition in an IFA (IF Always) statement is true, its THEN portion is executed on every pass through the XPRESS program as long as the condition remains true.

When a statement contains an ELSE portion, the ELSE is treated according to its companion IF/IFA. That is, when an IF condition evaluates false, the ELSE portion is executed exactly once. On subsequent passes through the program, if the condition remains false, the ELSE portion is skipped. The condition in the IF statement must go true, then false again for the ELSE portion to be executed again.

Likewise, an ELSE associated with an IFA is executed on every pass through the program in which the IFA condition evaluates false.

For example, in the following code fragment, the "on" message is sent to the LCD-Link only once when the input goes true, and the "off" message is sent just once when the input goes false. If the THEN and ELSE portions weren't skipped on subsequent passes through the program, the LCD-Link would be overrun with messages.

IF Input(5)=ON THEN
LCD(0) = "Input is on"
ELSE
LCD(0) = "Input is off"
END

In the next example, the LED connected to the output bit is toggled on every pass through the XPRESS program. Such a setup is useful to give a visual indication of overall system performance and can be helpful in assessing how much a hardware or software change to the system affects its throughput.

IFA Output(2)=OFF THEN
Output(2) = ON
ELSE
Output(2) = OFF
END

IF/IFA statements may be nested in any way to any number of levels. Care must be taken, however, when nesting IF statements within IFA statements. Take the following example:

IFA Input(10)=ON THEN
Output(2) = ON
IF Module(D2)=ON THEN
LCD(0) = "Module is on"
END
END

When input 10 is on, the IFA's THEN portion is executed every time through the program. When module D2 turns on, the command to send a message to the LCD-Link is executed the first time, then skipped on subsequent passes. Now suppose input 10 turns off. The entire IFA THEN portion is skipped because the IFA condition is false. Even if module D2 turns off and then back on, the inside IF is never evaluated so it never sees the module's on-off-on transition. If module D2 is on when input 10 goes on again, the THEN portion associated with the inside IF is skipped because it hasn't seen the on-off-on transition on the module.

It is very important to understand how IF and IFA work and what their differences are if you are to write XPRESS programs that work as you expect. 

Actions and Assignments

The THEN and ELSE portions of the XPRESS statement may contain any number of actions and assignments. Items must be on separate lines or be separated by semicolons. IF and IFA statements may also be included in this section. IFs and IFAs may be nested in any combination to any number of levels.

Mathematical equations may be used in assignment statements that deal with numbers. Such equations use signed 16-bit integer math operations and support addition (+), subtraction ( - ), multiplication (*), and division (/). Evaluation takes place in strict left-to-right order (contrary to traditional math where multiplication and division have a higher precedence than addition and subtraction), however parentheses may be used to alter the order of evaluation.

The negate operator is not supported, and all constants must be positive. An overflow results in a value of 32767 and an underflow results in - 32768. No errors are generated in over/underflow situations.

An equation must fit on a single line!

The following examples are valid:

Variable(2) = ((ADC(5) * 9) / 5) +32

DAC(3) = 1024 - (Variable(2) * 100)

The first example would evaluate the same way with or without parentheses, but their use often makes an equation more readable and eliminates any possibility of confusion. However, the second example would evaluate differently without the parentheses because of the left-to-right evaluation order used by default.

Note that equations using math may not be used in the IF portion of XPRESS statements. Math is only available when doing assignments. 

Command Summary

The following may appear anywhere in the XPRESS program:

! <comment> <comment> = comment ignored by the compiler

The following commands are used in the configuration section:

Config <module> = n <module> = "PL-Link", "IR-Link", "LCD-Link", "DIO-Link", "ADIO-Link", "DIO+-Link"

n = number of modules connected (0 - 7)

Config SC = <processor> <processor> = "HCS180", "IND180", "SpectraSense"

Config BUF = b b = number of BUFIO or BUF50 boards in system (1 or 2; do not count any BUF-Term boards)

Config IND54 = io,io,io,io io = IN or OUT indicating the direction of each 8255 on the board (there must be four parameters)

Config ADCRES = r r = ADC resolution (only 8, 10, and 12 are valid)

Config ADCGAIN = g0,…g7 gx = gain for each ADC channel (only 1, 2, 4, and 8 are valid; there must be eight parameters)

Define <label> = <string> <label> = any alphanumeric word up to 32 characters long with no spaces

<string> = any valid XPRESS expression

Display Modules = <list> <list> = list of housecodes separated by commas

 

The following commands and system values may be used in both the continuous and the sequential control sections:

ACfailed AC power has failed since the last test

ACpower Current status of AC power (ON/OFF)

ADC(n) n = valid ADC channel (0 - 135)

AllLightsOn(h) h = housecode (A - P)

AllUnitsOff(h) h = housecode (A - P)

CallerID Turn Caller ID support on or off

CIDxxxx Various Caller ID information

ClearLog Clear logged data from memory

ClearTimers Stop and clear all system timers

ClearVariables Clear all system variables to zero

Console="<string>" <string> = ASCII text string; must be surrounded by quotes

DAC(n) n = channel number (0 - 31)

Day Day of month (1 - 31)

Dec(Variable(n)) n = variable number (0 - 127)

DOW Day of week (1 - 7)

Hour Hour of day (0 - 23)

Inc(Variable(n)) n = variable number (0 - 127)

Input(n)=ON/OFF/EDGE n = input number (0 - 207)

IRcode(c) c = received IR code (0 - 255)

LCD(n)="<string>" n = LCD-Link number (0 - 7)

<string> = ASCII text string; must be surrounded by quotes

Log(i) i = reference ID of logged data

LogSize Number of data entries in log memory (0 - 4095)

LPT(n)="<string>" n = DIO-Link number (0 - 7)

<string> = ASCII text string; must be surrounded by quotes

MCIR(n) n = MCIR-Link number (0 - 7)

Minute Minute of hour (0 - 59)

ModemInit Set a new modem initialization string

ModemRings Number of rings to wait to answer modem

Module(m)=ON/OFF m = module (A1 - P16)

Module(m)=DIM(n) m = module (A1 - P16)

n = steps to dim (1 - 31)

Module(m)=BRIGHT(n) m = module (A1 - P16)

n = steps to brighten (1 - 31)

Month Month (1 - 12)

Netbit(n)=ON/OFF n = valid netbit number (0 - 319)

Netbyte(n) n = valid netbyte number (0 - 39)

Network="<string>" <string> = ASCII text string; must be surrounded by quotes

OnHook Put phone on hook (hang up)

Output(n)=ON/OFF n = output number (0 - 207)

Random(n) Generate random number (0 - n)

Refresh PL-Link refresh interval (0 - 99) minutes (0=off)

Reset True after reset

ResetIO Reinitialize all 8255 I/O ports

Rings Number of incoming rings

Say"<string>" <string> = ASCII text string; must be surrounded by quotes

Second Second of minute (0 - 59)

Time <op> hh:mm:dd hh= hour (0 - 23); mm = min (0 - 59); dd = day (SU,MO,TU,WE,TH,FR,SA,DY [daily], WK [weekday], EN [weekend])

Timer(n) n = timer number (0 - 127)

Variable(n) n = variable number (0 - 127)

Year Year (0 - 99)

 

The following commands may be used only in the sequential control section:

CallProgress(n) n = number of rings to allow while following progress of outgoing call

DialDigit(Variable(n)) n = variable number containing the digit to be dialed (0 - 9, 10 [*], 11 [#], 12 - 15 [A - D])

DialNumber(Variable(n),d) n = variable number containing the numbers to be dialed (0 - 9999)

d = number of digits to be dialed (1 - 4)

DialStr("<string>") <string> = text string containing digits to be dialed (0 - 9,*,#,A - D, and comma)

DialTone Check for dial tone

DTMFdigit(t) t = timeout value in tenths of seconds (1 - 255; 0.1 - 25.5 seconds)

DTMFnumber(t) t = timeout value in tenths of seconds (1 - 255; 0.1 - 25.5 seconds)

OffHook Take phone off hook (pick up)

SayW"<string>" <string> = ASCII text string; must be surrounded by quotes

Wait(n) n = suspend time in tenths of a second (1 - 255)

Some expressions and actions require that specific expansion boards or COMM-Link network modules be installed in the system to work properly. These requirements are noted in the detailed descriptions of each statement.


7. XPRESS COMMANDS

This chapter fully describes all XPRESS commands, how they are used, and what they require for hardware. Note also that some work only in the PDFsequential control section.


8. DATA LOGGING

While it is usually pretty easy to set up a control system based on specific events and known environmental conditions, sometimes it's useful to set up one or more sensors, collect data generated by those sensors, and then decide how the control system should work based on the collected data. The collected data may also be used to monitor what happens at the installation while you're away.

Since the Supervisory Controller already has all manner of sensors connected to it, spare memory, a real-time clock/calendar, and some intelligence, it makes a very good data-logging system in addition to a home-control system. Using the Log command (detailed in Chapter 7), single 16-bit values may be stored to memory at any time. A reference ID is attached to the sample to allow data from many different sensors to be logged to the same memory. Separating and sorting of the data is performed at a later time by custom processing software running on the host IBM PC. The current time and date are also saved with the data.

After the SC has been logging data to its memory for a while, you use the Dump command under the Log menu within HOST to dump the data from the SC's memory to a disk file on the PC. The data file is always called LOGDATA.BIN. Be sure to rename an old file before performing a dump if you wish to save the old data. 

Hardware Setup

To perform data logging, an additional 32K static RAM chip must be installed on the Supervisory Controller.

Before doing anything, turn off the power to the SC. Install a standard 62256 (or equivalent) chip in socket U10 on the SC (it is the empty 28-pin socket between the EPROM and existing RAM chip). On the SpectraSense, install the chip in socket U14. Be sure to orient the chip in the same way as the other memory chips on either side of it. Plugging the chip in backwards will destroy the chip and could damage other components on the board.

Next, verify that the two jumpers on JP6 (next to the new RAM chip) are installed between pins 2 & 3 and pins 4 & 5. Pin 1 of JP6 (the pin closest to the EPROM) should be left open. No jumpers need to be set on the SpectraSense

If you want the log memory to remain intact through a power outage, you'll need to use either a battery-backed RAM or a module that backs up a RAM chip plugged in on top of it (such as the Dallas Semiconductor DS1210 module). If you have any questions about what kind of RAM chip will work in the socket or about how to battery back the memory, contact Circuit Cellar.

When the RAM is installed and the jumpers are set, you may turn the power back on and try data logging. 

Software Setup

The first step that must be performed before logging any data is to clear the memory. Log memory may be cleared in one of two ways: from HOST or from within your XPRESS program.

While in HOST, selecting Clear from the Log menu clears the log memory. Clearing log memory from HOST may be done at any time. You may also embed a ClearLog command within your XPRESS program (see Chapter 7 for more details). Whenever the command is encountered, the log memory is cleared. The command is most often placed at the top of the program and is run as a result of the Reset condition (see Chapter 7). The only potential drawback of clearing log memory on reset is your data is cleared any time you load a new program or the power is lost and restored. If you prefer to have more control over when memory is cleared, stick with HOST's Clear command.

Once the log memory has been cleared, you may start logging data values to memory. Each time a value is saved with the Log command, a 16-bit value, a reference ID number, and the current time and date are saved (for a total of eight bytes). The purpose of the reference ID number becomes clear when you start planning what you want to log.

If data values were saved to memory without IDs, you would be limited to storing data from just one kind of sensor. Otherwise, you wouldn't know which sensor had generated the data. By storing data in memory sequentially with IDs attached to each value, you may sort the data by IDs at a later time. The examples presented later in this section clarify the concepts further.

Up to 4096 samples may be stored in memory at any given time (32768 bytes of RAM divided by 8 bytes per sample). When you reach the end of memory, new samples begin to overwrite the oldest samples, so when you dump the data to a disk file, you end up with the last 4096 samples stored.

When you decide to retrieve the data from the SC's memory, select the Dump command from the Log menu within HOST. The data is stored in a disk file called LOGDATA.BIN on the PC. Be aware that 32K of data transferred from the SC to the PC at 9600 bps takes up to 35 seconds to complete. Be patient. 

What to Log

There are many situations where the time stamp saved with the logged data is more useful to you than the actual data stored. For example, if you want to log the fact that a motion sensor was tripped or a door was opened, simply log a 0 with a reference ID that is unique to the motion sensor or door sensor. When you later process the logged data, you can ignore the data that was saved and associate the reference ID with the time and date saved. Take the following example:

    DEFINE Temp      = 0
    DEFINE Motion    = 1
    DEFINE FrontDoor = 2

    BEGIN
      IF Reset THEN
        ClearLog
        Timer(70) = ON
      END

      IF Timer(70)>=30 THEN
        Log(Temp) = ADC(2)
        Timer(70) = ON
      END

      IF Input(2)=ON THEN
        Log(Motion) = 0
      END

      IF Input(5)=ON THEN
        Log(Frontdoor) = 0
      END
    !!! End BEGIN
    

In the first Log statement, the value of the temperature sensor is stored every 30 minutes. In this case, you use reference ID 0 to find the temperature data in the file, then associate the actual temperature read with the time and date of when it was logged.

In the second two Log statements, you are only interested in when the sensors were tripped, not the value saved. Search the data file for reference IDs of 1, and you'll know every time that the motion sensor was tripped. Search for IDs of 2, and you'll know when the door was opened. 

Logged Data Format

Each logged data sample is stored in the LOGDATA.BIN file as follows:


    Byte 0: Reference ID number (0 - 254)
    Byte 1: Low byte of data    (0 - 255)
    Byte 2: High byte of data   (0 - 255)
    Byte 3: Month logged        (1 -  12)
    Byte 4: Day logged          (1 -  31)
    Byte 5: Hour logged         (0 -  23)
    Byte 6: Minute logged       (0 -  59)
    Byte 7: Second logged       (0 -  59)

All values are in binary. This file may not simply be typed to the screen. It consists of primarily unprintable binary characters and must be further processed on the PC by custom software to be useful. The following section contains some sample processing code written in C to give you an idea of what's necessary. 

Sample Processing Software

The following C program (included on the distribution disk in both source and executable form) may be used to process data logged by the Supervisory Controller and dumped to disk. Feel free to modify the code to fit your needs. It is written in Turbo C, but should work with most C compilers.

When run, the sample code reads the LOGDATA.BIN file (or another file you specify on the command line) and generates a report to the screen with the data grouped by reference ID numbers. The data value, date, and time are displayed, one record per line. You may redirect the output to a file or the printer for a permanent, readable record.

To process the data in the file called MYDATA.BIN, use the command:

PROCESS MYDATA REM

To process the data in LOGDATA.BIN and send it to a file called LOG.TXT, use the command:

PROCESS >LOG.TXT

To process the data in the file called WEEKLY.RAW and send it to the printer, use the command:

PROCESS WEEKLY.RAW >PRN


    #include <stdio.h>
    #include <stdlib.h>

    #define false 0
    #define true  1

    FILE *fp

    unsigned char *logdata;
    unsigned int len=0;

    unsigned int
    ReadData(char *input) {
      unsigned int i=0;

      if ((fp=fopen(input, "rb")) == NULL) {
          printf("\nError opening %s\n", input);
          fclose(fp);
          return 1;
      }

      logdata = malloc(32768);

      if (!logdata) {
          printf("\nError allocating memory.\n");
          fclose(fp);
          return 1;
      }

      while (!feof(fp)) {
          logdata[i++] = getc(fp);
          len++;
      }

      fclose(fp);

      return 0;
    }

    void
    ProcessData(void) {
        unsigned int id, record, id_header;
        for (id=0; id<=254; id++) {
            id_header = false;

            for (record=0; record<len; record+=8) {
                if (logdata[record]==id) {
                    if (!id_header) {
                      printf("\nID = %u\n", id);
                      id_header = true;
                    }
                    printf(" % 5i %02i/%02i, %02i:%02i:%02i\n",
                    logdata[record+1]+(logdata[record+2]*256),
                    logdata[record+3], logdata[record+4],
                    logdata[record+5], logdata[record+6],
                    logdata[record+7]);
                }
            }
        }
        printf("\n");
    }

    main(int argc, char *argv[]) {
        char *file, name[16];
        unsigned int err=0;
        file = name;

        if (argc < 2) {
            err = ReadData("LOGDATA.BIN");
        } else {
            if (strchr(argv[1],'.')) {
                err = ReadData(argv[1]);
            } else {
                strcpy(file, argv[1]);
                strcat(file, ".BIN");
                err = ReadData(file);
            }
        }

        if (!err) {
            ProcessData();
        }

        return 0;
    }
    

Legal

Circuit Cellar Inc. warrants the media on which XPRESS is delivered against physical defects for 60 days after the date of purchase.

Circuit Cellar will not be held responsible for any damages caused by use or misuse of XPRESS and the HCS II. Circuit Cellar provides XPRESS with the understanding that the user will determine its fitness for any particular application and Circuit Cellar specifically disclaims any implied warranties.

While we have attempted to provide accurate and up-to-date information in this manual, Circuit Cellar makes no representations or warranties respecting its contents. We reserve the right to make periodic changes to the text and to issue new editions of this manual without notice.

Occasionally in this manual we refer to the products of manufacturers other than ourselves. Such references do not constitute an endorsement of these products, but are included for the purpose of illustration or clarification. We do not intend such technical information to supersede information provided by the individual manufacturers. All trademarks referenced are the property of the respective trademark owners.

COMM-Link, PL-Link, IR-Link, MCIR-Link, LCD-Link, DIO-Link, DIO+-Link, ADIO-Link, Supervisory Controller, XPRESS, HCS II, and SpectraSense are trademarks of Circuit Cellar Inc.

XPRESS and this manual are copyright © 1992 - 2012 , Circuit Cellar, Inc.

All Rights Reserved