Click or drag to resize

Queryf

Performs a formatted write and read through as a single operation.

virtual HRESULT Queryf(const CString strWriteFormat, const CString strReadFormat  [, argument] ...) abstract;
Parameters
strWriteFormat

[in] String describing the format of the write arguments. See the topic I/O Format Specifiers for Write Operations for details.

strReadFormat

[in] String describing the format of the read arguments. See the topic I/O Format Specifiers for Read Operations for details.

argument

[in] Optional arguments interpreted by the write and read format strings.

Return Value

Returns S_OK if successful, otherwise a failure HRESULT.

Remarks

The Queryf function provides a mechanism of "send, then receive" typical to a device command sequences. In this manner, the response generated from the command can be read immediately. The device is not polled for errors after the write portion of the sequence.

This Queryf function performs a PrintfNoPoll operation followed immediately by a Scanf operation. The first n arguments are formatted according to the strWriteFormat then sent to the device. The write buffer is flushed immediately after the write portion of the operation completes. After these actions, the response data is read from the device into the remaining arguments (starting from parameter n+1) using the strReadFormat string.

Example

The following example demonstrates use of the Querf function. Note that the topics I/O Format Specifiers for Write Operations and I/O Format Specifiers for Read Operations has many more examples of format strings that can be used with Queryf.

C++
// CoAcme4321.cpp
STDMETHODIMP Acme4321::IAcme4321_Configure()
{
  HRESULT hr = S_OK;

  // Send ID query to device and read the response
  CString strManufacturer, strModel, strSerial, strRevision;

  hr = io.Queryf(_T("*IDN?"), _T("%$C[^,],%$C[^,],%$C[^,],%$C[^,]"), &strManufacturer, &strModel, &strSerial, &strRevision);           

  return hr;
}
See Also

Download a complete CHM version of this documentation here.