The CFLink namespace provides access to classes and methods related to CommandFusion's CFLink bus devices. It encapsulates all the classes, functions and definitions you need to work with CommandFusion hardware devices.

If you are looking for a starting point, you can obtain JavaScript objects to communicate with devices on the CFLink bus via the CFLink.getDevices and CFLink.getDevice functions.
Classes
CFMini
Interface to CFMini devices
Device
Base class for other device objects
DINMOD4
Interface to DIN-MOD4 devices
IOPort
Represents one I/O port of a CFLink device or module. Do not use directly.
IRBlaster
Interface to IRBlaster devices
LANBridge
Interface to a LAN Bridge device
LEDPort
Do not use directly
Module
Represents a module inserted in a DIN-MOD4 or MOD4 device
RelayPort
Do not use directly
RS232Port
Do not use directly
SW16
Interface to a SW16 device
Members

<static> deviceRegistry

A registry of CFLink devices. Each key is the device serial number. Individual modules (modules for DIN-MOD4 and MOD4) are not listed in this registry. Keys in this registry are device serial numbers. For topology discovery, you can check the cflinkNetworks property which allows you to determine on which CFLink network a device is connected (for example, there may be several LANBridge devices providing multiple network accesses to the same group of interconnected CFLink devices, but there can be several such groups not interconnected, and with CFLink device IDs overlapping those on the other network)

<static> model

Constants for known CommandFusion hardware models (devices and modules)
Name Value Description
LANBridge LANBridge a CommandFusion LANBridge device
DINMOD4 DIN-MOD4 a CommandFusion DIN-MOD4 device
MOD4 MOD4 a CommandFusion MOD4 device
CFMini CFMini a CommandFusion CFMini device
SW16 SW16 a CommandFusion SW16 device
IRBlaster IRBlaster a CommandFusion IRBlaster device
HRY2 MOD-HRY2 HRY2 module: 2 x 250VAC 15A latching (polarized) relays
RY4 MOD-RY4 RY4 module: 4 x 250VAC 5A non-latching normally-open relays
LRY8 MOD-LRY8 LRY8: 8 x 30VDC 1A latching (polarized) relays
SSRY4 MOD-SSRY4 SSRY4: 4 x 250VAC 2A non-latching normally-open solid-state relays
IO8 MOD-IO8 IO8: 8 x configurable I/O - dry contact, voltage reading, resistance reading, LED output, video sensing, voltrage trigger
IR8 MOD-IR8 IR8: 8 x IR outputs
COM4 MOD-COM4 COM4: 2-4 x configurable RS232/422/485 bi-directional serial ports
Methods
<static> addDeviceToRegistry ( device )
Parameters:
Name Type Description
device CFLink.Device the device object to add to the registry
Returns
true if the device was added to the list, false if it was already in it
Type
Boolean
Add a device to the device registry, if it wasn't already in it. It may already be there if there are several LANBridge devices on the same network and we perform the discovery process on all of them. This method is also internally used when creating devices manually from a predefined list.
<static> attachReplyCallbackByCFLinkID ( id , callback , me )
Parameters:
Name Type Description
id String The ID of the target device ('02' - 'EF', 'FF')
callback Function The function to call when the regex matches
me Object the object to set as `this' when your callback function is executed
Attach a new callback for replies based on regex match from device ID
<static> attachReplyCallbackByCommand ( command , callback , me )
Parameters:
Name Type Description
command String the command to craft the regex for (i.e. "TRLYSET")
callback Function a function to call when the regex is matched
me Object the object to set as `this' when your callback function is called.
Attach a new callback for replies based on regex match of a specific command type
<static> buildMsg ( systemName , cflinkID , commandType , target , command , payload )
Parameters:
Name Type Description
systemName String name of the remote system (in iViewer GUI) to send the command to. Pass null to not send the command right away (simply return the assembled packet)
cflinkID String ID of device to talk to ("02" to "EF", "FF" for broadcast)
commandType String type of command to send: "Q"=query, "C"=configure, "T"=transmit
target String the 3-char name of the target (i.e. "LAN", "IOX" for I/O module, etc)
command String the 3-char name of the command
payload String the command data payload
Returns
the complete constructed CFLink packet
Type
String
Build a valid CFLink packet and optionally send it.
<static> buildNetworkRegistry ( )
Call this function when the discovery is complete, so as to prepare the network registry based on the data gathered and effectively generate a view of the network topology
<static> getDevice ( systemName , deviceModel , cflinkID , modules )
Parameters:
Name Type Description
systemName String name of the iViewer network system we use to send CFLink messages (to a LANBridge on the same CFLink bus as the target device)
deviceModel String model of the device
cflinkID String the CFLink device ID ("02" to "FE")
modules Array this parameter is optional. When creating a MOD4 or DIN-MOD4 you can specify which modules are present. See CFLink.getDevices function for an example.
Obtain the JavaScript object representing a CFLink device. We identify the device by its model (i.e. CFLink.model.CFMini), CFLink ID and name of network system iViewer uses to send its messages. If the device does not exist yet (has not been discovered by automatic discovery, or has never been used), its object is created, added to the registry and will remain there for as long as CFLink.initializeDeviceRegistry is not called.
<static> getDeviceBySerialNumber ( serialNumber )
Parameters:
Name Type Description
serialNumber string the CF device serial number
Returns
the CFLink.Device object
Type
CFLink.Device
Obtain the JS object representing a CFLink device, based on its serial number
<static> getDeviceForModule ( moduleObject )
Parameters:
Name Type Description
moduleObject CFLink.Module the JavaScript object representing this module
Returns
a CFLink.Device object (typically a CFLink.DINMOD4 object)
Obtain the CFLink.Device object that contains the module that itself contains the given port object
<static> getDeviceForModulePort ( portObject )
Parameters:
Name Type Description
portObject CFLink.IOPort the JavaScript object for the port (i.e. a CFLink.IOPort object, etc).
Obtain the CFLink.Device object that contains the module that itself contains the given port object
<static> getDevices ( devices )
Parameters:
Name Type Description
devices object
Return type
object
Obtain a number of CFLink devices. On input, pass an object whose properties are names for devices, and values are objects defining the type of device to control. Each device will be added to our registry (no discovery needed) and on return, an object mapping names and JavaScript objects (CFLinkDevice instances) will be returned. The object describing each device should have at least two properies: an `id' property (String) that is the CFLink ID of the devce, and a `type' property that is the CFLink.model of the device. When obtaining a DIN-MOD4 or MOD4 device, you can optionally specify the list of modules that are currently inserted in the device, so as to being able to access the modules right away without having to wait for the device information to come back on the CFLink bus (every time you obtain a device that has not been previously obtained, a query is sent on the CFLink bus to obtain configuration information about the device).
Example
var devices = CFLink.getDevices({
  mini1: {
    id: "04",
    type: CFLink.model.CFMini
  },
  mini2: {
    id: "05",
    type: CFLink.model.CFMini
  },
  keypad: {
    id: "3E",
    type: CFLink.model.SW16
  },
  bay: {
    id: "2B",
    type: CFLink.model.DINMOD4,
    // array of modules in slots 1, 2, 3, 4. null if no module present.
    modules: [ CFLink.model.IO8, CFLink.model.SSRY4, CFLink.model.HRY2, null ]
  }
}, "CFLINK_SYSTEM");

// now we can talk to the devices

// pulse relay #3 for 0.5 second
devices.mini1.pulseRelayState(3, 5);

// blink keypad digits (LEDs 0 to 9)
var digits = [0,1,2,3,4,5,6,7,8,9];
devices.keypad.blinkLED(digits, 0, 100, 5, 3, 0);

// be notified of digit presses
devices.keypad.watchContacts(digits, function(keypad, digit, state) {
  // we are called when one of the digits 0-9 is pressed,
  //	and again when it is released
  if (state == 1) {
    CF.log("Keypad digit " + digit + " was pressed");
  } else {
    CF.log("Keypad digit " + digit + " was released");
  }
});
<static> initializeDeviceRegistry ( )
Call this method at the beginning of the discovery process, or when starting a new discovery. Note that as soon as you have called this methods, all objects that were in use from a previous discovery will stop having their data callbacks called, as we remove them from our attachment list. If you need to keep these objects around for any reason, make sure you make a copy of the deviceRegistry first.
<static> interceptNetworkDialog ( )
A function you can set that intercepts all inbound and outbound CFLink messages (ie to log traffic). Your function should be: function(incoming,systemName,data) where `incoming' is true for received data and false for sent data, systemName is the name of the external system defined in iViewer, and data is the raw data received. You can further parse the data using CFLink.baseCFLinkRegex for your display purposes
<static> removeCallbackByCFLinkID ( id )
Parameters:
Name Type Description
id String The ID of the target device ('02' - 'EF', 'FF')
Remove an attached callback based on its CFLink ID
<static> removeCallbackByCommand ( command )
Parameters:
Name Type Description
command String The Command to remove the callback for
Remove an attached callback based on its Command
<static> removeCallbacksByDevice ( device )
Parameters:
Name Type Description
device CFLink.Device
Remove all callbacks for a specific device
<static> unwatch ( watcherID )
Parameters:
Name Type Description
watcherID Number the watcher ID originally returned by CFLink.watch().
Stop watching a CFLink event. Use the watcherID returned by CFLink.watch() to identify the event watcher to remove
<static> watch ( event , sender , callback , me )
Parameters:
Name Type Description
event String the event to watch (i.e. CFLink.SW16.DRY_CONTACT_CHANGE)
sender Object filter on events from a specific CFLink object. Pass null to watch the same event emitted by all CFLink objects
callback Function your callback function. Parameters are specific to each event, the first two parameters are always the CFLink object and the event name
me Object the object to set as the 'this' object when calling your callback function
Returns
an event watcher ID you can use to stop watching this event by calling CFLink.unwatch()
Type
Number
Start watching events emitted by CFLink devices. The order in which registered objects will receive a fire notification through their registered callback is the following: First, those watching a specific CFLink object will receive the notification, in the order their registered. Second, those watching any CFLink object (registered using a null sender object) will receive the notification, in the order their registered.