LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP Read bytes to read

Hi everybody,

I have an additional question regarding my LabVIEW application:

Each TCP_read block needs an exact number of bytes to read, correct? But I have the problem, that I send only a small (1-3 bytes long) command (via TCP_write) to a solar power station, which sends an answer with a variable number of bytes. So I can't actually set the "bytes_to_read" number before the data comes in. Is there a way to read data without setting the bytes-to-read option ( e.g. read all incoming data within 10 seconds...)? Or do I have to do it a completly other way?

Otherwise, if there is absolutely no possibility to do that, I have to change my server C-code, detect, how many bytes are to send and send this value to the Client. But that's a bit difficult....so I would like to avoid that...! 😉
Anyway, maybe somebody has an idea...!



Thanks,

Dennis
0 Kudos
Message 1 of 4
(5,013 Views)
Are you using LabWindows/CVI or LabVIEW? If you are using LabVIEW, you'll be able to get a better answer if you post on the LabVIEW forum.
Bilal Durrani
NI
0 Kudos
Message 2 of 4
(5,003 Views)
Hi Dennis.

If the remote device only transmits in response to your commands, and you know the maximum length of the response you will receive for each command, the solution is fairly simple:
1. Set "bytes_to_read" to the maximum length.
2. Set the TCP_Read timeout to allow for this length and the worst-case latency.
3. Do not send further commands until the TCP_Read function returns (to ensure that you read only one response message for each command). It will return when either of the following occurs:
- the specified number of bytes is read
- the timeout period expires

Regards,
Colin.
0 Kudos
Message 3 of 4
(4,993 Views)

What is your maximum number of bytes ?????

Try this.............

1. Set the number of bytes to be read as maximum possible.

2. Set the read mode as immediate..

3. Thats it...run the program.

 

In immediate mode as soon as you will receive the data TCP read will read untill data is continue & once data is over it will return immdaitely.

Let me know if its working fine. & if you have any other good solution, let me know.

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 4 of 4
(4,461 Views)