| Some examples |
|
|
|
| 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 if full (500), then the following lines could be part of the program: u3Base u3b(””); 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 * FIH3 * FIO3” );
Description It is the thought that checkAllInputs() method should be called repeatedly for example at an interval of one 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, if 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 }
To the project page.
|
|
| Last Updated ( Saturday, 18 October 2008 09:38 ) |