delete(gcf);

fclose('all');

clear all
close all

global seq_num_last;
global CircBuff;
global R_idx;
global MaxSeqNum;

seq_num_last = 0;

canch1 = canChannel('PEAK-System', 'PCAN_USBBUS1');
configBusSpeed(canch1, 125000);

R_idx = PacketDefinition;

ExpectedSampleRate = 10;  %Hz
ExpectedSamplePeriod = 1/ExpectedSampleRate;
n_samples = 2^9; %MaxDisplayTime*ExpectedSampleRate;
DisplayTime = n_samples/ExpectedSampleRate;  %seconds

CircBuff = NaN(n_samples,length(fieldnames(R_idx)));
CircBuff(1:end,R_idx.time) = (1:length(CircBuff))*ExpectedSamplePeriod-ExpectedSamplePeriod;
CircBuff(1:end,R_idx.DataIDs) = 0;

start(canch1)
canch1.MessageReceivedFcnCount = 1;
%canch1.MessageReceivedFcn = @LabTxtDisplayCanCallback;
