- The terminator is read. For TCPIP objects, the terminator is given by the Terminator property.
- The time specified by the Timeout property passes.
- The input buffer is filled.
Message truncation/concatenation in TCP/IP between MATLAB and Swistrack
1 次查看(过去 30 天)
显示 更早的评论
Hi
I'm new working with TCP/IP but my project requires interfacing Swistrack, a visual tracking software, with Matlab. Swistrack outputs data as NMEA 0183 protocol with checksums.
The messages Swistrack sends look like these "$PARTICLE,4,122.863,296.96,1.28146,204.197,400.507*37" or "$FRAMENUMBER,331*43". I wrote a program in MATLAB to establish the connection between two programs and it receives the data when I ran both programs. However, the messages that MATLAB receives are sometimes concatenated and truncated, hence, the important information is lost. For example this is what MATLAB recieves: "$PARTICLE,0,415.927,416.624,-0.$FRAMENUMBER,333*41". I have a feeling that I'm forgetting to set some buffer properties but I'm not sure how to fix this. Can you please help me understand why the data is truncated and lost? I would really appreciate. Thank you.
Here is the code that I'm using:
close all; clc;clear all;
myIP = % I use the IP of my computer
t = tcpip('myIP', 3000);
fopen(t);
pause(.5);
while (get(t, 'BytesAvailable') > 0)
Data = fscanf(t);
fprintf(Data)
pause(0.001);
end
fclose(t);
delete(t);
0 个评论
采纳的回答
Ankit Desai
2011-4-15
fscanf reads the data from the object until one of the following conditions is met:
You might be running into one or more of these conditions resulting in truncated data.
You might also want to consider doing an event based read rather than using a while loop. The online help for events and callbacks is a good start.
Hope this helps.
-Ankit
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Instrument Control Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!