Function ziAPIGetValueD#
Defined in File ziAPI.h
-
ZIResult_enum ziAPIGetValueD(ZIConnection conn, const char *path, ZIDoubleData *value)#
gets the double-type value of the specified node
This function retrieves the numerical value of the specified node as an double-type value. The value first found is returned if more than one value is available (a wildcard is used in the path).
// Copyright [2018] Zurich Instruments AG #include <algorithm> #include <cstdlib> #include <ctime> #include <iostream> #include <map> #include <string> #include "ziAPI.h" #include "ziUtils.hpp" void setDemodRate( ZIConnection conn, const char** deviceAddress, uint32_t index, ZIDoubleData rate) { char nodePath[1024]; snprintf( nodePath, sizeof(nodePath), "/%s/demods/%d/rate", *deviceAddress, index); checkError(ziAPISetValueD(conn, nodePath, rate)); } ZIDoubleData getDemodRate( ZIConnection conn, const char** deviceAddress, uint32_t index) { ZIDoubleData rate; char nodePath[1024]; snprintf( nodePath, sizeof(nodePath), "/%s/demods/%d/rate", *deviceAddress, index); checkError(ziAPIGetValueD(conn, nodePath, &rate)); return rate; } int main() { // The device address of the device to run the example on. const char* deviceAddress = ziUtilsGetEnv("LABONE_DEVICE", "dev2123"); printf("ENV LABONE_DEVICE=%s\n", deviceAddress); // Address of the data server. const char* dataServer = ziUtilsGetEnv("LABONE_SERVER", "localhost"); // Port of the data server. const uint16_t port = 8004; // Over which interface the connection to the // device should be established. Can be either // - 1: "1GbE" - Ethernet // - 2: "USB" - USB // - 3: "PCIe" - PCIe const char* deviceInterface = "1GbE"; ZIConnection conn = nullptr; if (isError(ziAPIInit(&conn))) { return 1; } ziAPISetDebugLevel(0); ziAPIWriteDebugLog(0, "Logging enabled."); try { checkError( ziAPIConnectEx(conn, dataServer, port, ZI_API_VERSION_6, nullptr)); ziApiServerVersionCheck(conn); checkError( ziAPIConnectDevice(conn, deviceAddress, deviceInterface, nullptr)); // Set a device configuration. uint32_t index = 0; ZIDoubleData rate = 10e3; setDemodRate(conn, &deviceAddress, index, rate); // Read it back. rate = getDemodRate(conn, &deviceAddress, index); std::cout << "[INFO] " << "Device " << deviceAddress << " demod " << index << " has rate " << rate << ".\n"; ziAPIDisconnect(conn); } catch (std::runtime_error& e) { char extErrorMessage[1024] = ""; ziAPIGetLastError(conn, extErrorMessage, 1024); fprintf(stderr, "[ERROR] %s\ndetails: `%s`\n.", e.what(), extErrorMessage); return 1; } catch (...) { // Ensure all exceptions are caught. fprintf(stderr, "[ERROR] Unexpected error\n."); return 1; } ziAPIDestroy(conn); return 0; }
See also
- Parameters:
conn – [in] Pointer to ZIConnection with which the value should be retrieved
path – [in] Path to the node holding the value
value – [out] Pointer to a double in which the value should be written
- Returns:
ZI_INFO_SUCCESS on success
ZI_ERROR_CONNECTION when the connection is invalid (not connected) or when a communication error occurred
ZI_ERROR_LENGTH if the path’s length exceeds MAX_PATH_LEN
ZI_ERROR_COMMAND on an incorrect answer of the server
ZI_ERROR_SERVER_INTERNAL if an internal error occurred in Data Server
ZI_WARNING_NOTFOUND if the given path could not be resolved or no value is attached to the node
ZI_ERROR_TIMEOUT when communication timed out
Other return codes may also be returned, for a detailed error message use ziAPIGetLastError.