Test and Measurement Forum

MATLAB and USB PT104

Post your MATLAB discussions here

MATLAB and USB PT104

Postby Wipster » Fri Feb 18, 2011 10:11 am

Hi all,
I am trying to make some matlab code which will allow me to stream directly into my workspace however I am having a few issues with establishing a connection with the device.
When I call the enumeration to find the serials of the devices attached I see that the PT104 responds with USB:AT313/069 so I try to run the connect function with 'AT313/069' and tried with prefixing the 'USB:' but it always returns no device.
Here is a copy of the offending code.
Code: Select all
if not(libisloaded('USBPT104'))
disp('Matlab: Load USBPT104.dll')
loadlibrary('USBPT104','UsbPt104Api.h')
disp('Matlab: dll loaded')
disp('')
else
disp('Matlab: dll already loaded')
disp('')
end

pause(0.5)

%%
serials = '';
serials_ptr = libpointer('cstring',serials);
seriallen = uint32(0);
seriallen_ptr = libpointer('uint32Ptr',seriallen);

[status, serials, seriallen] = calllib('USBPT104', 'UsbPt104Enumerate', serials_ptr, seriallen_ptr, 1);

pause(0.5);
disp(serials);

%%
handle = int16(0);
handle_ptr = libpointer('int16Ptr',handle);

serials = 'AT313/069';
%serials(end+1)=0;

[status, handle] = calllib('USBPT104', 'UsbPt104OpenUnit', handle_ptr, serials_ptr);

[status] = calllib('USBPT104','UsbPt104SetChannel', handle ,int16(1),int8(1),int16(4)); %setup a single channel

%-------------------------------------------------------------------------
y=int16(3);
yp = libpointer('voidPtr',y);
for loop =1:100
[status, y]=calllib('USBPT104','UsbPt104GetValue',handle, int16(1),yp, 0);
disp(y);
pause(1)
end
%-------------------------------------------------------------------------

%%
[status] = calllib('USBPT104', 'UsbPt104CloseUnit', handle);
Wipster
User
User
 
Posts: 3
Joined: Fri Oct 02, 2009 3:24 pm

Re: MATLAB and USB PT104

Postby Chris » Mon Feb 21, 2011 10:45 am

Not sure of the matlab syntax, but you need to pass the serial number without the USB: prefix, so in your case, you would just pass a null terminated AT313/069 string.

in C, this would be.....
char details[20];

g_status = UsbPt104Enumerate(details, &length, 0x01);
g_status = UsbPt104OpenUnit(&g_handle, &details[4]);
Chris
Site Admin
Site Admin
 
Posts: 169
Joined: Tue Aug 17, 2010 9:00 am
Location: St. Neots

Re: MATLAB and USB PT104

Postby stadtaffe » Thu May 07, 2015 6:18 pm

Hi
I am very primitive programmer. Could you please help to get interfacing of Pt-104 Pico Tech under matlab environment ?
Some examples to access this device via Matlab would be great. In the past I have done some interfacing with SCPI via matlab. I hope it saves time for many.

Thanking you.
stadtaffe
Newbie
 
Posts: 0
Joined: Thu May 07, 2015 6:11 pm

Re: MATLAB and USB PT104

Postby Hitesh » Mon May 11, 2015 11:47 am

Hi stadtaffe,

If you have not already done so, please download the SDK for the USB PT-104 from https://www.picotech.com/downloads

Select PicoLog Data Loggers -> Pt-104 -> Software then select the option for the USB PT-104 Software Development Kit.

If you are using a 32-bit version of MATLAB (use the computer function to detect the version) then use the following files from the SDK:

  • usbpt104.dll
  • /MATLAB/usbpt104/usbPT104MFILE.m

If you are using a 64-bit version of MATLAB you will need the following files:

  • /x64/usbpt104.dll
  • /MATLAB/usbpt104/x64/usbPT104MFILE.m

You will also need to configure a C compiler in MATLAB using the mex -setup command. If you are using a 64-bit version of MATLAB please refer to the following article:

http://uk.mathworks.com/matlabcentral/answers/101105-how-do-i-install-microsoft-windows-sdk-7-1

Please note the section about the Visual Studio 2010 Redistributable as if it is already installed it will need to be uninstalled and reinstalled after Windows SDK 7.1 and it's patch has been applied.

You will need to refer to the Programmer's Guide in the SDK and can use the above snippet of code as a starting point.

Also, instead of

Code: Select all
loadlibrary('USBPT104','UsbPt104Api.h')

use

Code: Select all
loadlibrary('usbpt104.dll', @usbPT104MFILE)

Please note that Pico Technology is not responsible for the content of external third party sites.

I hope this helps.
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to MATLAB

Who is online

Users browsing this forum: No registered users and 0 guests