Skip to content

Commit e89a191

Browse files
committed
ExperimentConfig supports initialReadDelay option set by device
- LabPro requires an initial delay before reading experiment data
1 parent 66a2ff8 commit e89a191

File tree

6 files changed

+86
-12
lines changed

6 files changed

+86
-12
lines changed

sensor-native/src/swig/java/ccsd/pseudo/ExperimentConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ExperimentConfig implements
3737
{
3838
private long swigCPtr;
3939
protected boolean swigCMemOwn;
40+
private int initialReadDelayMillis;
4041

4142
protected ExperimentConfig(long cPtr, boolean cMemoryOwn) {
4243
swigCMemOwn = cMemoryOwn;
@@ -69,6 +70,16 @@ public boolean getExactPeriod()
6970
return getExactPeriodUChar() == 1;
7071
}
7172

73+
public int getInitialReadDelay()
74+
{
75+
return initialReadDelayMillis;
76+
}
77+
78+
public void setInitialReadDelay(int initialReadDelayMillis)
79+
{
80+
this.initialReadDelayMillis = initialReadDelayMillis;
81+
}
82+
7283
public org.concord.sensor.SensorConfig [] getSensorConfigs()
7384
{
7485
int num = getNumSensorConfigs();

sensor-native/src/swig/java/ccsd/ti/ExperimentConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ExperimentConfig implements
3737
{
3838
private long swigCPtr;
3939
protected boolean swigCMemOwn;
40+
private int initialReadDelayMillis;
4041

4142
protected ExperimentConfig(long cPtr, boolean cMemoryOwn) {
4243
swigCMemOwn = cMemoryOwn;
@@ -136,6 +137,16 @@ public String getDeviceName() {
136137
return NativeBridgeJNI.get_ExperimentConfig_deviceName(swigCPtr);
137138
}
138139

140+
public int getInitialReadDelay()
141+
{
142+
return initialReadDelayMillis;
143+
}
144+
145+
public void setInitialReadDelay(int initialReadDelayMillis)
146+
{
147+
this.initialReadDelayMillis = initialReadDelayMillis;
148+
}
149+
139150
public void setNumSensorConfigs(int numSensorConfigs) {
140151
NativeBridgeJNI.set_ExperimentConfig_numSensorConfigs(swigCPtr, numSensorConfigs);
141152
}

sensor-native/src/swig/java/ccsd/vernier/ExperimentConfig.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ public class ExperimentConfig implements
3737
{
3838
private long swigCPtr;
3939
protected boolean swigCMemOwn;
40+
private int initialReadDelayMillis;
4041

4142
protected ExperimentConfig(long cPtr, boolean cMemoryOwn) {
4243
swigCMemOwn = cMemoryOwn;
4344
swigCPtr = cPtr;
45+
initialReadDelayMillis = 0;
4446
}
4547

4648
protected void finalize() {
@@ -67,7 +69,17 @@ public boolean isValid()
6769
public boolean getExactPeriod()
6870
{
6971
return getExactPeriodUChar() == 1;
70-
}
72+
}
73+
74+
public int getInitialReadDelay()
75+
{
76+
return initialReadDelayMillis;
77+
}
78+
79+
public void setInitialReadDelay(int initialReadDelayMillis)
80+
{
81+
this.initialReadDelayMillis = initialReadDelayMillis;
82+
}
7183

7284
public org.concord.sensor.SensorConfig [] getSensorConfigs()
7385
{

sensor-vernier/src/main/java/org/concord/sensor/vernier/labpro/LabProSensorDevice.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public class LabProSensorDevice extends AbstractStreamingSensorDevice
3333

3434
public final static int [] CHANNELS = {1,2,3,4,11,12};
3535

36-
public final static String ERR_DEVICE_NOT_ATTACHED = "LabPro is not attached";
36+
public final static String ERR_DEVICE_NOT_ATTACHED = "LabPro is not attached";
37+
38+
// additional delay from starting an experiment to reading first sample
39+
public final static int INITIAL_READ_DELAY_MILLIS = 850;
3740

3841
protected final byte [] buf = new byte [1024];
3942

@@ -169,15 +172,18 @@ public final static int round(float value)
169172
* @see org.concord.sensor.device.SensorDevice#configure(org.concord.sensor.ExperimentRequest)
170173
*/
171174
public ExperimentConfig configure(ExperimentRequest request)
172-
{
175+
{
173176
ExperimentConfig experimentConfig = autoIdConfigure(request);
174177

178+
// Configure the LabPro-specific timing delay
179+
experimentConfig.setInitialReadDelay(INITIAL_READ_DELAY_MILLIS);
180+
175181
// Configure the LabPro library appropriately
176182
int numChannels = experimentConfig.getSensorConfigs().length;
177183
port.setNumChannels(numChannels);
178184

179185
return experimentConfig;
180-
}
186+
}
181187

182188

183189
/**
@@ -389,12 +395,12 @@ public boolean start()
389395
} else if(sensor.getType() == SensorConfig.QUANTITY_RAW_VOLTAGE_2 ||
390396
sensor.getType() == SensorConfig.QUANTITY_RAW_DATA_2){
391397
// setup sensor to report +/-10V
392-
protocol.channelSetup(channelNumber, 2);
398+
protocol.channelSetup(channelNumber, 2);
393399
} else {
394400
protocol.channelSetup(channelNumber, 1);
395-
}
396-
}
397-
401+
}
402+
}
403+
398404
port.setNumChannels(sensorConfigs.length);
399405

400406
// Turning on the power seems necessary before reading
@@ -439,7 +445,7 @@ public void stop(boolean wasRunning)
439445
// send the reset
440446
protocol.reset();
441447
port.reset();
442-
448+
443449
// Close the port if it can open quickly again.
444450
// This way if the program crashes or second program is opened then there will
445451
// be less of a chance of port conflict.

sensor/src/main/java/org/concord/sensor/ExperimentConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ public interface ExperimentConfig
9696
*/
9797
public float getDataReadPeriod();
9898

99+
/**
100+
* This is the number of milliseconds the client should wait between
101+
* starting an experiment and beginning to collect the data in
102+
* addition to the time it takes to collect the first sample.
103+
*
104+
* @return
105+
*/
106+
public int getInitialReadDelay();
107+
108+
/**
109+
* This is the number of milliseconds the client should wait between
110+
* starting an experiment and beginning to collect the data in
111+
* addition to the time it takes to collect the first sample.
112+
*
113+
* @return
114+
*/
115+
public void setInitialReadDelay(int initialReadDelayMillis);
116+
99117
/**
100118
* An array of SensorConfig, each SensorConfig contains configuration
101119
* information about the sensor. This will return null if there are no

sensor/src/main/java/org/concord/sensor/impl/ExperimentConfigImpl.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ public class ExperimentConfigImpl
4949
private String deviceName;
5050
private int deviceId;
5151
private float dataReadPeriod;
52+
private int initialReadDelayMillis;
5253

5354
private Range periodRange;
54-
55+
56+
public ExperimentConfigImpl()
57+
{
58+
initialReadDelayMillis = 0;
59+
}
60+
5561
/* (non-Javadoc)
5662
* @see org.concord.sensor.ExperimentConfig#isValid()
5763
*/
@@ -102,8 +108,18 @@ public void setExactPeriod(boolean exact)
102108
{
103109
exactPeriod = exact;
104110
}
105-
106-
/* (non-Javadoc)
111+
112+
public int getInitialReadDelay()
113+
{
114+
return initialReadDelayMillis;
115+
}
116+
117+
public void setInitialReadDelay(int initialReadDelayMillis)
118+
{
119+
this.initialReadDelayMillis = initialReadDelayMillis;
120+
}
121+
122+
/* (non-Javadoc)
107123
* @see org.concord.sensor.ExperimentConfig#getSensorConfigs()
108124
*/
109125
public SensorConfig[] getSensorConfigs()

0 commit comments

Comments
 (0)