BusWorks Model XT1531‐000
4 CH Current 4 CH Digital I/O w/USB & Modbus
Acromag, Inc. Tel: 248‐295‐0880
‐
42
‐
Example Code (w/Coil Registers Disabled)
The example code that follows is used with Coil Registers Disabled. With coil registers disabled, the digital I/O channels of
this model are only addressed four channels at a time. Thus, when writing a specific output, you need to first retrieve the
current output states for the group, or refer to a stored record of the current output states for the group, in order to
implement a masking strategy to prevent adjacent channels of the group from being toggled.
To do this, first get the current output settings by reading the Holding registers, or reading the RAM variable where the
current settings have been saved. Then, to write specific output(s) of the group, clear the outputs of any adjacent field
input channels (to keep them turned OFF). Then use a bitmask and either OR the current setting with 1 to turn the output
ON, or AND the current setting with 0 to turn the output OFF, as required and in the specific bit position(s) that
correspond to the output channel(s) to be changed. One example for accomplishing this follows:
//////////////////////////////////////////////////////////////////////////////////////////
//
//
// The software contained here is provided only as a guide with the aim of
//
// saving time when writing their own code to control the XT1111 or XT1121
//
// modules from Acromag. As such, Acromag Inc. shall not be held liable for
//
// any direct, indirect or consequential damages with respect to any claims
//
// arising from the content of such software and/or the use made by customers
//
// of the coding information contained herein in connection with their products. //
// Code is suppled untested with no warranty of any kind.
//
//
//
// COPYRIGHT 2014 Acromag Inc.
//
////////////////////////////////////////////////////////////////////////////////////////
#define OFF 0
#define ON 1
#define FIRST_DO_HADDRESS 40001
unsigned word OutputWord[4] = {0, 0, 0, 0}; // declare this in the associated .h file or make it a global and be
sure to initialize all 4 elements to 0