Connection with PicoScope5000 c code

Post your MATLAB discussions here
Post Reply
steiemi
Newbie
Posts: 0
Joined: Wed Apr 18, 2018 6:34 am

Connection with PicoScope5000 c code

Post by steiemi »

Hello support,

I have a problem connecting my PicoScope 5444B to Matlab (C / API).
However, the connection with PicoScope6 and the normal Matlab library does not work with the Matlab c code.

Here is my code:

Code: Select all

setenv('MW_MINGW64_LOC','C:\TDM-GCC-64')
mex -setup C++

clc;
clear all;
close all;

loadlibrary 'ps5000a.dll' 'ps5000aApi.h' addheader 'picoStatus.h' mfilename 'PS5000aMFile';
if ~libisloaded('ps5000a')
error('library ps5000a.dll or ps5000a.h not found') %check if the library is loaded
end

% loadlibrary('ps5000aWrap.dll', 'ps5000aWrapMFile');

pBufferChASize = 1000000;
pBufferChA = libpointer('int16Ptr', zeros(pBufferChASize, 1));
[methodinfo,structs,enuminfo] = PS5000aMFile; % Data and method structure for the ps5000a api.

unithandle = 0; % Handle to the opened unit.
offsetVoltage = 0; % Offset in microvolt (±1 V).
pkToPk = 500000; % Peak-to-peak amplitude in microvolt (±250 mV to ±2 V).
waveType = enuminfo.enPS5000AWaveType.PS5000A_SINE; % Type of Wave. See commentsection at the bottom of this file for a full list.
%waveType = 'PS5000A_SINE'; % Type of Wave. See commentsection at the bottom of this file for a full list.
startFrequency = 1000; % Hz (must be lower than or equal to stopfrequency).
stopFrequency = 1000; % Hz.
increment = 0; % Increment in frequency for sweepmode.
dwellTime = 0; % Time (sec) spent in each frequency for sweepmode.
sweepType = enuminfo.enPS5000ASweepType.PS5000A_UP; % Type of sweep. See commentsection at the bottom of this file for a full list.
operation = enuminfo.enPS5000AExtraOperations.PS5000A_ES_OFF; % TRUE or FALSE.
shots = 0; % Number of shots if not in sweepmode.
sweeps = 0; % Number of sweeps if in sweepmode.
triggerType = enuminfo.enPS5000ASigGenTrigType.PS5000A_SIGGEN_RISING; % Trigger type. See commentsection at the bottom of this file for a full list.
triggerSource = enuminfo.enPS5000ASigGenTrigSource.PS5000A_SIGGEN_NONE; % Trigger source. See commentsection at the bottom of this file for a full list.
extInThreshold = 0; % Threshold for trigger on external in.

resolution = enuminfo.enPS5000ADeviceResolution.PS5000A_DR_8BIT;

noOfPreTriggerSamples = 0;
noOfPostTriggerSamples = 10;
noOfSamples = noOfPreTriggerSamples + noOfPostTriggerSamples;
maxSamples = noOfSamples;
timebase = 25;
oversample = 1;
timeIndisposedMs = [];
segmentIndex = 0; % Leave set to 0 unless the data is being captured in a specific segment on the device.
lpReady = []; % Callback not used
pParameter = [];
overflow = [];
channelA = enuminfo.enPS5000AChannel.PS5000A_CHANNEL_A;
range = enuminfo.enPS5000ARange.PS5000A_500MV;
downSampleRatio = 0; % If downSampleRatioMode = RATIO_MODE_NONE then this value is ignored
downSampleRatioMode = enuminfo.enPS5000ARatioMode.PS5000A_RATIO_MODE_NONE;
true = enuminfo.enPS5000ATriggerState.PS5000A_CONDITION_TRUE;

pico_status = 0;


[status_open,unithandle] = calllib('ps5000a','ps5000aOpenUnit',unithandle,0,resolution);
status_open = dec2hex(status_open);

status_ps5000aFlashLed = dec2hex(calllib('ps5000a','ps5000aFlashLed',unithandle, -1));

status_ps5000aPingUnit = dec2hex(calllib('ps5000a','ps5000aPingUnit',unithandle));

status_ps5000aSetChannel = dec2hex(calllib('ps5000a','ps5000aSetChannel',unithandle,channelA,true,true,range,offsetVoltage));

status_ps5000aGetTimebase = dec2hex(calllib('ps5000a','ps5000aGetTimebase',unithandle,timebase,noOfSamples,0,maxSamples,segmentIndex));

status_SetSigGenBuiltIn = dec2hex(calllib('ps5000a','ps5000aSetSigGenBuiltIn',unithandle,...
    offsetVoltage,pkToPk,waveType,startFrequency,stopFrequency,increment,dwellTime,...
    sweepType,operation,shots,sweeps,triggerType,triggerSource,extInThreshold));

status_ps5000aRunBlock = dec2hex(calllib('ps5000a','ps5000aRunBlock',unithandle, noOfPreTriggerSamples,...
    noOfPostTriggerSamples, timebase, timeIndisposedMs, segmentIndex, lpReady, pParameter));

ready = 0;
% Poll the driver until it has captured some data
while(ready == 0)
[status_read, ready] = calllib('ps5000a', 'ps5000aIsReady', unithandle, ready);
status_read = dec2hex(status_read);
pause(0.1);
end

% %pause(1);
% stillColectingData = 0;
% while(stillColectingData == 0)
%     status_IsReady = calllib('ps5000a','ps5000aIsReady',unithandle,&stillColectingData);
% end

status_ps5000aSetDataBuffer = dec2hex(calllib('ps5000a','ps5000aSetDataBuffer',unithandle,...
    channelA,pBufferChA,pBufferChASize,segmentIndex,downSampleRatioMode));

status_ps5000aGetValues = dec2hex(calllib('ps5000a','ps5000aGetValues',unithandle,...
    0,noOfSamples,downSampleRatio, downSampleRatioMode,segmentIndex,overflow));
    
% status_ps5000aBlockReady = calllib('ps5000a','ps5000aBlockReady',unithandle,pico_status,pParameter);

bufferChA = get(pBufferChA, 'Value');


unloadlibrary('ps5000a');
I did not get any errors! The only problem is that the status of the connection with ps5000aOpenUnit is 03 PICO_NOT_FOUND.

I know that PicoScope6 must not be opened and that no other connection with the PicoScope5444B should run!

Can someone help me with this problem?

Many thanks!
Mirco Steiert

Hitesh

Re: Connection with PicoScope5000 c code

Post by Hitesh »

Hi Mirco,

It looks as though by passing '0' for the serial number, the driver is unable to find a device with that serial number.

To ignore the serial number use the null matrix, i.e. []:

Code: Select all

[status_open,unithandle] = calllib('ps5000a','ps5000aOpenUnit',unithandle,[],resolution);
Just so you are aware, you can use the supporting files from the Instrument Driver package and don't need to use mex -setup as we already provide the prototype and thunk files.

When loading the libraries, you can call:

Code: Select all

loadlibrary('ps5000a.dll', @ps5000aMFile);
loadlibrary('ps5000aWrap.dll', @ps5000aWrapMFile);
Regards,

Post Reply