TCP/IP data send delay
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I am trying to communicate MATLAB and Python over TCP connection.
System works as such; Python file sends an array like "1001,1002,1003,1004,1005" to MATLAB and MATLAB replies this message with "10003,10004,10005". The problem is that MATLAB's response is too slow (about 30 secs - 120 secs)
I will use this system in a real-time simulation. So I need to resolve delay problem.
How can I overcome this problem?
Thanks
0 Kommentare
Antworten (1)
Walter Roberson
am 17 Nov. 2011
TCP/IP is buffered by default; the I/O subsystem may accumulate data to be sent until the packet is full or the timers time out or the user explicitly requests that the data be sent (by setting the PSH control bit in a packet.)
Therefore the first thing you should do is monitor the network to be sure your data is being sent when you think it is.
Then, when MATLAB receives packets, it will not necessarily pass them on immediately to the application, if the connection has been configured to use a Terminator character. The description of the rules is here. Notice the small line suggesting setting the Terminator to '' for binary files.
2 Kommentare
Walter Roberson
am 17 Nov. 2011
Consider setting a BytesAvailableFcn callback instead of looping polling the bytes available. Also, you can use t.BytesAvailable instead of the get() operation.
If you have control over the protocol, it would be better for you to define \n (newline) or \r\n (carriage return and newline) as the terminator, and to send those as part of the string, and then set the Terminator to \n .
Something I should have pointed out earlier but forgot to, is that MATLAB is not designed for real-time work. It is probably good enough for "soft real time" in low-bandwidth environments, but not for "hard real time". TCP/IP itself is not suitable for "hard real time" as TCP/IP places no upper bound on the amount of time a packet can be in transmission.
Also, be advised that older versions of the Instrument Control Toolbox did not permit MATLAB to be a TCP/IP server, only a client (that is, it would have to initiate connections to outside programs.) My recollection is that that restriction was removed in R2011B, but I could be wrong about that or off by a version.
There is a MATLAB File Exchange contribution "tcpudpip", http://www.mathworks.com/matlabcentral/fileexchange/345-tcpudpip-toolbox-2-0-6 which can substitute for the Instrument Control Toolbox and does NOT have restrictions on being a TCP/IP server.
Siehe auch
Kategorien
Mehr zu Instrument Control Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!