I am currently trying to learn Dewesoft's C++ script module. Unfortunately, there is no forum for it specifically so I am pressing all the buttons to try to find help. I want to write a code where I send 5V burst through channels at set intervals (25 ms and 50 ms, from the channels DO1 and DO2) however, I cannot, for the life of me, get anything to trigger. I have done the online course (can be found in this link: https://dewesoft.com/academy/online/dewesoft-c-script#page-3) but I unfortunately either cannot understand them for the life of me or there's a fault in my logic. If there is a fault in my logic, I reckoned that people unfamiliar with Dewesoft could also find it and kindly let me know because I honestly have no idea where I went wrong.
Here is a step by step list with pictures and code detailing what I have done:
1. I have set an input channel as a time signal. (Dewesoft requires at least one input channel).
3. I have linked my digital output pins to the software outputs.
4. I have written my code within the skeleton code Dewesoft offers as such:
namespace bsc = Dewesoft::Math::Api::Basic;
class Module: public bsc::MathModule {
public:
Module(); ~Module();
void configure() override;
void start() override;
void stop() override;
void clear() override;
// MY CODE BELOW THIS POINT
// Outputs have been mapped to Ctrl DO1 / Ctrl DO2 in A/D out
double PyroOneOut = 0.0; // "First Pyro's Output"
double PyroTwoOut = 0.0; // "Second Pyro's Out"
private:
//Timing parameters (ms)
const double t1_ms = 25.0; // DO1 fires at 25 ms
const double t2_ms = 50.0; // DO2 fires at 50 ms
const double width_ms = 5.0; // pulse width (will change if needed)
// Internal clock
std::chrono::steady_clock::time_point t0;
};
inline Module::Module() {
// Procedure which gets called the first thing a setup containing your module gets loaded or when the window with your module's setup form is closed. During this call only variables in published'' struct are properly set. Useful for loading heavy libraries, reading from files, etc. }
inline Module::~Module() {
// Called when your module is no longer used, giving you an opportunity to clean up. }
inline void Module::configure() {
// Procedure used for overriding settings set in Configure'' tab. Most useful for setting blockSizeInSamples, and output channel's units, axes and expectedAsyncRates, based on the values of published variables.
PyroOneOut = 0.0;
PyroTwoOut = 0.0;
}
inline void Module::start() {
// Procedure which gets called at the start of a new measurement, strictly after Module::init(). Useful for setting initial values for your variables.
// Called at measurement start — zero outputs and arm the timer.
t0 = std::chrono::steady_clock::now();
PyroOneOut = 0.0;
PyroTwoOut = 0.0;
}
inline void Module::stop() {
// A converse of Module::start(), called when the measurement is stopped.
// Ensure outputs go LOW when stopping.
PyroOneOut = 0.0;
PyroTwoOut = 0.0;
}
inline void Module::clear() {
// Procedure which gets called whenever DEWESoft // clears data in channels, eg. when storing is started.
PyroOneOut = 0.0;
PyroTwoOut = 0.0;
}
inline void Module::calculate() {
// Procedure which gets called repeatedly whenever DEWESoft has exactly Block size'' (or 1, in sample based mode) number of new samples in input channels.
using namespace std::chrono;
const double ms =
duration(steady_clock::now() - t0).count();
const bool do1_high = (ms >= t1_ms) && (ms < (t1_ms + width_ms));
const bool do2_high = (ms >= t2_ms) && (ms < (t2_ms + width_ms));
PyroOneOut = do1_high ? 1.0 : 0.0;
PyroTwoOut = do2_high ? 1.0 : 0.0;
}