CoachLabII+ element
EJS Element for CoachLab II+, a multifunctional interface for computerized measurement and control.
Important notice: Currently, the element only works under the Windows operating system.
Usage
To add a CoachLabII+ element to your model, simply drag the icon element to the list of your model elements.
In your model, call the element reset() method before any other method of the interface.
Before running the simulation, though, make sure that:
- the CoachLab II+ interface is connected to the computer on one if its USB ports,
- you have installed the CoachLab II+ driver (use the CD included in the CoachLab II+ box),
- you copy the DLL for your operating system anywhere in the java.library.path list of directories.
(The DLLs can be found in the EJS bin/extension/DLLs directory.)
Under windows, rename the rxtxSerialXX.dll (XX=32 for a 32 bits Windows, 64 for a 64 bits Windows) to just rxtxSerial.dll,
and copy it, for instance, to C:\Windows\System32.
The Mac OS X DLL is not working right now.
Configuration methods
- void reset(). Reset the interface at the default communication speed (833333 bd)
- void reset(int rate). Reset the interface at a given communication speed. Default is 300 (= 833333 bd)
- void reboot(). Soft power-on reset of the interface
- void stop(). Stop data communication to the port
- void resetInitialTime(). Set the initial time. This is needed so that values read in sequence bear the correct time stamp
- void dispose(). Free the communication channel on exit
Input methods
The following input methods require a channel (int in the range 1-4) and a sensor int value.
The list of sensors currently supported is the following:
(Use the integer number or the constant with the prefix es.uhu.serial.coach.CoachLabIIPlus, as in es.uhu.ejs.serial.CoachLabIIPlus.SENSOR_THERMOCOUPLE_0135i_m20_M110C)
- 0 : SENSOR_ADC_OUTPUT
- 1 : SENSOR_GENERIC_SENSOR_m10M10V : Generic value in the range (-10 +10V)
- 2 : SENSOR_GENERIC_SENSOR_05V
- 10 : SENSOR_THERMOCOUPLE_0135i_m20_M110C : Temperature in the range (-20°C +110°C)
- 12 : SENSOR_THERMOCOUPLE_0135i_m200_M1300C : Temperature in the range (-200°C +1300°C)
- 20 : SENSOR_FORCE_0663i_mM5N : Force in the range (-5N +5N)
- 22 : SENSOR_FORCE_0663i_mM50N : Force in the range (-50N +50N)
- 30 : SENSOR_MAGNETIC_FIELD_024i_m10M50mT : Magnetic field in the range (-10mT +50mT)
- 32 : SENSOR_MAGNETIC_FIELD_024i_m100M500mT : Magnetic field in the range (-100mT +500mT)
- 41 : SENSOR_CURRENT_m500M500mA : Current in the range (-500mA +500mA)
- 51 : SENSOR_DIFFERENTIAL_VOLTAGE_m10M10V : Voltage in the range (-10V +10V)
The list of input methods is:
- double readValue (int channel, int sensorType).
Read an analog channel (single reading).
Returns the Normalized value of the measurement (V, N, A, mT...) or Double.NaN if failed to read
- setTrigger (int channel, int sensorType, double level, boolean goingUp, int hysteresis, String methodName).
Configure trigger options for subsequent reading of sequences of data (histeresis in the range 0 - 127).
When the signal reaches the trigger level, a sequence of data will be read. The object can wait in the background until the data is ready,
and then invoke the given method of the simulation.
When the signal reaches the trigger level, a sequence of data will be read. When the data is ready, the program tries to set to true the value of a boolean variable
or call a public custom method (with no parameters) of the simulation. If no notification String is provided, the program waits until the data is ready.
- readSequence(int channel, int sensorType, int nPoints, double totalTime).
Reads one sequence of data from a single channel. If successful, the data can be obtained using:
- double[] getSampledTimes() : sampled times
- double[] getSampledData(0) : sampled data
Returns true if successful, false otherwise.
- readSequence(int[] channels, int[] sensors, int nPoints, double totalTime).
Reads one sequence of data from the given channels (up to four channels in the range 1-4). If successful, the data can be obtained using:
- double[] getSampledTimes() : sampled times
- double[] getSampledData(i) : sampled data on the i-th channel (from 0 to 3)
Returns true if successful, false otherwise.
Output methods
The following output methods require a channel parameter which must be one of A1,A2,B1,B2,C1,C2,D1,D2:
- void setOutputEnabled(String channel, boolean enabled). Enable/Disable one of the output channels
- boolean setOutputMaskEnabled(int mask, boolean enabled). Enable several outputs at once.
The mask is taken a a series of 0s and 1s, one for each of the outputs, in the same order as listed above.
Outputs which correspond to a '1' in the mask are set.
Outputs corresponding to a '0' in the mask will remain unchanged.
Returns true if successful (the mask is in the range 0-255), false otherwise.
- int getOutputStatus(). Return a number between 0 and 255 with the current status of all the outputs.
- boolean setSwitch(String channel, boolean on). Turn on/of the switch module on the given channel.
Returns true if successful (correct channel), false otherwise.
- boolean setPWM(String channel, int level). Set the PWM output level for a given channel.
Outputs are dutycycled with a frecuency of 625 Hz in 16 levels (0-15).
Returns true if successful (correct channel), false otherwise.
- boolean setAllOutputsEnabledTemporarily(String lastChannel, double time).
Enables all outputs up to (and including) the given channel for a given period of time.
Returns true if successful (correct channel), false otherwise.
More info
A JavaDoc format description of the methods can be found at CoachLabII+.
Example of input
(Connect the temperature sensor to the input channel "1>" on the interface.)
coachLab.reset();
double temperature = coachLab.readValue(1,10); // 10 is the temperature sensor in the range -20 +110 ¼C
_println ("Temperature = "+temperature);
Example of output
(Connect the switch module (D063) to A1 and A2 on the interface.)
coachLab.reset();
coachLab.setOutputEnabled("A1",true);
coachLab.setOutputEnabled("A2",true);
coachLab.setSwitch("A1",true); // whatever is connected to the switch will power on