PCGU 1000 DLL and Matlab

Hi Velleman group,

for a research project we are planing to use a programmable function generator such as PCGU 1000, but we need to modify signals from MatLab. The provided DLL seems perfect; I just have no experience if it is possible to embed such a DLL in Matlab. Any ideas?
We are using Win7, 64bit with Matlab R2010a.

Thanks for any tips!

Jorg

It seems to be possible to call a dynamic link library (DLL) from MATLAB.
Please check this thread: viewtopic.php?f=11&p=17383

Also check these links:
mathworks.com/support/soluti … on=1-1ABRP
mathworks.com/help/techdoc/m … 4dfi7.html

It seems that you need the header file for the FGULINK.dll too.
Here is the contents of the header file:

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

#define FUNCTION __declspec(dllimport)

FUNCTION void __stdcall SetGen(int func, float freq, float ampl, float offset);
FUNCTION void __stdcall SetSweep(float freq1, float freq2, float ampl, float offset, float time, int form);
FUNCTION void __stdcall SetLibWave(float freq, float ampl, float offset, int filter, char *pointer);
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 status);
FUNCTION void __stdcall AttOn(bool att);
FUNCTION void __stdcall LogSweep(bool log);

#ifdef __cplusplus
}
#endif[/code]

Or you can use this simpler version:

[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]

Hi,

I’m trying to use your code in Matlab 7.7 but it does not work.
I’ve found a script using your code (wiki.lsr.ei.tum.de/nst/equipmen … ngenerator) but the Status of the Generator remains to 0.

A simple “loadlibrary(‘FGULINK.dll’, ‘FGULINK.h’);” then “calllib(‘FGULINK’, ‘OpenGen’)” does not work either (status LED of the generator always OFF).

If I use FGU.exe, I have no problem.

Do you have any idea ?

Thank you.

Please download this latest version of the FGU.EXE and FGULink_demo.exe.
This version doesn’t need to run “As Administrator” as the previous version needs to do.
Here is the link to download the updated files: box.net/shared/a5ub2zlbjq

After extracting the package, can you get the generator working from the FGULink_demo.exe ?

Hi,

Thank you for your answer.

With FGULink_demo.exe everything runs perfectly.
I also tried to use your VB.net example, no problem.

My problem is only related to MATLAB. I don’t know why the OpenGen command does nothing in MATLAB.

Do you still have your C++ example or anything simple I could compile in Dev-C++ ? I tried

[code]#include
#include
#include “fgulink.h”

using namespace std;

int main(int argc, char *argv[])
{
system(“PAUSE”);
OpenGen();
return EXIT_SUCCESS;
}[/code]

But I get [Linker error] undefined reference to `_imp__OpenGen@0’. I guess I need more than only fgulink ?

I’m not really good in C++, I guess I have to add the .lib file to call the dll in such a way ?

Sorry, there is no .LIB file available for Dev-C++.
Here is a working code written in Dev-C++.
In this example there is used explicit DLL linking (no bneed for a .LIB file):
See: http://msdn.microsoft.com/en-us/library/784bt7z7.aspx

Copy the files FGU.exe. FGULINK.DLL and fgu1000.bit to the Dev-C++ project folder.

[code]#include
#include <windows.h>
#include

typedef void (__stdcall *PFN1)(int, float, float, float);
typedef void (__stdcall *PFN2)(float, float, float, float, float, int);
typedef void (__stdcall PFN3)(float, float, float, int, char);
typedef void (__stdcall *PFN4)();
typedef bool (__stdcall *PFN5)();
typedef int (__stdcall *PFN6)();
typedef void (__stdcall *PFN7)(bool);

// Definitions:
PFN1 SetGen; //void SetGen(int, float, float, float);
PFN2 SetSweep; //void SetSweep(float, float, float, float, float, int);
PFN3 SetLibWave; //void SetLibWave(float, float, float, int, char*);
PFN4 StartGen; //void StartGen();
PFN4 StopGen; //void StopGen();
PFN4 OpenGen; //void OpenGen();
PFN4 CloseGen; //void CloseGen();
PFN5 GenReady; //bool GenReady();
PFN6 GenStatus; //int GenStatus();
PFN7 ShowGen; //void ShowGen(bool);
PFN7 AttOn; //void AttOn(bool);
PFN7 LogSweep; //void LogSweep(bool);

HINSTANCE hDLL;
int init();
using namespace std;

int main(int)
{
if (!init())
{
cout << “DLL found - Press Enter to turn generator on” << endl;
cin.get();
OpenGen();

	cout << "Press Enter to check the generator status" << endl;
	cin.get();
	int h = GenStatus();
	cout << h <<  endl;

	cout << "Press Enter to output 1kHz, 5Vpp, 0V offset sine wave" << endl;
	cin.get();
	SetGen(1, 1000, 5, 0);

    cout << "Press Enter to close generator and free library" << endl;
    cin.get();
	CloseGen();
}
else
{
	cout << "DLL not found" << endl;
    cout << "Press Enter to free library" << endl;
	cin.get();
}
FreeLibrary(hDLL);
return EXIT_SUCCESS;

}

int init()
{
// Loading DLL
hDLL = LoadLibrary(“fgulink.dll”);
if (hDLL != NULL)
{
// DLL function assignments
SetGen = (PFN1)GetProcAddress(hDLL, “SetGen”);
SetSweep = (PFN2)GetProcAddress(hDLL, “SetSweep”);
SetLibWave = (PFN3)GetProcAddress(hDLL, “SetLibWave”);
StartGen = (PFN4)GetProcAddress(hDLL, “StartGen”);
StopGen = (PFN4)GetProcAddress(hDLL, “StopGen”);
OpenGen = (PFN4)GetProcAddress(hDLL, “OpenGen”);
CloseGen = (PFN4)GetProcAddress(hDLL, “CloseGen”);
GenReady = (PFN5)GetProcAddress(hDLL, “GenReady”);
GenStatus = (PFN6)GetProcAddress(hDLL, “GenStatus”);
ShowGen = (PFN7)GetProcAddress(hDLL, “ShowGen”);
AttOn = (PFN7)GetProcAddress(hDLL, “AttOn”);
LogSweep = (PFN7)GetProcAddress(hDLL, “LogSweep”);
return 0;
}
return -1; // Error to load DLL
}[/code]

Thank you,

In fact, my question was not really clear. I wanted to use DevC++ to use the .h file in another environment and see if I could run the generator.
My purpose is still to use MATLAB ; ).

OK. It is strange why you can’t get the function generator working using the header file from the MATLAB.

Hello,

i got a problem with the output of the PCGU 1000 when i use it in Matlab. The dll import works fine with the header file provided here. Because I need to design the signals myself, I used the SetLibWave command to set the variables. Problem is that I get only one period of the signal as an output. If I use the SetGen command it works fine, but then I am not able to used my own .lib files. Within the waveform sequence you can specify SetGen(4,fre,amp,off, *lib) but this doesnt work with the header file. When I use the 4 as indicator for the waveform the generator is set to sweep.

Is there anything I am overlooking? Can you provide a solution for my problem?

Best regards and Thanks in advance.

Daniel

You may try following:
Download the latest FGULINK.DLL and FGU.EXE from this link: box.net/shared/a5ub2zlbjq
Try the SetLibWave with these new files.
Does it help if you use StopGen and then StartGen ?

If still problems you can try following:

Use SetLibWave to “open” the library data file.
Then use the SetSweep to sweep the library waveform.
Set the parameter “form” to 3 in the function SetSweep.
Use equal values for freq1 and freq2 to prevent frequency sweep.

SetSweep
Syntax

procedure SetSweep(freq1, freq2, ampl, offset, time: Single; form:Longint);Parameters
freq1: Sweep start frequency in Hz.
freq2: Sweep stop frequency in Hz.
ampl: Peak-to-peak amplitude in volts.
offset: DC offset in volts.
time: Sweep time in seconds.
form: Sweep waveform type: 1=sine, 2=square, [color=#800000]3=previously selected waveform[/color].