Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 15 Extending DAQFactory > 15.2 User Devices

15.2.2 Creating your own device

Scroll Prev Top Next More

To create your own device, go to the Device Configuration window by selecting Quick - Device Configuration from the main menu.  In addition to the standard DAQFactory devices, you will see New User Device listed.  Click on this and hit Select.  This will open the User Device Configuration window.  The first thing to do is name your device.  Like all DAQFactory names, your device name needs to start with a letter and contain only letters, numbers or the underscore.  You'll also need to specify a filename to save your device to.  User devices are not stored with your document, but rather are written to a text file.  This way, you can use your device in multiple documents and even share it with colleagues.  In order for DAQFactory to recognize is as a device, you'll need to make sure it is in your DAQFactory directory and that the file name ends in ".dds".  Note that the DAQFactory directory is, by default, read-only, so while you are creating your device you will need to go into Windows and set it as read/write.  When done, we strongly suggest setting it back to read only so that a potential hacker can't change your code.

A device consists of collection of I/O Types and functions.  You can use either or both.  I/O types apply to channels, while functions are accessible from sequences.  Both consist of sequence script.  We recommend coding your device using regular sequences so you can take advantage of the debugger and then transferring tested code into your device.

I/O Types:

Each I/O type that you create will have a sequence script associated with it.  This script will take the device number, channel number and other information and return a value (for inputs) or set a value (for outputs).  In the User Device Configuration window you can add new I/O Types to your device by clicking on the Add I/O type button at the bottom.  A new window will appear asking about your I/O type.  You'll first need to specify the I/O type name.  The I/O Type is one of the few places where you can use spaces and other special characters in the name.  You'll also need to provide a unique number for your I/O Type.  Internally, I/O types are tracked by number.  It doesn't matter what this number is, as long as it is a positive integer less than 2^32.  Finally you'll need to specify whether the I/O type is an input or output, and whether the data will be numeric or a string.

Once you've added a new I/O type it will appear in the list along the left.  If you click on the I/O type, the script for this type will appear to the right.  Initially, of course, it will be blank.  Here you can put in whatever sequence code you need to read or write your values.  Remember, though, that this code executes often, so long loops or delays are not recommended.  The following private variables are available to you:

DeviceNumber - the device number of the channel

Channel - the channel number of the channel

Specifier - the quick note / opc specifier for the channel

SetToValue - the value to set to (output I/O types)

strSetToValue - same as above, but the string version

OriginalValue - the pre-converted value to set to.  Return this for output I/O types.

strOriginalValue - same as above, but the string version

ChannelName - the name of the channel

For input I/O types, you'll want to return the value read at the end of your script.  If you don't have a value to return, for example in the case of an error, just return nothing: return.  For output I/O types you will typically want to return OriginalValue to confirm that the output was set, or again, nothing if the value could not be set.

Functions:

Device functions are typically called from sequences.  To create a new function, click on the Add Function button at the bottom of the window.  You will then be prompted for a function name, which like all other names in DAQFactory, must start with a letter, and contain only letters, numbers or the underscore.  Like I/O types, a function is simply sequence code.  The arguments passed to the function are just like a sequence used as a function and named arg0, arg1, etc. for each subsequent argument, and prefixed with 'str', i.e. strarg0, when a string is passed.  You can optionally return a value as well.

There are two types of functions, Public and Private, which is selected at the top right above the code.  A public function is visible from anywhere in DAQFactory and typically accessed by Device.MyFunction() notation.  A private function is actually available from anywhere, but does not appear in any drop downs when entering code, so is not really visible.  Private functions are typically used solely by other functions or I/O types of this device.

OnLoad / OnUnload:

In addition to the I/O types that you add, there are two events that exist with every user device and will appear in the I/O type list from the beginning. OnLoad is called once before any of your I/O type code and allows you to put initialization code.  This is a great place to put extern() statements and other initialization. OnUnload is called when you quit DAQFactory or when you start a new document or open an existing document.  Use this event for any shutdown code.  Note that for every OnLoad called, OnUnload will be called once as well.  To edit these events, simply click on them in the I/O type list.

Note: you cannot remove an I/O type or function from within DAQFactory.  To do this, you will need to quit DAQFactory, open the .dds file you specified and remove the I/O type or function and associated code from there.