Skip to content

Commit

Permalink
temp_commit: testing the new write function to raw attribute
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Stanea <[email protected]>
  • Loading branch information
Adrian-Stanea committed Nov 29, 2023
1 parent f4b6652 commit 92b610e
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
38 changes: 38 additions & 0 deletions bindings/python/examples/aout.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
#

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)
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ add_subdirectory(digital)
add_subdirectory(powersupply)
add_subdirectory(voltmeter)
add_subdirectory(lidar)
add_subdirectory(custom)

18 changes: 18 additions & 0 deletions examples/custom/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
72 changes: 72 additions & 0 deletions examples/custom/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*/
// 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 <iostream>
#include <math.h>
#include <libm2k/m2k.hpp>
#include <libm2k/contextbuilder.hpp>
#include <libm2k/analog/m2kpowersupply.hpp>
#include <libm2k/analog/m2kanalogin.hpp>
#include <libm2k/analog/m2kanalogout.hpp>

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;
}

0 comments on commit 92b610e

Please sign in to comment.