Passing Pointer to DLL file

3 visualizaciones (últimos 30 días)
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh el 14 de Jul. de 2014
Respondida: Johannes Bleser el 2 de Mzo. de 2022
Hi Everyone.
Thanks so much for your attention and help in advance.
I' have a problem with TTi (TGA12104) Arbitrary Waveform Generator connected via USB to PC. I'm loading the DLL file into MATLAB and using its functions to send commands to the device.
loadlibrary('AWGUSB.DLL')
Device is connected, I can detect the device using "AWG_GetDevices()" and then I use "AWG_Open()" to open the device, there is no problem up to this point, but as I try "AWG_Write()" to send commands, I receive beeps which means the command is not recognized, I can't even reset the device sending a string '*RST'
There is a "TestAWGUSB.exe" provided with the driver which works very well with the same DLL file ensures that the "DLL" file works, the device is connected and there is a problem with what I'm doing in MATLAB(I've been using this device via RS232 but it fails one out of 4 for unknown reasons, anyway this is not related to the problem at all)
Code is consist of some few lines so far, cuz I'm still unable to even reset it via USB :(
I have a "AWGUSB.DLL" "AWGUSB.lib" and "AWGUSB.H" in the same folder as I wrote the MATLAB code.
After loading the device, it's time to open it so
deviceNumber = calllib('AWGUSB','AWG_GetDevices',1,1); % this works fine
LibPointerDevHandle = calllib('AWGUSB','AWG_Open',deviceNumber,1024,0); % believe this is ok
stat = calllib('AWGUSB','AWG_Write',LibPointerDevHandle,'*RST',4); % this is the problem
As I run the last command it beeps(unrecognized command,doesn't restart), command should be a char pointer apparently, so I tried below but still the same
command = '*RST';
cmd = libpointer('cstring',command);
stat = calllib('AWGUSB','AWG_Write',LibPointerDevHandle,cmd,4);
The same problem, I tried sprintf(command) instead of cmd, command,char(command), int32(4) instead of 4! No progress at all!
According to the DLL guide PDF "AWG_Write" should return (-5) in case of an error, and number of transmitted chars otherwise, and 'stat' is always 4 which means writing is ok! But it is not infact! :(
I have no idea what the problem is, is it the format of the command which is not recognized to the "AWG_Write"? Am I not using the write data format!?
Header is attached in text format so that you can see the input argument format.
Thanks a lot!

Respuesta aceptada

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh el 17 de Jul. de 2014
I found the problem.
I had to terminate the commands with ' ; '
Something that I did not need to do while using RS232! so I concatenate every command with ' ; '
And problem is solved!

Más respuestas (2)

Friedrich
Friedrich el 15 de Jul. de 2014
Hi,
Are you sure that the AWG_Open call is successfull? Check the error code to see if its indeed okay. The call should be:
[LibPointerDevHandle,err] = calllib('AWGUSB','AWG_Open',deviceNumber,1024,0);
Check the value of err.
I would guess the AWG_GetDevices functions returns the device IDs not as first output. I would guess its like this
[status, deviceNumbers] = calllib('AWGUSB','AWG_GetDevices',1,1);
Calling the AWG_Write like this
stat = calllib('AWGUSB','AWG_Write',LibPointerDevHandle,'*RST',4)
should be fine.

Johannes Bleser
Johannes Bleser el 2 de Mzo. de 2022
Hi,
do you mind sharing the files from the driver CD? Maybe you can somehow provide a CD image?
I'm not able to find the software or the USB-communication-manual anywhere in all of the internet.
Kind regards
Johannes

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by