diff --git a/bindings/python/examples/aout.py b/bindings/python/examples/aout.py new file mode 100644 index 00000000..b8ec8e17 --- /dev/null +++ b/bindings/python/examples/aout.py @@ -0,0 +1,38 @@ +# +# Copyright (c) 2019 Analog Devices Inc. +# +# This file is part of libm2k +# (see http://www.github.com/analogdevicesinc/libm2k). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +# + +import libm2k + +ctx=libm2k.m2kOpen("ip:192.168.2.1") +if ctx is None: + print("Connection Error: No ADALM2000 device available/connected to your PC.") + exit(1) + +ctx.calibrateADC() +aout = ctx.getAnalogOut() + +print(f"channel 0: {aout.setChannelRaw(0, 555)}") +print(f"channel 0: {aout.setChannelRaw(1, 666)}") + + + + + +libm2k.contextClose(ctx) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 52838c39..155d246e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,3 +5,5 @@ add_subdirectory(digital) add_subdirectory(powersupply) add_subdirectory(voltmeter) add_subdirectory(lidar) +add_subdirectory(custom) + diff --git a/examples/custom/CMakeLists.txt b/examples/custom/CMakeLists.txt new file mode 100644 index 00000000..dc17ba13 --- /dev/null +++ b/examples/custom/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.1.3) +set (CMAKE_CXX_STANDARD 11) +project(custom LANGUAGES CXX) + + +if (LIBM2K_VERSION) # in-source build + set(PROJECT_VERSION ${LIBM2K_VERSION}) +else() # standalone build + set(PROJECT_VERSION "1.0.0") + find_package(libm2k REQUIRED) +endif() + +if (NOT WIN32) + find_library(PTHREAD_LIBRARIES pthread) +endif() + +add_executable(${PROJECT_NAME} "main.cpp") +target_link_libraries(${PROJECT_NAME} PRIVATE libm2k::libm2k) diff --git a/examples/custom/main.cpp b/examples/custom/main.cpp new file mode 100644 index 00000000..fbee0abf --- /dev/null +++ b/examples/custom/main.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2019 Analog Devices Inc. + * + * This file is part of libm2k + * (see http://www.github.com/analogdevicesinc/libm2k). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + */ +// This example assumes the following connections: +// W1 -> 1+ +// W2 -> 2+ +// GND -> 1- +// GND -> 2- +// +// The application will generate a sine and triangular wave on W1 and W2. The signal is fed back into the analog input +// and the voltage values are displayed on the screen + +#define _USE_MATH_DEFINES +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace libm2k; +using namespace libm2k::analog; +using namespace libm2k::context; + +// uncomment the following definition to test triggering +//#define TRIGGERING + +int main(int argc, char* argv[]) +{ + M2k *ctx = m2kOpen("ip:192.168.2.1"); + if (!ctx) { + std::cout << "Connection Error: No ADALM2000 device available/connected to your PC." << std::endl; + return 1; + } + + M2kAnalogIn *ain = ctx->getAnalogIn(); + M2kAnalogOut *aout = ctx->getAnalogOut(); +#ifdef TRIGGERING + M2kHardwareTrigger *trig = ain->getTrigger(); +#endif + + // Prevent bad initial config + ain->reset(); + aout->reset(); + + aout->setChannelRaw(0, 123); + aout->setChannelRaw(1, 456); + + + contextClose(ctx); + + return 0; +}