Skip to content

Commit 22c4a8c

Browse files
mikeprosserniMike Prosser
andauthored
Add ReadDigitalWaveforms to NiDAQmxService (#1213)
* Enhance NIDAQmx API with waveform support and additional metadata - Added ReadAnalogWaveforms method stub to NiDAQmxService for reading analog waveforms. - Updated metadata validation to include CustomCodeNoLibrary. - Introduced new waveform attributes and functions in metadata. - Enhanced CMake configuration for new protobuf files. - Improved CONTRIBUTING.md with Ninja build instructions. * fix lint * fix validate_examples * ReadAnalogWaveforms implementation (untested, but compiles) * add tests * Add support for creating two AI voltage channels in tests * cleanup * cleanup CMakeLists.txt * attempt fix for ubuntu build * more verbose build output * Try some different build settings * add quotes to fix cmake flags * add sampsPerChanRead to ReadAnalogWaveforms response * revert changes in build_cmake.yml and do -fno-var-tracking-assignments instead * use GCC push_options * use -fno-var-tracking-assignments globally for gcc * fix timing conversion * add ReadDigitalWaveforms RPC with stub implementation * implementation and tests for single channel * test multi channel and multi line * add copilot instructions for how to build with ninja, and do some cleanup * fix data layout * brad's feedback * copy protobuf types protos to heirarchical location * fix merge and templatize the SetWfmAttrCallback * copilot-build.ps1 * handle epoch difference (note - SecondsFrom0001EpochTo1904Epoch value is off by 5ish months) * convert_dot_net_daqmx_ticks_to_btf_precision_timestamp * fixes and cleanup * cleanup and more test cases * PrecisionTimestampConverterLiteralTests * fix merge * remove copilot instructions (will be added in separate PR) * use correct logic for NI-BTF * test cleanup * fillMode: 1 = GROUP_BY_SCAN_NUMBER (interleaved) * cleanup merge * cleanup * use waveform->mutable_y_data(); * test cleanup * Brad's feedback * cleanup --------- Co-authored-by: Mike Prosser <[email protected]>
1 parent 5f047e3 commit 22c4a8c

File tree

7 files changed

+541
-50
lines changed

7 files changed

+541
-50
lines changed

generated/nidaqmx/nidaqmx.proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ service NiDAQmx {
467467
rpc WriteToTEDSFromArray(WriteToTEDSFromArrayRequest) returns (WriteToTEDSFromArrayResponse);
468468
rpc WriteToTEDSFromFile(WriteToTEDSFromFileRequest) returns (WriteToTEDSFromFileResponse);
469469
rpc ReadAnalogWaveforms(ReadAnalogWaveformsRequest) returns (ReadAnalogWaveformsResponse);
470+
rpc ReadDigitalWaveforms(ReadDigitalWaveformsRequest) returns (ReadDigitalWaveformsResponse);
470471
}
471472

472473
enum BufferUInt32Attribute {
@@ -11535,3 +11536,19 @@ message ReadAnalogWaveformsResponse {
1153511536
int32 samps_per_chan_read = 3;
1153611537
}
1153711538

11539+
message ReadDigitalWaveformsRequest {
11540+
nidevice_grpc.Session task = 1;
11541+
int32 num_samps_per_chan = 2;
11542+
double timeout = 3;
11543+
oneof waveform_attribute_mode_enum {
11544+
WaveformAttributeMode waveform_attribute_mode = 4;
11545+
int32 waveform_attribute_mode_raw = 5;
11546+
}
11547+
}
11548+
11549+
message ReadDigitalWaveformsResponse {
11550+
int32 status = 1;
11551+
repeated ni.protobuf.types.DigitalWaveform waveforms = 2;
11552+
int32 samps_per_chan_read = 3;
11553+
}
11554+

generated/nidaqmx/nidaqmx_client.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12441,5 +12441,32 @@ read_analog_waveforms(const StubPtr& stub, const nidevice_grpc::Session& task, c
1244112441
return response;
1244212442
}
1244312443

12444+
ReadDigitalWaveformsResponse
12445+
read_digital_waveforms(const StubPtr& stub, const nidevice_grpc::Session& task, const pb::int32& num_samps_per_chan, const double& timeout, const simple_variant<WaveformAttributeMode, pb::int32>& waveform_attribute_mode)
12446+
{
12447+
::grpc::ClientContext context;
12448+
12449+
auto request = ReadDigitalWaveformsRequest{};
12450+
request.mutable_task()->CopyFrom(task);
12451+
request.set_num_samps_per_chan(num_samps_per_chan);
12452+
request.set_timeout(timeout);
12453+
const auto waveform_attribute_mode_ptr = waveform_attribute_mode.get_if<WaveformAttributeMode>();
12454+
const auto waveform_attribute_mode_raw_ptr = waveform_attribute_mode.get_if<pb::int32>();
12455+
if (waveform_attribute_mode_ptr) {
12456+
request.set_waveform_attribute_mode(*waveform_attribute_mode_ptr);
12457+
}
12458+
else if (waveform_attribute_mode_raw_ptr) {
12459+
request.set_waveform_attribute_mode_raw(*waveform_attribute_mode_raw_ptr);
12460+
}
12461+
12462+
auto response = ReadDigitalWaveformsResponse{};
12463+
12464+
raise_if_error(
12465+
stub->ReadDigitalWaveforms(&context, request, &response),
12466+
context);
12467+
12468+
return response;
12469+
}
12470+
1244412471

1244512472
} // namespace nidaqmx_grpc::experimental::client

generated/nidaqmx/nidaqmx_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ BeginWriteRawResponse begin_write_raw(const StubPtr& stub, const nidevice_grpc::
469469
WriteToTEDSFromArrayResponse write_to_teds_from_array(const StubPtr& stub, const std::string& physical_channel, const std::string& bit_stream, const simple_variant<WriteBasicTEDSOptions, pb::int32>& basic_teds_options);
470470
WriteToTEDSFromFileResponse write_to_teds_from_file(const StubPtr& stub, const std::string& physical_channel, const std::string& file_path, const simple_variant<WriteBasicTEDSOptions, pb::int32>& basic_teds_options);
471471
ReadAnalogWaveformsResponse read_analog_waveforms(const StubPtr& stub, const nidevice_grpc::Session& task, const pb::int32& num_samps_per_chan, const double& timeout, const simple_variant<WaveformAttributeMode, pb::int32>& waveform_attribute_mode);
472+
ReadDigitalWaveformsResponse read_digital_waveforms(const StubPtr& stub, const nidevice_grpc::Session& task, const pb::int32& num_samps_per_chan, const double& timeout, const simple_variant<WaveformAttributeMode, pb::int32>& waveform_attribute_mode);
472473

473474
} // namespace nidaqmx_grpc::experimental::client
474475

generated/nidaqmx/nidaqmx_service.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ class NiDAQmxService final : public NiDAQmx::WithCallbackMethod_RegisterSignalEv
539539
::grpc::Status WriteToTEDSFromArray(::grpc::ServerContext* context, const WriteToTEDSFromArrayRequest* request, WriteToTEDSFromArrayResponse* response) override;
540540
::grpc::Status WriteToTEDSFromFile(::grpc::ServerContext* context, const WriteToTEDSFromFileRequest* request, WriteToTEDSFromFileResponse* response) override;
541541
::grpc::Status ReadAnalogWaveforms(::grpc::ServerContext* context, const ReadAnalogWaveformsRequest* request, ReadAnalogWaveformsResponse* response) override;
542+
::grpc::Status ReadDigitalWaveforms(::grpc::ServerContext* context, const ReadDigitalWaveformsRequest* request, ReadDigitalWaveformsResponse* response) override;
542543
private:
543544
LibrarySharedPtr library_;
544545
ResourceRepositorySharedPtr session_repository_;

source/codegen/metadata/nidaqmx/functions_addon.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,76 @@
6868
'type': 'int32'
6969
}
7070
]
71+
},
72+
'ReadDigitalWaveforms': {
73+
'returns': 'int32',
74+
'codegen_method': 'CustomCodeNoLibrary',
75+
'parameters': [
76+
{
77+
'ctypes_data_type': 'ctypes.TaskHandle',
78+
'direction': 'in',
79+
'is_optional_in_python': False,
80+
'name': 'task',
81+
'python_data_type': 'TaskHandle',
82+
'python_description': '',
83+
'python_type_annotation': 'TaskHandle',
84+
'type': 'TaskHandle'
85+
},
86+
{
87+
'ctypes_data_type': 'ctypes.c_int',
88+
'direction': 'in',
89+
'is_optional_in_python': False,
90+
'name': 'numSampsPerChan',
91+
'python_data_type': 'int',
92+
'python_description': '',
93+
'python_type_annotation': 'int',
94+
'type': 'int32'
95+
},
96+
{
97+
'ctypes_data_type': 'ctypes.c_double',
98+
'direction': 'in',
99+
'is_optional_in_python': True,
100+
'name': 'timeout',
101+
'python_data_type': 'float',
102+
'python_default_value': '10.0',
103+
'python_description': 'Specifies the time in seconds to wait for the device to respond before timing out.',
104+
'python_type_annotation': 'Optional[float]',
105+
'type': 'float64'
106+
},
107+
{
108+
'ctypes_data_type': 'ctypes.c_int',
109+
'direction': 'in',
110+
'enum': 'WaveformAttributeMode',
111+
'is_optional_in_python': True,
112+
'name': 'waveformAttributeMode',
113+
'python_data_type': 'WaveformAttributeMode',
114+
'python_default_value': 'WaveformAttributeMode.NONE',
115+
'python_description': 'Specifies which waveform attributes to return with the waveforms.',
116+
'python_type_annotation': 'Optional[nidaqmx.constants.WaveformAttributeMode]',
117+
'type': 'int32'
118+
},
119+
{
120+
'direction': 'out',
121+
'is_optional_in_python': False,
122+
'name': 'waveforms',
123+
'python_data_type': 'object',
124+
'python_description': 'The waveforms read from the specified channels.',
125+
'python_type_annotation': 'List[object]',
126+
'type': 'repeated ni.protobuf.types.DigitalWaveform'
127+
},
128+
{
129+
'ctypes_data_type': 'ctypes.c_int',
130+
'direction': 'out',
131+
'is_optional_in_python': False,
132+
'is_streaming_type': True,
133+
'name': 'sampsPerChanRead',
134+
'python_data_type': 'int',
135+
'python_description': '',
136+
'python_type_annotation': 'int',
137+
'return_on_error_key': 'ni-samps-per-chan-read',
138+
'type': 'int32'
139+
}
140+
]
71141
}
72142
}
73143

@@ -101,7 +171,13 @@
101171
},
102172
'ReadAnalogWaveforms': {
103173
'parameters': {
104-
# size is determined by the number of channels in the task
174+
# size is determined by the Read.ChannelsToRead property
175+
'waveforms': ['ARRAY_PARAMETER_NEEDS_SIZE']
176+
}
177+
},
178+
'ReadDigitalWaveforms': {
179+
'parameters': {
180+
# size is determined by the Read.ChannelsToRead property
105181
'waveforms': ['ARRAY_PARAMETER_NEEDS_SIZE']
106182
}
107183
}

0 commit comments

Comments
 (0)