I'm developing my own program for ADC-16 datalogger and having problems with getting data from it. Calling adc_16_get_value function in program causes the following error:
Run-Time Chack Failure #0 - The value of ESP was not properly saved across a function call.
This is usually a result of calling a function declared with one calling convention with a function pointer with a different calling convention.
typedef int (_stdcall *Openptr)(short int port);
typedef int (_stdcall *Closeptr)(unsigned short int port);
typedef int (_stdcall *Valueptr)(long far * value, unsigned short int port, int resolution, short int channel);
typedef int (_stdcall *FValueptr) (long far * value, unsigned short int port, short int channel);
typedef int (_stdcall *GCycleptr) (long far * cycle, short int port);
typedef int (_stdcall *Versionptr)(short int far * version, short int port);
typedef void (_stdcall *Pollptr)(void);
typedef void (_stdcall *SetChannelptr) (unsigned short int port, unsigned short int channel,unsigned short int resolution,
unsigned short int single_ended, unsigned short int filter_factor);
short int version; // Version of ADC16
unsigned short int port=1; // 1= COM1, 2= COM2 etc.
unsigned short int channel=1; // Current channel
unsigned short int resolution=8; // A/D resolution (bits)
unsigned short int mode=true; // False for differential mode, True = single ended
unsigned short int ffactor=1; // Filtering factor
long value;
long cycle;
int i;
Just got rid of errors by selecting from: project > properties > configuration properties > c/c++ > code generation > basic runtime checks: Unintialised Variables option. Still having problems to get valid data from datalogger, only valid return value is version number. All the other return values are 1 or 0. What's going wrong ?
The return values of the function are meant to be 1 or 0 - they show whether a reading is available or not. After the driver has been opened it will take a few seconds before this returns TRUE.
To get the values, you need to look at the first argument in the function - the actual reading is assigned to this variable when it becomes available.
Still having problems with functions. Only adc16_get_version and adc16_open_unit return true so these are working. I can't get any of others to return true and value of the arguments that are supposed to change during the functions don't change.
I made some minor changes to it, still won't work. Current code is here:
#include "stdafx.h"
#include
typedef int (_stdcall *Openptr) (short int port);
typedef int (_stdcall *Closeptr) (unsigned short int port);
typedef int (_stdcall *Valueptr) (long far * value, unsigned short int port, short int channel);
typedef int (_stdcall *FValueptr) (long far * value, unsigned short int port, short int channel);
typedef int (_stdcall *GCycleptr) (long far * cycle, short int port);
typedef int (_stdcall *Versionptr) (short int far * version, short int port);
typedef void (_stdcall *Pollptr) (void);
typedef void (_stdcall *SetChannelptr) (unsigned short int port, unsigned short int channel,
unsigned short int resolution, unsigned short int single_ended,
unsigned short int filter_factor);
void wait(int frv);
int main(int argc, _TCHAR* argv[])
{
HINSTANCE hLib;
short int version; // Version of ADC16
unsigned short int port=1; // 1= COM1, 2= COM2 etc.
unsigned short int channel=1; // Current channel
unsigned short int resolution=13; // A/D resolution (bits)
unsigned short int mode=1; // False for differential mode, True = single ended
unsigned short int ffactor=1; // Filtering factor
long far value=0;
long far cycle=0;
int i;
int frv=0;