artf4162: Fixes multiple solenoid creations in java

Change-Id: Iff1d6cb608c1c95723fa3121fd6c24629952f4dd
This commit is contained in:
Thad House
2015-08-22 20:19:41 -07:00
committed by Joe Ross
parent ad64c0b025
commit 966e4be36a
2 changed files with 9 additions and 3 deletions

View File

@@ -35,6 +35,13 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
checkSolenoidModule(m_moduleNumber);
checkSolenoidChannel(m_channel);
try {
m_allocated.allocate(m_moduleNumber * kSolenoidChannels + m_channel);
} catch (CheckedAllocationException e) {
throw new AllocationException("Solenoid channel " + m_channel + " on module "
+ m_moduleNumber + " is already allocated");
}
long port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
m_solenoid_port = SolenoidJNI.initializeSolenoidPort(port);
@@ -69,8 +76,7 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
* Destructor.
*/
public synchronized void free() {
// m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_channel -
// 1);
m_allocated.free(m_moduleNumber * kSolenoidChannels + m_channel);
}
/**

View File

@@ -18,7 +18,7 @@ public abstract class SolenoidBase extends SensorBase {
private long[] m_ports;
protected int m_moduleNumber; // /< The number of the solenoid module being
// used.
protected Resource m_allocated = new Resource(63 * SensorBase.kSolenoidChannels);
protected static Resource m_allocated = new Resource(63 * SensorBase.kSolenoidChannels);
/**
* Constructor.