have a labview robot, want to write to it’s network tables from a java app on driver station. That works great, but now I want to write an array of numbers.
If I write a array of numbers to the network table from labview, Java sees it as an Object] containing Doubles. If I try to construct the same using
networkTable.putValue (“array”, new Object] { double1, double2 } );
I get an IllegalArgumentType: Invalid Type exception.
Here’s the method that’s throwing the exception (from edu.wpi.first.wpilibj.networktables2.NetworkTableNode):
public void putValue(String name, Object value) throws IllegalArgumentException{
if(value instanceof Double){
putValue(name, DefaultEntryTypes.DOUBLE, value);
} else if (value instanceof String){
putValue(name, DefaultEntryTypes.STRING, value);
} else if(value instanceof Boolean){
putValue(name, DefaultEntryTypes.BOOLEAN, value);
} else if(value instanceof ComplexData){
putValue(name, ((ComplexData)value).getType(), value);
} else if(value==null) {
throw new NullPointerException("Cannot put a null value into networktables");
} else {
throw new IllegalArgumentException("Invalid Type");
}
}
NetworkTables can only contain Doubles, Strings, Booleans, and ComplexData. ComplexData is implemented by ArrayData, which is extended by BooleanArray, StringArray, and NumberArray. I think you want to use NumberArray, and as far as I can tell, you’d use it like this:
NumberArray outputArray = new NumberArray();
outputArray.add(double1);
outputArray.add(double2);
networkTable.putValue("array",outputArray);