C++ Network Tables

I am attempting to use the network tables class to pass values from my SmartDashboard extensions to the robot.

This thread describes the process using Java

but it seems to imply near the end that the same process will not work for C++

In my code and in the windows API I could find equivalent commands though- for everything other than begin and end transaction.

Without these, the robot crashes as soon an i try TableName->GetNumber(“”,0);

Am I missing something?

NetworkTable *Vision;
float d;
Vision->GetTable("VisionTable");//should create table if does not exist
//control loop (where it crashes)
if (Vision->IsConnected())
     d = Vision->GetNumber("d",0);//where 0 is default if "d" does not exist

Hmm… Normally when interacting with the SmartDashboard one uses the static functions from the SmartDashboard class. Like SmartDashboard::GetNumber(“d”), for your example.

As far as I know, the smart dashboard class does not support defaults, because you should initialize variables before you try retrieving them.

If you examine the source code for NetworkTables, you will notice that it throws an exception when you do a GetNumber() without first doing a PutNumber() (only the first PutNumber() is required).

They got rid of Begin/End transaction in this year’s implementation of NetworkTables, thus why you can’t find it. :slight_smile:

Thanks guys! You’re advice and a little trial and error provided me with the fix:

Putting this before the GetTable command keeps the code from crashing.
I haven’t tested getting values yet though because I’m having issues with the SmartDashboard. Also, the put function causes a crash but this is progress! : )

		NetworkTable::SetIPAddress("");//driverstation IP

Keep in mind that the ‘client’ is the driver station, and the ‘server’ is the robot. Also, you should only call SetIPAddress or SetTeam, not both. SetTeam is used to determine the IP address of the robot when in client mode. Read the code. :slight_smile:


That’s helpful. Still having trouble with the client side but I need to make it work a little differently and I’ll get to fixing that tomorrow. Thanks again guys!