MATLAB and USB PT104

Post your MATLAB discussions here.

MATLAB and USB PT104

Postby Wipster » Fri Feb 18, 2011 11: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 4:24 pm

Re: MATLAB and USB PT104

Postby Chris » Mon Feb 21, 2011 11: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 10:00 am
Location: St. Neots


Return to MATLAB

Who is online

Users browsing this forum: No registered users and 0 guests