Picolog 1012 Matlab interface

Post your MATLAB discussions here
jjohn
Newbie
Posts: 0
Joined: Sun May 06, 2012 10:25 am

Picolog 1012 Matlab interface

Post by jjohn »

Hi
Tried to use in Matlab 2010b:

loadlibrary ('PL1000.dll','pl1000Api.h');
calllib('PL1000', 'pl1000OpenUnit');

Get following errors:

Warning: Message from C preprocessor:
lcc preprocessor warning: C:\Corpower_SW\pl1000Api.h:142 No newline at
end of file

Warning: The data type 'error' used by function pl1000OpenUnit does not
exist.

No method with matching signature.
Error in ==> PicoMatlab at 9
calllib('PL1000', 'pl1000OpenUnit');

(Have tried PS2000.dll & PS2000.h for test and it works fine)

Hitesh

Re: Picolog 1012 Matlab interface

Post by Hitesh »

Hi jjohn,

It appears that you are missing the handle argument to the open unit call.

It should be:

Code: Select all

[status_open, handle] = calllib('PL1000', 'pl1000OpenUnit', handle)
The handle argument is a pointer hence it is returned in the square brackets.

Please refer to the Programmer's guide and use the 'libfunctionsview' command to determine the arguments required for each function.

Also, the warning you receive is because there may be a need to remove a new line at the end of the header file.

Hope this helps.

Hitesh

jjohn
Newbie
Posts: 0
Joined: Sun May 06, 2012 10:25 am

Re: Picolog 1012 Matlab interface

Post by jjohn »

Q: When I use pl1000GetValues and want to test when the collecting of data is ready
i.e. the buffer is full in the Stream Mode (2).
(10 sec of collecting 1000 samples buffer #1024)

I test with the pl1000Ready but the flag do not change.

How do I do that?


rsize = libpointer('int16Ptr', zeros(1,1))
cbuffer = libpointer('cstring', '123456789ABCDEF')
[err0 cbuffer rsize] = calllib ('PL1000', 'pl1000GetUnitInfo', hand.Value , cbuffer, 16, rsize, 1)

fs = 1000;
ts = 10;
channels = 2;

pBuffer = libpointer('uint16Ptr',zeros(1024,1));
bsize = libpointer('uint32Ptr', 1024);
overflow = libpointer('uint16Ptr',zeros(1,1));

us_for_block = libpointer('uint32Ptr', ts*1000000);
ideal_nr = libpointer('uint32Ptr', fs*ts);
nr_channels = libpointer('uint16Ptr', zeros(2,1));
ready = libpointer('int16Ptr', 0);

[err1] = calllib ('PL1000', 'pl1000SetTrigger', hand.Value, 0, 0, 0, 0, 0, 0, 0, 0);
[err2] = calllib ('PL1000', 'pl1000SetInterval', hand.Value , us_for_block, 1024, [1 2], 2);
[err3] = calllib ('PL1000', 'pl1000Run', hand.Value , 1024, 2);

[err4 pBuffer bsize overflow trig] = calllib ('PL1000', 'pl1000GetValues', hand.Value , pBuffer, bsize, overflow, trig);
[err5] = calllib ('PL1000', 'pl1000Ready', hand.Value , ready);

% Test if done????
while ready.Value == 0
ready.Value
[err5] = calllib ('PL1000', 'pl1000Ready', hand.Value , ready);
end

Hitesh

Re: Picolog 1012 Matlab interface

Post by Hitesh »

Hi,

This looks like you are having an issue with the use of libpointers - from previous experience I would recommend only using those for arrays or the overflow value.

MATLAB can convert data values when passed as arguments to a function so you can declare a variable and pass it to a function call, and it will take care of the fact that it is a pointer.

Also, values that are pointers are returned by MATLAB to the left side of the '=' in a statement as is shown in the libfunctionsview('PL1000') call.

The following is a snippet of code from an example I've worked on:

Code: Select all

% Start device running
status_run = calllib('PL1000', 'pl1000Run', data.unithandle, data.nSamples, BM_STREAM);

% Wait for device to become ready
while data.isReady == 0
    
    [status_ready, data.isReady] = calllib('PL1000', 'pl1000Ready', data.unithandle, data.isReady);
    
end
Hope this helps.

botond
Newbie
Posts: 0
Joined: Thu Sep 13, 2012 7:10 pm

Re: Picolog 1012 Matlab interface

Post by botond »

Hi,
I have the same problem with PicoLog 1216. I have the following code:

loadlibrary 'PL1000.dll' 'pl1000Api.h' addheader 'picoStatus.h';

hand = libpointer('int16Ptr',0);
[status_open, hand] = calllib('PL1000', 'pl1000OpenUnit', hand);
setdatatype(status_open,'voidPtr',1,1);

I get the following Matlab warnings:
Warning: The data type 'error' used by function pl1000OpenUnit does not exist.

... and so on for all functions.

Further, if I call pl1000GetUnitInfo, the string remains the same after calling. I suspected there should be the required info, shouldn't be? How can I see whether my unit is responding or not?

Thanks

Hitesh

Re: Picolog 1012 Matlab interface

Post by Hitesh »

Hi botond,

In the pl1000Api.h file, you will need to add the following line after the #define line:

Code: Select all

#include "picoStatus.h"
What is the status value returned by the call to pl1000GetUnitInfo()?

Can you post the relevant lines of code that show how you are calling the function?

Thanks,

botond
Newbie
Posts: 0
Joined: Thu Sep 13, 2012 7:10 pm

Picolog 1216 Matlab interface

Post by botond »

Hi,
I'm using PicoLog 1216 Data Logger an i'm writing a program in Matlab 2010b.
This is a sequence of my Code:
clear all;close all;clc
loadlibrary 'C:\Users\ PL1000.dll' 'C:\Users\ pl1000Api.h'
hand = libpointer('int16Ptr',0);
[status_open, hand] = calllib('PL1000', 'pl1000OpenUnit', hand);
hand
status_open

rsize = libpointer('int16Ptr', zeros(1,1));
cbuffer = libpointer('cstring', '');
[status_get cbuffer rsize] = calllib ('PL1000', 'pl1000GetUnitInfo', hand , cbuffer, 48, rsize, 0);
cbuffer
unloadlibrary('PL1000')

I have the following problem: the programms runs only one time an after that Matlab force me to close.
This is the Matlab Meesage:
Segmentation violation detected at Sun Sep 30 20:46:39 2012
Fault Count: 1



Abnormal termination:


Register State (from fault):
EAX = 000012fe EBX = 0eea0555
ECX = 020453fb EDX = 00000204
ESP = 00c2e21c EBP = 00c2e250
ESI = 1d3484bc EDI = 0eea0000

EIP = 77c32d24 EFL = 00010202

CS = 0000001b DS = 00000023 SS = 00000023
ES = 00000023 FS = 0000003b GS = 00000000


Stack Trace (from fault):....
I hope that anyone can help me.
Thanks

Hitesh

Re: Picolog 1012 Matlab interface

Post by Hitesh »

Hi Botond,

I think this a memory issue related to how the rsize and cbuffer variables have been setup. It seems that the driver may not like rsize being set to 0 initally.

Although the function calls specify that you need a pointer for various arguments such as requiredSize, MATLAB converts the data to the required data type for you, so you don't really need a libpointer (apart for data buffers).

Please try the following:

Code: Select all

rsize = 15;
string = '';

[status_get string rsize] = calllib ('PL1000', 'pl1000GetUnitInfo', hand, string, 48, rsize, 0);
I hope this helps.

botond
Newbie
Posts: 0
Joined: Thu Sep 13, 2012 7:10 pm

Re: Picolog 1012 Matlab interface

Post by botond »

Hi Hitesh,
thank you for the Answer,unfortunately it still does not work.
After three times of Running,I recieve the same Message from Matlab:

Warning: Message from C preprocessor:
lcc preprocessor warning: C:\Users\Szabolcs\Documents\Pico\picoStatus.h:108
C:\Users\Szabolcs\Documents\Pico\pl1000Api.h:3 No newline at end of file

> In loadlibrary at 371
In panel at 2
Here I did make the newline,but Istill get this warning Message.
The error Message is as follows:

Code: Select all

------------------------------------------------------------------------
       Segmentation violation detected at Tue Oct 02 19:21:15 2012
------------------------------------------------------------------------

Configuration:
  MATLAB Version:   7.11.0.584 (R2010b)
  MATLAB License:   359886
  Operating System: Microsoft Windows 7
  Window System:    Version 6.1 (Build 7601: Service Pack 1)
  Processor ID:     x86 Family 6 Model 5 Stepping 5, GenuineIntel
  Virtual Machine:  Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
  Default Encoding:  windows-1252

Fault Count: 1



Abnormal termination:


Register State (from fault):
  EAX = 00000000  EBX = 9fe70001
  ECX = 001803c9  EDX = 00000018
  ESP = 00c2d87c  EBP = 00c2d8b0
  ESI = 1e8bd956  EDI = 9fe70000
 
  EIP = 77862d24  EFL = 00010206
 
   CS = 0000001b   DS = 00000023   SS = 00000023
   ES = 00000023   FS = 0000003b   GS = 00000000


Stack Trace (from fault):
[  0] 0x77862d24                      C:/Windows/SYSTEM32/ntdll.dll+00339236 ( RtlFreeHeap+000298 )
[  1] 0x77862c78                      C:/Windows/SYSTEM32/ntdll.dll+00339064 ( RtlFreeHeap+000126 )
[  2] 0x7637c3d4                   C:/Windows/system32/kernel32.dll+00312276 ( HeapFree+000020 )
[  3] 0x70214c39 C:/Windows/WinSxS/x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4940_none_d08cc06a442b34fc/MSVCR80.dll+00019513 ( free+000205 )
[  4] 0x7aa88170 C:/Program Files/MATLAB/R2010b/bin/win32/m_interpreter.dll+00819568 ( inGetCallersWorkSpace+000928 )
[  5] 0x7aaa005e C:/Program Files/MATLAB/R2010b/bin/win32/m_interpreter.dll+00917598 ( inFunctionHandleInterface::getWorkspaceObj+013374 )
[  6] 0x7aa7c183 C:/Program Files/MATLAB/R2010b/bin/win32/m_interpreter.dll+00770435 ( inEvalExp+000643 )
[  7] 0x7aa7c1be C:/Program Files/MATLAB/R2010b/bin/win32/m_interpreter.dll+00770494 ( inEvalExp+000702 )
[  8] 0x7aa7c24d C:/Program Files/MATLAB/R2010b/bin/win32/m_interpreter.dll+00770637 ( inEvalExp+000845 )
[  9] 0x7aa7c28c C:/Program Files/MATLAB/R2010b/bin/win32/m_interpreter.dll+00770700 ( inEvalExp+000908 )
[ 10] 0x7aa62d3d C:/Program 
....
botond

Hitesh

Re: Picolog 1012 Matlab interface

Post by Hitesh »

Hi Botond,

One thing to note is that you can use the loadlibrary command to generate a prototype file which you can load instead of the pl1000Api.h file e.g.

Code: Select all

loadlibrary 'PL1000.dll' 'pl1000Api.h' -mfilename 'pl1000mFile'; % Create the protofile

unloadlibrary('PL1000'); % Unload the library
Then, the following time use:

Code: Select all

loadlibrary 'PL1000.dll' 'pl1000mFile'
Can you please send your MATLAB script to support@picotech.com and I will run it here.

Thanks,
Last edited by Hitesh on Wed Oct 03, 2012 9:30 am, edited 1 time in total.
Reason: Additional information for Customer

Hitesh

Re: Picolog 1012 Matlab interface

Post by Hitesh »

Hi Botond,

I have been able to run the script using MATLAB 2011b and 2012a.

I had to change the location of the dll and pl1000Api header file in the script to match the PC I tested on but I also made the following change to pl1000Api.h.

Underneath:

Code: Select all

#ifndef __PL1000API_H__
#define  __PL1000API_H__
add the line

Code: Select all

#include "picoStatus.h"
Please try running the script again.

This would also have to be done prior to generating the prototype file I mentioned in my last post.

nuit
Newbie
Posts: 0
Joined: Mon Dec 31, 2012 3:06 pm

Picolog 1216 Matlab interface

Post by nuit »

Hi Hitesh,

I am also enountering some problems while calling the API from Matlab. I get the following warning from loadlibrary():
Type 'BLOCK_METHOD' was not found. Defaulting to type error.
Found on line 260 of input from line 89 of file pl1000Api.h
Further on, the status of the call to pl1000Run reports a wrong parameter, which I suspect has something to do with the above warning, hence, the argument 'BM_SINGLE' is not recognized or has the wrong type or something. I tried a lot of things, but nothing worked. Can you help figure out what goes wrong here? Thanks a lot!

The Matlab code I use is as follows:

Code: Select all

global data;

[notfound,warnings] = loadlibrary('PL1000.dll','pl1000Api.h','addheader','picoStatus.h','mfilename','PL1000MFile');
% [notfound,warnings] = loadlibrary('PL1000.dll', 'PL1000MFile');
if ~libisloaded('PL1000')
    error('library PL1000.dll or PL1000.h not found') %check if the library is loaded
end

try

data.unithandle = 0;
data.serial =[];

[status_OpenUnit, data.unithandle] = calllib('PL1000', 'pl1000OpenUnit', data.unithandle);

blockLength = 2e6; % [us], Interval of measurement block
nrSamples = 8100; % [-], Number of samples to collect in block
channelIDs = [1 2]; %[-], Active channels

nrOfValues = 4;
BM_SINGLE = 0;
BM_WINDOW = 1;
BM_STREAM = 2;

[status_SetInterval] = calllib('PL1000', 'pl1000SetInterval', data.unithandle, blockLength, nrSamples, channelIDs, length(channelIDs));

for k = 1
    
%     method = libpointer('error',BM_SINGLE);
%     method = BM_SINGLE;
    string = 'BM_SINGLE';
    method = libpointer('BLOCK_METHOD',0);
    [status_Run] = calllib('PL1000', 'pl1000Run', data.unithandle, nrOfValues, method);
    
    ready = false;
    [status_Ready, ready] = calllib('PL1000', 'pl1000Ready', data.unithandle, ready);
    while ~ready
    end
    
    values = zeros(1,nrOfValues);
    overflow = 0;
    triggerIndex = 0;
    [status_GetValues, values, nrOfValues, overflow, triggerIndex] = calllib('PL1000', 'pl1000GetValues', data.unithandle, values, nrOfValues, overflow, triggerIndex);
    
end

status_CloseUnit = calllib('PL1000', 'pl1000CloseUnit', data.unithandle);

unloadlibrary('PL1000');

catch exception
    unloadlibrary('PL1000');
    throw(exception);
end
Regards, Nuit

Hitesh

Re: Picolog 1012 Matlab interface

Post by Hitesh »

Hi nuit,

Have you added the line

Code: Select all

#include "picoStatus.h"


to the pl1000Api.h file?

Looking at your code I can see the following:

Code: Select all

string = 'BM_SINGLE';
method = libpointer('BLOCK_METHOD',0);
[status_Run] = calllib('PL1000', 'pl1000Run', data.unithandle, nrOfValues, method);
Your 'method' variable should represent an enumeration so you do not need a libpointer - I can see that you had previously defined 'method' as:

Code: Select all

method = BM_SINGLE;
If you call the loadlibrary function with the mfile as you have commented out:

Code: Select all

[notfound,warnings] = loadlibrary('PL1000.dll', 'PL1000MFile');
You can access the enumerations through the enuminfo structure in the m file - you can copy the first line from the function file (minus the function keyword) into the MATLAB command line.

Hope this helps.

nuit
Newbie
Posts: 0
Joined: Mon Dec 31, 2012 3:06 pm

Re: Picolog 1012 Matlab interface

Post by nuit »

Hi hitesh, thanks for the quick reply.

Yes, I added the #include line to the pl1000Api.h file.

I tried to put just a number there like

Code: Select all

method  = 0;
but then the script keeps hanging, and when I terminate it, status_Run has value 13, corresponding to PICO_INVALID_PARAMETER. (The library calls up to that point are fine, they all have status 0)

Also, libfunctionsview('PL1000') reports 'voidPtr' as the type of the third argument, while the proto mfile reports 'error'.

Best, nuit

Hitesh

Re: Picolog 1012 Matlab interface

Post by Hitesh »

Hi nuit,

It looks as though there is an issue with how your header file is being loaded in - are you using a 32-bit version of MATLAB and compiler?

When you call the libfunctionsview function you should see the following:
PL1000 Functions
PL1000 Functions
I have attached a Prototype file that should work:

[The extension m has been deactivated and can no longer be displayed.]

The third argument should appear as e_BLOCK_METHOD.

I hope this helps.

Post Reply