Set Data Rate

Legacy support with Phidget21
dxc536
Fresh meat
Posts: 4
Joined: Mon Oct 30, 2017 2:32 pm
Contact:

Set Data Rate

Postby dxc536 » Mon Jun 17, 2019 10:31 am

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: 3064
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Set Data Rate

Postby Patrick » Wed Jun 19, 2019 2:20 pm

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

-Patrick


Return to “Matlab”

Who is online

Users browsing this forum: No registered users and 2 guests