Page 1 of 1

Set Data Rate

Posted: Mon Jun 17, 2019 10:31 am
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

Re: Set Data Rate

Posted: Wed Jun 19, 2019 2:20 pm
by Patrick
You need to leave the device open. The library will read in several samples as part of initialization on each open.

-Patrick