Borrar filtros
Borrar filtros

Efficient real-time data streaming between two PCs.

1 visualización (últimos 30 días)
RZM
RZM el 30 de Mzo. de 2018
Dear all,
I am trying to read data in real-time using TCP/IP from a remote PC which has an application running to record some data. The following code helps reading each data item at "a time". The problem is that when you want to get more data items you have to run the following four lines again with different data number (which here is 13), this takes too long for each sample of data so it misses some data between each readings. For instance if the data items are provided every 0.003 sec it reads the data every 0.01 sec so missing at least two samples in this 0.007 sec interval.
flushinput(t); %clear input buffer
GetDataItem(t,13); %send command to the remote PC
InputBuf = fread(t,40); %read 1st 40bytes sent back by the remote PC
data(sampl_cnt) = fread(t,1,'single'); %read floating point value starting at byte 41
This is the subroutine function to send a command to the application in the remote PC to choose a data item
function GetDataItem(t, DataID)
GetDataItem_cmd = 25;
output_bytes = [76,83,65,32,20,0,0,0,GetDataItem_cmd,0,0,0,0,0,0,0,DataID,0,0,0];
% compute check sum
% First, sum the bytes in the output array
sum = int32(0);
for count = 1:20;
incr = int32(output_bytes(count));
sum = sum + incr;
end
% Get the least significant byte of the sum
sum16 = uint16(sum);
sum_lsb = bitand(sum16,255);
% Take the "twos compliment" of the lsb
chksm = bitcmp(uint8(sum_lsb),'uint8') + 1;
% insert the checksum in the output array
output_bytes(13) = chksm;
fwrite(t,output_bytes);
end
Do you have any suggestions to optimize the codes to run faster or do you think it is possible to take multiple data items at a time?

Respuestas (0)

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by