Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 6 Channels and Conversions

6.13 Disabling a Device with Bypass

Scroll Prev Top Next More

There are times when you may be testing your software and not have all your hardware, or a piece of hardware is simply out for repair and you'd like to run your program without the constant alerts telling you DAQFactory couldn't communicate with the device.  There are also times when you'd like to run a simulation of inputs instead of using the real inputs.  For these cases, there is the Bypass feature.  The bypass feature allows you, on a device by device basis, to skip calling the device or communication drivers and instead call script.  

The bypass feature consists of two member functions of device types and a system event.  To bypass a device use the SetBypass() function:

device.myDevice.setBypass([Device Number])

where myDevice is the name of the device as you see in the Device Type column of the Channel table. Device Number is an optional value that allows you to disable just one particular piece of hardware for a device type.  For example, let's say you have created a Modbus device connection called "MyMod" and it is an RS485 multidrop with 3 PLC's with Modbus ID's 1, 2 and 3.  ID #2 died and you want to bypass it.  So you would put:

 

device.myMod.setBypass(2)

If you don't specify the device number, then all device numbers for that device type are bypassed.

You can call the function multiple times to disable multiple devices for a particular device type or across different device types.  So, continuing the last example, if ID #3 also died and you wanted to only read ID 1, you would do:

 

device.myMod.setBypass(2)

device.myMod.setBypass(3)

To cancel bypassing for a particular device type, use ClearBypass():

device.myMod.clearBypass()

This would clear all bypass instructions for the device type.  This function does not take any parameters and affects all device numbers on the specified device type.

Note: the Bypass feature only affects channels.  It will not affect device functions that read / write to the device.  So, device.myMod.readHoldingU16(2, 0, 1) would not be bypassed in the above example.

If all you needed to do was disable a device, the above functions are all you need.  But for more control there is the OnBypass system event.  If you create a sequence called OnBypass, the sequence will be called every time DAQFactory needs to read or write a channel that would otherwise be bypassed.  The function is passed the following parameters:

function OnByPass(DeviceName, DeviceNumber, ChannelName, SetValue)

SetValue is only passed if the channel is being written to, and it receives the unconverted output value.

With this information you can then manually insert values into your channels and thus create a simulation.  You also have finer control over what gets bypassed.  If you return(0) in the OnBypass sequence, then the channel will not be bypassed.  So, continuing our example, if we had a channel called "MyInput" one device number 2 of our myMod device that we wanted to read even if the rest of the device was bypassed, we could put this in OnBypass:

 

if (ChannelName == "MyInput")

   return(0)

endif

Returning any non-zero value, or simply not calling return() in OnBypass results in the channel being bypassed.

Creating a simulation:

As mentioned, you can use the bypass feature to create a simulation mode for your application for when there is no hardware available.  This is great for testing, or for demonstrations.  How this is implemented depends quite a bit on your application and there is a lot of ways to do it, but here are a few tips:

1) use startup flags, or a persistent setting to determine if you are in Sim mode or not.  Don't hard code it, otherwise you'll forget to set it back to non-sim mode when you ship

2) At the least, you probably want this script in OnBypass:

 

if (!isEmpty(setValue))

   execute(channelName + ".addValue(setValue)")

endif

return(1)

This will cause any output commands to put the output value into the channel for you, even if the actual output is bypassed.  

3) You can also put your simulation code for inputs in OnBypass, but its usually better to create a separate sequence that runs when you are in your sim mode that loops at some interval and stuffs new values into your input channels based on the values of output channels.  Use AddValue() to stuff the values into the channels.