LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Tcp server/client question

Its more of a design issue.

My device talks tcp/ip so I am using CVI TCP library for this. The device
expects something like
"CmdNo, CmdData", and responds with "SameCmdNo, Response". Now in addition,
the device sends un-solicted status messages, like "StatusCmdNo, Status
Response". All information is binary (liek first byte is comamnd no,
followed by fixed data bytes), I am using text for illustration purposes
only.

I am developing a library to interface to this device. Now in the library I
will func1 which when called needs to send command1 and wait for the
response and return. Another func2 will send command2 and wait for response.
To keep things simple, only 1 function will be called at 1 time. In
addition, when status message comes from dev
ice, I need to let user of my
library know about it, so I am thinking of using callbacks for that.

Now question is:

Under TcpCallBack, I will read data when DATA Ready event kicks in. If it is
status message, I will call user defined callback to give him status info.

In Func1 code, I do something:

Send command1 and data bytes
Now how do I sit here wait for the response for this command, as TCP
callbacks will automatically get called when DATA is ready. so how I do
transfer data received for response to command1, from TcpCallback back to
this point in Func1.

I am just looking for what is a better way to handle this. I know I can use
some global buffers, flags to transfer data. Later I will have to convert
this library to multi-threaded where multiple commands will be sent to
device before responses come back.


vishi
0 Kudos
Message 1 of 2
(2,582 Views)
Hello,

1)I think you can use a global variable to read or not from inside your callback. ( or instead of a global variable a static variable passed as CallbackData ). So, inside the callback you can read or not.

2) if you prefer to read always you can do a loop with ProcessSystemEvents call and wait for a global variable.
0 Kudos
Message 2 of 2
(2,582 Views)