View Single Post
  #4   Spotlight this post!  
Unread 18-02-2013, 23:56
mitchellweb1 mitchellweb1 is offline
Registered User
AKA: Mitchell W
FRC #0190
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Acton, MA
Posts: 30
mitchellweb1 is an unknown quantity at this point
Re: NetworkTable issues...

Hi Rob,

Thanks for the additional information. Unfortunately there is no guarantee in the order which values are delivered. If you want to guarantee that you receive both values together than you can use arrays (see code below) which allow for transaction like behavior but only with keys of the same type. The NumberArray acts just like an array list and supports simple operations such as add, set, clear and remove. Doing operations on array object do not send any values until putValue is used. retrieveValue will atomically retrieve values from network tables. DO NOT attempt to use the value in the ValueChanged callback. You must always use retrieveValue to get an array.

As for multithreading, networktables should be thread safe, HOWEVER the ValueChanged callback will be called while an internal lock is held on the internal data store. This means that you cannot do any kind of put or get from another thread (but you can do it from inside of the callback) so if you attempt to take a lock inside of the ValueChanged method make sure that another thread will not be holding the same lock and attempt to use networktables or your code will deadlock. One other consideration is try to make sure that you don't do a put on networktables inside of ValueChanged that will cause ValueChanged to be called again as this will cause recursive call of ValueChanged.

You can use whatever table you want. If you put values to the SmartDashboard table then they will show up on the Smart Dashboard but otherwise there is no reason either way.

Also you can just do getDouble. You don't have to do getValue and then do the type check.

--Mitchell Wills


//to sent value
NumberArray data= new NumberArray();
table.putValue("mykey", data);
//values in date are now valid

=======================================

//to retrieve value
NumberArray data= new NumberArray();
//put values in the array
table.retrieveValue("mykey", data);
Reply With Quote