Set Data Rate

Legacy support with Phidget21
Post Reply
dxc536
Phidgetsian
Posts: 5
Joined: Mon Oct 30, 2017 2:32 pm
Contact:

Set Data Rate

Post by dxc536 »

Hello,

I'm using the polling method to read in sensor data into matlab and I don't think I understand where to place 'CPhidgetInterfaceKit_setDataRate' in order to change the datarate.

After I run:

Code: Select all

loadphidget21;

handles.phid = libpointer('int32Ptr');
calllib('phidget21', 'CPhidgetInterfaceKit_create', handles.phid);
calllib('phidget21', 'CPhidget_open', handles.phid, -1);


The following function is used:

Code: Select all

function sensorvalue = analogin_mod(n,phid)



if calllib('phidget21', 'CPhidget_waitForAttachment', phid, 500) == 0
    calllib('phidget21','CPhidgetInterfaceKit_setDataRate',phid,n,8);
    dataptr = libpointer('int32Ptr', 0);
    if calllib('phidget21', 'CPhidgetInterfaceKit_getSensorValue', phid, n, dataptr) == 0
       sensorvalue = dataptr.Value;
    else
        % clean up
        calllib('phidget21', 'CPhidget_close', phid);
        calllib('phidget21', 'CPhidget_delete', phid);
        error('Error getting sensor data..');
    end
else
    % clean up
    calllib('phidget21', 'CPhidget_close', phid);
    calllib('phidget21', 'CPhidget_delete', phid);
    error('Could not open InterfaceKit')
end


I don't run into any errors, but no matter what I change the DataRate to I'm only able to sample at 40 hz. Even if I remove that line from the code I am still sampling at 40 hz.

Any thoughts?

Thanks
User avatar
Patrick
Lead Developer
Posts: 634
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Set Data Rate

Post by Patrick »

You need to leave the device open. The library will read in several samples as part of initialization on each open.

-Patrick
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests