Ideen, die mir kamen:
- Eine DLL mit C++ aus den API Funktionen erstellen (wie gehe ich mit Objekten um?)
- Die API Datei zerlegen und ei Aufrufe an die zugrunde liegende DLL herauspicken
- Eine bisschen Code in C++ schreiben und eine DLL bauen, die PB kompatible Werte zurückgibt
(Muss ich beim Aufruf etwas beachten?)
- ...?
Vor allem stellt sich die Frage: Wie baue ich am besten mit C++ eine DLL für PureBasic?
Bereits gelernt: Nächstes mal besser darauf achten, welches Gerät mir vorgelegt wird
Für die Interessierten:
Gerät: CEBO-LC 16-bit Multi-I/O USB measurement laboratory
Programming Reference
API Download
Und ein Codebeispiel mit deren API:
Code: Alles auswählen
/**
* CeboMsr - C++ example - Single I/O.
*
* The I/O's of digital port #0 are read and mirrored to digital port #1.
* (IO-0 - IO-7 are mirrored to IO-8 - IO-15).
* The voltage at AI-0 is mirrored to AO-1 and AI-1 to AO-0 too.
*
* Does only work on CeboLC devices.
*
* (c) 2015 Cesys GmbH
* @author Thomas Hoppe
*/
#include <iostream>
#include <stdexcept>
#include <cebomsrpp.h>
using namespace std;
using namespace CeboMsr;
/**
* Do very simple IO, digital as well as analog.
*/
void singleIoTest(Device &device) {
// Read digital port #0 and write result to digital port #1 (mirror pins).
// At first, we need references to both ports.
// Port #0 will be a copy of the original instance.
DigitalPort dp0 = device.getDigitalPorts().at(0);
// As an alternative, get a reference to Port #1.
const DigitalPort &dp1 = device.getDigitalPorts().at(1);
// Configure port first, all bits of digital port #0 as input (default)
// and all bits of digital port #1 as output.
dp1.setOutputEnableMask(0xff);
// Read from #0 ...
int value = dp0.read();
// Write the value to #1 ...
dp1.write(value);
// Now some analog I/O, do it without any additional local references.
// Read single ended #0 input voltage ...
float vvalue = device.getSingleEndedInputs().at(0).read();
// Write value to analog output #1
device.getAnalogOutputs().at(1).write(vvalue);
// .. or in one line: single ended #1 to analog output #0 ...
device.getAnalogOutputs().at(0).write(device.getSingleEndedInputs().at(1).read());
// Reset to power up defaults.
device.resetDevice();
}
/**
* Application entry point.
*/
int main() {
// Nearly all methods can raise exceptions. For this example, the error handling is done at this single point.
try {
// Search for devices ...
DeviceVector devices = LibraryInterface::enumerate(DeviceType::CeboLC);
// If at least one has been found, use the first one ...
if (!devices.empty()) {
Device device = devices[0];
// Open device, nothing can be done without doing this.
device.open();
// *** DIGITAL PORTS AND ANALOG OUTPUTS ARE MODIFIED DURING THIS ***
// *** SECTION, SO DO NOT CONNECT ANY PERIPHERALS WITHOUT STUDYING ***
// *** THE ACTIONS DONE HERE, OTHERWISE YOUR PERIPHERALS MAY BE DAMAGED !!! ***
singleIoTest(device);
// Finalize device usage, this free's up the device, so it can be used
// again, including other applications.
device.close();
}
} // These exceptions are currently used to report different problems ...
catch (const std::invalid_argument &e) { cout << "Invalid argument exception raised: " << e.what() << endl; }
catch (const std::out_of_range &e) { cout << "Out of range exception raised: " << e.what() << endl; }
catch (const std::logic_error &e) { cout << "Logic error exception raised: " << e.what() << endl; }
catch (const std::runtime_error &e) { cout << "Runtime/IO error exception raised: " << e.what() << endl; }
catch (const std::exception &e) { cout << "Unknown exception raised: " << e.what() << endl; }
return 0;
}