Skip to content

Commit

Permalink
update documentation, include CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
doshirohan committed Jan 2, 2025
1 parent 8772eec commit daa892f
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 30 deletions.
95 changes: 95 additions & 0 deletions examples/nidaqmx/moniker-streaming/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# cmake build file for C++ MonikerStreamingClient example.
# Assumes protobuf and gRPC have been installed using cmake.

cmake_minimum_required(VERSION 3.16)

project(MonikerStreamingClient C CXX)

find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")

set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
find_program(_PROTOBUF_PROTOC protoc)
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
set(_GRPC_GRPCPP gRPC::grpc++)
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")

# Proto files
get_filename_component(daqmx_proto "../../../generated/nidaqmx/nidaqmx.proto" ABSOLUTE)
get_filename_component(daqmx_proto_path "${daqmx_proto}" PATH)
get_filename_component(session_proto "../../../imports/protobuf/session.proto" ABSOLUTE)
get_filename_component(session_proto_path "${session_proto}" PATH)
get_filename_component(data_moniker_proto "../../../imports/protobuf/data_moniker.proto" ABSOLUTE)
get_filename_component(data_moniker_proto_path "${data_moniker_proto}" PATH)

# Generated sources
set(daqmx_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/nidaqmx.pb.cc")
set(daqmx_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/nidaqmx.pb.h")
set(daq_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/nidaqmx.grpc.pb.cc")
set(daq_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/nidaqmx.grpc.pb.h")
add_custom_command(
OUTPUT "${daqmx_proto_srcs}" "${daqmx_proto_hdrs}" "${daq_grpc_srcs}" "${daq_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${daqmx_proto_path}"
-I "${session_proto_path}"
-I "${data_moniker_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${daqmx_proto}"
DEPENDS "${daqmx_proto}")

# Generated sources
set(session_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/session.pb.cc")
set(session_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/session.pb.h")
set(session_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/session.grpc.pb.cc")
set(session_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/session.grpc.pb.h")
add_custom_command(
OUTPUT "${session_proto_srcs}" "${session_proto_hdrs}" "${session_grpc_srcs}" "${session_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${session_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${session_proto}"
DEPENDS "${session_proto}")

# Generated sources
set(data_moniker_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/data_moniker.pb.cc")
set(data_moniker_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/data_moniker.pb.h")
set(data_moniker_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/data_moniker.grpc.pb.cc")
set(data_moniker_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/data_moniker.grpc.pb.h")
add_custom_command(
OUTPUT "${data_moniker_proto_srcs}" "${data_moniker_proto_hdrs}" "${data_moniker_grpc_srcs}" "${data_moniker_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${data_moniker_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${data_moniker_proto}"
DEPENDS "${data_moniker_proto}")

# Include generated *.pb.h files
include_directories("${CMAKE_CURRENT_BINARY_DIR}")

add_executable(MonikerStreamingClient
"stream-read-analog-input-using-moniker-streaming.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/nidaqmx.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/nidaqmx.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/nidaqmx.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/nidaqmx.grpc.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/session.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/session.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/session.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/session.grpc.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/data_moniker.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/data_moniker.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/data_moniker.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/data_moniker.grpc.pb.h"
)
target_link_libraries(MonikerStreamingClient
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
/*********************************************************************
* Acquire a finite amount of data using the DAQ device's internal clock.
The gRPC API is built from the C API. NI-DAQmx documentation is installed with the driver at:
C:\Program Files (x86)\National Instruments\NI-DAQ\docs\cdaqmx.chm
Getting Started:
To run this example, install "NI-DAQmx Driver" on the server machine:
https://www.ni.com/en-us/support/downloads/drivers/download.ni-daqmx.html
For instructions on how to use protoc to generate gRPC client interfaces, see our "Creating a gRPC
Client" wiki page:
https://github.com/ni/grpc-device/wiki/Creating-a-gRPC-Client
Refer to the NI DAQmx gRPC Wiki for the latest C Function Reference:
https://github.com/ni/grpc-device/wiki/NI-DAQMX-C-Function-Reference
To run this example without hardware: create a simulated device in NI MAX on the server (Windows
only).
Running from command line:
Server machine's IP address, port number, and physical channel name can be passed as separate
command line arguments.
> python analog-input.py <server_address> <port_number> <physical_channel_name>
To acquire data from multiple channels, pass in a list or range of channels (i.e., Dev1/ai0:3).
If they are not passed in as command line arguments, then by default the server address will be
"localhost:31763", with "Dev1/ai0" as the physical channel name..
"""
* Acquire data continuously from an analog input channel using moniker based streaming
*
* The gRPC API is built from the C API. NI-DAQmx documentation is installed with the driver at:
* C:\Program Files (x86)\National Instruments\NI-DAQ\docs\cdaqmx.chm
*
* Getting Started:
*
* To run this example, install "NI-DAQmx Driver" on the server machine:
* https://www.ni.com/en-us/support/downloads/drivers/download.ni-daqmx.html
*
* For instructions on how to use protoc to generate gRPC client interfaces, see our "Creating a gRPC
* Client" wiki page:
* https://github.com/ni/grpc-device/wiki/Creating-a-gRPC-Client
*
* Refer to the NI DAQmx gRPC Wiki for the latest C Function Reference:
* https://github.com/ni/grpc-device/wiki/NI-DAQMX-C-Function-Reference
*
* To run this example without hardware: create a simulated device in NI MAX on the server (Windows
* only).
*
* Build:
*
* > mkdir build
* > cd build
* > cmake ..
* > cmake --build .
*
* Running from command line:
*
* Server machine's IP address, port number, and physical channel name can be passed as separate
* command line arguments.
* > MonikerStreamingClient <server_address> <port_number> <physical_channel_name>
* If they are not passed in as command line arguments, then by default the server address will be
* "localhost:31763", with "Dev1/ai0" as the physical channel name..
*********************************************************************/

#include <iostream>
Expand All @@ -42,7 +47,7 @@ using StubPtr = std::unique_ptr<NiDAQmx::Stub>;

std::string SERVER_ADDRESS = "localhost";
std::string SERVER_PORT = "31763";
std::string PHYSICAL_CHANNEL = "PXI1Slot6/ai0";
std::string PHYSICAL_CHANNEL = "Dev1/ai0";
int NUM_ITERATIONS = 5;

class grpc_driver_error : public std::runtime_error {
Expand Down

0 comments on commit daa892f

Please sign in to comment.