C++
首先下载PROTO文件
引入头文件
#include "robot.grpc.pb.h"
using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
using robot::RobotService;
创建客户端
RobotClient greeter(grpc::CreateChannel("192.168.100.102:50051", grpc::InsecureChannelCredentials()));
测试RPC Server状态
if(!greeter.ConnectRPCServer())
return -1;
机械臂上电
greeter.MoveStart();
机械臂运动(MoveA)
greeter.RunthreadRobotJoint();
机械臂下电
greeter.MoveStop();
创建相关环境变量用于编译
$ export MY_INSTALL_DIR=$HOME/.local
$ mkdir -p $MY_INSTALL_DIR
$ export PATH="$PATH:$MY_INSTALL_DIR/bin"
创建文件夹安装相关依赖
$ mkdir -p cmake/build
$ pushd cmake/build
$ cmake -DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
../..
$ make -j
$ make install
$ popd
运行
$ ./greeter_client