Some examples PDF Print E-mail
Written by Carl Friis-Hansen   
Saturday, 18 October 2008 08:50

Example

Let's say counter0 located at FIO3, then it's reset command name would be RCT0.
In case of counter1 it would be RCT1.
If we would like to reset the counter0 when logic input CIO1 goes lo/off/false and analog input FIO1 goes above 1.8V and counter is full (500), then the following lines would do to set up this functionality:

u3Base u3b(1);
 
u3b.buildInputCommandAIN( ”FIO1”, 1.0, 0.0, 1.8, ”FIO1 Analog input” );
 
u3b.buildInputCommandDIN( ”CIO1”, ”Enable counter reset”, ”Block counter reset” );
u3b.buildInputCommandCNT( ”FIO3”, 0, 500, ”Counter0 is full by a count of 500);
 
u3b.logicTableAdd( ”RCT0”, ”!CIO1 * FIH1 * FIO3” );

Description

Line 1:  makes an instance of the u3Base class for LabJack device number one.
Line 2:  Make analog input FIO1 with scaling factor 1.0 and min trigger 0.0V and max trigger 1.8V.
Line 3:  Make logic input CIO1 and assign the first text with low state and second text with high.
Line 4:  Make counter0 at FIO3 and reset to 0 and claim full at 500 counts.
Line 5:  Reset counter0 when input CIO1 is LO, and input FIO1 is over 1.8V and counter0 is full.

I have no idea what it can be used for, but it illustrates how easy it is to define very complex functions in just a few lines of code.  The above example also illustrates how the logic tables incorporates analog, logic and counters into a functional whole.  The logic equations could be subjected to Queen McCluskey reduction, Karnaugh Maps and various hazard check before the system is going live.

 

The main loop

It is assumed checkAllInputs() method is called repeatedly, for example at an interval of one eights second.  In multi-threaded applications it is important to wait, until the return value of the method is received, before any other methods in u3Base or any contact to the U3 device are made.  During the execution of checkAllInputs all inputs, defined by the buildInputCommand... methods, are read and modified.  After this eventual conversion tables are processed and finally the Boolean expressions from any logTableAdd definitions is processed.  The process of logTables results in logic outputs being stimulated in the same sequence as they are defined with the method logTableAdd.
One of the big questions is how often one would call checkAllInputs?  If the LabJack U3 is used for surveillance, regulation of environment and processes of a fairly slow nature, then a cal every second would probably do very fine.  However, in case of a feeding machine, a roller coaster or other machinery that needs fast reaction, then a call every 20msec or less is likely to be needed. Below is an example where method checkAllInputs is called every 125msec and printing to terminal is done every 2sec:

while( !kbhit() ) {
 
count++;
 
u3b.checkAllInputs(); // every 1/8 second
 
if( (count & 0x0F) == 0 ) {
// various printing to terminal or other process every 2 seconds
}
usleep( 125 * 1000 ); // 1/8 sec
 
}
.

 

Last Updated on Wednesday, 26 May 2010 09:16
 

Add comment

To be able to vote and have easier access to write comments, etc., go to Login and register yourself.
Your user name and email will never leave this website.


Security code
Refresh