Class SimDevice
- java.lang.Object
-
- edu.wpi.first.hal.SimDevice
-
- All Implemented Interfaces:
AutoCloseable
public class SimDevice extends Object implements AutoCloseable
A wrapper around a simulator device handle.
-
-
Constructor Summary
Constructors Constructor Description SimDevice(int handle)Wraps a simulated device handle as returned by SimDeviceJNI.createSimDevice().
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static SimDevicecreate(String name)Creates a simulated device.static SimDevicecreate(String name, int index)Creates a simulated device.static SimDevicecreate(String name, int index, int channel)Creates a simulated device.SimBooleancreateBoolean(String name, boolean readonly, boolean initialValue)Creates a boolean value on the simulated device.SimDoublecreateDouble(String name, boolean readonly, double initialValue)Creates a double value on the simulated device.SimEnumcreateEnum(String name, boolean readonly, String[] options, int initialValue)Creates an enumerated value on the simulated device.SimValuecreateValue(String name, boolean readonly, HALValue initialValue)Creates a value on the simulated device.intgetNativeHandle()Get the internal device handle.
-
-
-
Method Detail
-
create
public static SimDevice create(String name)
Creates a simulated device.The device name must be unique. Returns null if the device name already exists. If multiple instances of the same device are desired, recommend appending the instance/unique identifer in brackets to the base name, e.g. "device[1]".
null is returned if not in simulation.
- Parameters:
name- device name- Returns:
- simulated device object
-
create
public static SimDevice create(String name, int index)
Creates a simulated device.The device name must be unique. Returns null if the device name already exists. This is a convenience method that appends index in brackets to the device name, e.g. passing index=1 results in "device[1]" for the device name.
null is returned if not in simulation.
- Parameters:
name- device nameindex- device index number to append to name- Returns:
- simulated device object
-
create
public static SimDevice create(String name, int index, int channel)
Creates a simulated device.The device name must be unique. Returns null if the device name already exists. This is a convenience method that appends index and channel in brackets to the device name, e.g. passing index=1 and channel=2 results in "device[1,2]" for the device name.
null is returned if not in simulation.
- Parameters:
name- device nameindex- device index number to append to namechannel- device channel number to append to name- Returns:
- simulated device object
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
getNativeHandle
public int getNativeHandle()
Get the internal device handle.- Returns:
- internal handle
-
createValue
public SimValue createValue(String name, boolean readonly, HALValue initialValue)
Creates a value on the simulated device.Returns null if not in simulation.
- Parameters:
name- value namereadonly- if the value should not be written from simulation sideinitialValue- initial value- Returns:
- simulated value object
-
createDouble
public SimDouble createDouble(String name, boolean readonly, double initialValue)
Creates a double value on the simulated device.Returns null if not in simulation.
- Parameters:
name- value namereadonly- if the value should not be written from simulation sideinitialValue- initial value- Returns:
- simulated double value object
-
createEnum
public SimEnum createEnum(String name, boolean readonly, String[] options, int initialValue)
Creates an enumerated value on the simulated device.Enumerated values are always in the range 0 to numOptions-1.
Returns null if not in simulation.
- Parameters:
name- value namereadonly- if the value should not be written from simulation sideoptions- array of option descriptionsinitialValue- initial value (selection)- Returns:
- simulated enum value object
-
createBoolean
public SimBoolean createBoolean(String name, boolean readonly, boolean initialValue)
Creates a boolean value on the simulated device.Returns null if not in simulation.
- Parameters:
name- value namereadonly- if the value should not be written from simulation sideinitialValue- initial value- Returns:
- simulated boolean value object
-
-