Controlling the PCGU1000 from Matlab

Hi,

I would like to know if controlling the PCGU1000 from Matlab is possible, and if yes how. I am blocked when trying to load FGULINK.dll with the loadlibrary function because it asks for a header file that I cannot find in my Velleman installation directory. There was an interesting post at viewtopic.php?f=11&t=3170 where a similar problem was encountered, but unfortunately the talks diverted and no solution was provided.

Can such a header file be created, thus rendering the control of the PCGU1000 from Matlab possible? By searching the forum, I couldn’t see any post on the topic, surprisingly.

Thank’s in advance

I think the C++ header file should look like this:

[code]#ifdef __cplusplus
extern “C” {
#endif

#define FUNCTION __declspec(dllimport)

FUNCTION __stdcall SetGen(int func, float freq, float ampl, float offset);
FUNCTION __stdcall SetSweep(float freq1, float freq2, float ampl, float offset, float time, int form);
FUNCTION __stdcall SetLibWave(float freq, float ampl, float offset, int filter, char *pointer);
FUNCTION __stdcall StartGen();
FUNCTION __stdcall StopGen();
FUNCTION __stdcall OpenGen();
FUNCTION __stdcall CloseGen();
FUNCTION bool __stdcall GenReady();
FUNCTION int __stdcall GenStatus();
FUNCTION __stdcall ShowGen(bool status);
FUNCTION __stdcall AttOn(bool att);
FUNCTION __stdcall LogSweep(bool log);

#ifdef __cplusplus
}
#endif[/code]

int = 32 bit integer

Hi, thank’s for your quick response. I have gone through some experiments myself last night and succeeded to communicate with my PCGu1000. My header was, to say, identical to what you posted. However, I had only put into work the OpenGen, CloseGen and StartGen functions. The SetGen caused me trouble because I couldn’t declare a single precision variable type (Single) in the .h . I will try it with the float tonight as you suggest and come back on the results. I also think that the variable names can be omitted in the header, i.e. “SetGen(int,float,float,…)” instead of “SetGen(int func,float freq,float ampl)”.

In the meantime, I made a working C++ demo program in Borland C++Builder.

[quote]I also think that the variable names can be omitted in the header, i.e. “SetGen(int,float,float,…)” instead of “SetGen(int func,float freq,float ampl)”.[/quote]Indeed, works fine with this header file too:
fgulink.h

[code]#ifdef __cplusplus
extern “C” {
#endif

#define FUNCTION __declspec(dllimport)

FUNCTION __stdcall SetGen(int, float, float, float);
FUNCTION __stdcall SetSweep(float, float, float, float, float, int);
FUNCTION __stdcall SetLibWave(float, float, float, int, char*);
FUNCTION __stdcall StartGen();
FUNCTION __stdcall StopGen();
FUNCTION __stdcall OpenGen();
FUNCTION __stdcall CloseGen();
FUNCTION bool __stdcall GenReady();
FUNCTION int __stdcall GenStatus();
FUNCTION __stdcall ShowGen(bool);
FUNCTION __stdcall AttOn(bool);
FUNCTION __stdcall LogSweep(bool);

#ifdef __cplusplus
}
#endif[/code]
Here the code of the whole program:[size=85][code]
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include “fgulink.h”
#include “Unit1.h”
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource “*.dfm”
TForm1 Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent
Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button6Click(TObject *Sender)
{
OpenGen();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button7Click(TObject *Sender)
{
CloseGen();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
SetGen(1, 1000, 5, 0);
StartGen();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button8Click(TObject *Sender)
{
SetGen(2, 1500, 5, 0);
StartGen();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
SetGen(3, 1000, 5, 0);
StartGen();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button11Click(TObject *Sender)
{
char s[20] = “ramp_dn.lib”;
SetLibWave(1000, 5, 2.5, 1, s);
StartGen();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject *Sender)
{
LogSweep(true);
SetSweep(10, 2000000, 5, 0, 50, 1);
StartGen();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
LogSweep(false);
SetSweep(1000, 10000, 5, 0, 10, 2);
StartGen();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
StopGen();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
AttOn(CheckBox1->Checked);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox2Click(TObject *Sender)
{
ShowGen(!CheckBox2->Checked);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(GenReady())
{
Label2->Caption = “Generator Ready!”;
}
else
{
Label2->Caption = “Generator Not Ready”;
}
Label3->Caption = "Status: "+IntToStr(GenStatus());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
CloseGen();
}
//---------------------------------------------------------------------------[/code][/size]

Thank you very much for this info. I believe it will be of valuable interest for many users.

Should I add only a small correction to your code VEL255, functions that return no values should be declared with the “void” statement at the beginning. The final code would look like this :

[code]#ifdef __cplusplus
extern “C” {
#endif

#define FUNCTION __declspec(dllimport)

FUNCTION void __stdcall SetGen(int, float, float, float);
FUNCTION void __stdcall SetSweep(float, float, float, float, float, int);
FUNCTION void __stdcall SetLibWave(float, float, float, int, char*);
FUNCTION void __stdcall StartGen();
FUNCTION void __stdcall StopGen();
FUNCTION void __stdcall OpenGen();
FUNCTION void __stdcall CloseGen();
FUNCTION bool __stdcall GenReady();
FUNCTION int __stdcall GenStatus();
FUNCTION void __stdcall ShowGen(bool);
FUNCTION void __stdcall AttOn(bool);
FUNCTION void __stdcall LogSweep(bool);

#ifdef __cplusplus
}
#endif[/code]

There the Matlab compiler no more issues warnings. I will test the functionning of the generator tonight from a simple .m file and come back on the results.

Thank you for this info.
My C++ test program works fine with this modified header file too.
It seems to be better to use the “void” declaration for compatibility reasons.

In this thread there is described a similar problem and a similar solution of the problem with other compiler:
viewtopic.php?f=3&t=3787

[quote]…change all the
FUNCTION __stdcall
to
FUNCTION void __stdcall[/quote]

Yes, right. I remember having read this thread. I just want here to confirm that the PCGU1000 is fully operational from Matlab using this last header version. It ran with Matlab R2009b under Win XP SP3 32 bits.

I’m sure the ISO C standard requires that every function has its return type declared explicitly