Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Network Tables with c++ (http://www.chiefdelphi.com/forums/showthread.php?t=149164)

balloman 25-06-2016 12:43

Network Tables with c++
 
I have vision code in c++ that I would like to send to the roborio with network tables. My only problem is that there are no tutorials on the wpilib website to do this in C++.

connor.worley 25-06-2016 13:35

Re: Network Tables with c++
 
https://www.google.com/search?q=networktables+c%2B%2B

euhlmann 25-06-2016 14:54

Re: Network Tables with c++
 
I'll assume your C++ project is not built with WPILib.

First, git clone the NetworkTables repository: https://github.com/wpilibsuite/ntcore
Then build it for whatever you're running this on (arm or native) with gradle. See the readme file for how.
Then, find the static library file for whatever you built it for. For example, a x64 native build would be located at ntcore\native\build\binaries\ntcoreStaticLibrary\x 64\ntcore.lib
Also find the includes folder at ntcore\include

Now you're ready to use it in your C++ project. Add the includes folder as an include path, the folder containing ntcore.lib as a library path, and tell the linker to use ntcore as a library (-lntcore on GCC)

Then in your cpp file add these includes
Code:

#include <ntcore.h>
#include <networktables/NetworkTable.h>

Documentation for NetworkTable is included in WPILib documentation here: http://first.wpi.edu/FRC/roborio/rel...workTable.html

For example, to publish a string value to the roboRIO's SmartDashboard you can do
Code:

#include <ntcore.h>
#include <networktables/NetworkTable.h>
using std::shared_ptr;
int main() {
    NetworkTable::SetClientMode();
    NetworkTable::SetIPAddress("10.te.am.2");
    NetworkTable::Initialize();
    shared_ptr<NetworkTable> myTable = NetworkTable::GetTable("SmartDashboard");
    myTable->PutString("ExampleString", "Sample Text");
    NetworkTable::Shutdown();
    return 0;
}


balloman 26-06-2016 02:24

Re: Network Tables with c++
 
Quote:

Originally Posted by euhlmann (Post 1594346)
I'll assume your C++ project is not built with WPILib.

First, git clone the NetworkTables repository: https://github.com/wpilibsuite/ntcore
Then build it for whatever you're running this on (arm or native) with gradle. See the readme file for how.
Then, find the static library file for whatever you built it for. For example, a x64 native build would be located at ntcore\native\build\binaries\ntcoreStaticLibrary\x 64\ntcore.lib
Also find the includes folder at ntcore\include

Now you're ready to use it in your C++ project. Add the includes folder as an include path, the folder containing ntcore.lib as a library path, and tell the linker to use ntcore as a library (-lntcore on GCC)

Then in your cpp file add these includes
Code:

#include <ntcore.h>
#include <networktables/NetworkTable.h>

Documentation for NetworkTable is included in WPILib documentation here: http://first.wpi.edu/FRC/roborio/rel...workTable.html

For example, to publish a string value to the roboRIO's SmartDashboard you can do
Code:

#include <ntcore.h>
#include <networktables/NetworkTable.h>
using std::shared_ptr;
int main() {
    NetworkTable::SetClientMode();
    NetworkTable::SetIPAddress("10.te.am.2");
    NetworkTable::Initialize();
    shared_ptr<NetworkTable> myTable = NetworkTable::GetTable("SmartDashboard");
    myTable->PutString("ExampleString", "Sample Text");
    NetworkTable::Shutdown();
    return 0;
}


Thank you so much, this is exactly what I was looking for. I kept searching on google BEFORE I posted this, but couldn't find anything.


All times are GMT -5. The time now is 20:49.

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