Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   network tables and arrays (http://www.chiefdelphi.com/forums/showthread.php?t=115249)

fovea1959 21-03-2013 13:08

network tables and arrays
 
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.

Is what I am attempting doable?

Ginto8 21-03-2013 15:48

Re: network tables and arrays
 
Here's the method that's throwing the exception (from edu.wpi.first.wpilibj.networktables2.NetworkTableN ode):
Code:

        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:
Code:

NumberArray outputArray = new NumberArray();
outputArray.add(double1);
outputArray.add(double2);
networkTable.putValue("array",outputArray);


fovea1959 29-03-2013 10:42

Re: network tables and arrays
 
That worked. Thanks!


All times are GMT -5. The time now is 22:33.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi