Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   C++ Network Tables (http://www.chiefdelphi.com/forums/showthread.php?t=112694)

IDKnow 03-02-2013 20:07

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
http://www.chiefdelphi.com/forums/sh...d.php?t=103352
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?

Code:

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


nightpool 04-02-2013 08:49

Re: C++ Network Tables
 
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.

virtuald 04-02-2013 11:07

Re: C++ Network Tables
 
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. :)

IDKnow 04-02-2013 21:22

Re: C++ Network Tables
 
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! : )

Code:

                NetworkTable::SetIPAddress("10.16.71.20");//driverstation IP
                NetworkTable::SetClientMode();
                NetworkTable::SetTeam(1671);
                NetworkTable::Initialize();


virtuald 05-02-2013 00:01

Re: C++ Network Tables
 
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. :)

IDKnow 06-02-2013 00:49

Re: C++ Network Tables
 
http://wpilib.screenstepslive.com/s/...client-pc-side

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!


All times are GMT -5. The time now is 12:55.

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