01-30-2012 07:56 PM
Dear all,
I am trying to operatewith a robot using VISA TCP/IP tools. The robot is operating in a following way: I send a command (string) like AA and then it responds to it by sending numerical value of this parameter with an additional text trash. I need to get information about a some number of these parameters, call them AA1, AA2, AA3 and so on. This part (send data to robot) is working without any problems.
My first attempt to organize reading was to use following approach: start read data in while loop, then send a bunch of necessary commands and finally stop read the data and process data. In this case my CPU becomes overloaded in while loop.
Then I started to use another approach like that: I start to read the data after send each command (sequence of operation becomes WRITE - READ - WRITE - READ - WRITE - READ) and I found that some of the parameters after read operation might be missed. Missing means there are no data was read. This is a problem. My guess is that when I start read the data it is not yet come (or its length is less than number of bytes that I want to read) and due to very small Timeout, VISA Read function generates error and I get nothing.
So, my question, is there are any way to realize reading data that will not overload the CPU (that is the best way) or is there are any way to use approach (WRITE - READ - WRITE - READ - ....) and be guaranteed that I will get all data, except situation if something will goes wrong with network connection.
Thank you in advance!
01-31-2012 03:57 PM
Hi Andrey!
See below for some ideas on how to implement some approaches you mentioned. You can implement a "wait" function in the while loop so that the while loop does not take up your entire processor's power constantly. Also, it shows how you can implement a wait between a write and a read so that you won't start the read function immediately after writing the data. You can also increase the timeout of the TCP Read.
If your processing time is still getting bogged down, I would suggest looking at this tutorial in our developer's zone on a Producer/Consumer loop architecture so that you can read data off of the bus and process the data in another loop.
01-31-2012 04:59 PM
Hi Peter,
The problem is that the whole sequence of sending commands and getting data back must be complete as soon as possible, i.e. total amount of time that I have is no more then 20 ms.
01-31-2012 05:58 PM
When you say that you only have 20ms, does that mean each combination of command/reading can only take 20ms?
Also, what you could do is perform these actions in parallel loops. Writing to the TCP bus ocurrs in one bus and reading from the TCP bus ocurrs in the other. That way you are constantly reading and writing what is ocurring.
Are you expecting to write and read a constant bit stream or is this ocurring in bursts of data (i.e. write AAAA, Read AA1AA1 vs. write AA, read AA1, wait, write AA, read AA1)?
02-01-2012 07:38 AM
Peter,
20 ms is a required time for execution not only for whole this sequence but also with additional stuff.
Two loops as I said not works as I mentioned previously. CPU becomes overloaded.
Unfortunately read data does not has any particular structure and I do some postprocess this data to get necessary information
02-01-2012 11:38 AM
Suggestions:
1) post a VI or a png image, otherwise people can't tell what your doing and thus cant help.
2) I'm guessing your problem is you are polling the Read TCP as fast as possible, and thus sometimes miss part of the message. The solution is to make the first part of the message a set of four bytes that encodes the length of the rest of the message; first Read 4 bytes (with a long timeout), then read a number of bytes indicated by those first four (again with a long timeout). Then you will get the complete message as fast as possible without missing anything and without using any CPU in polling.
-- James
02-01-2012 11:49 AM
It looks like this: