LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make server and client use the same file at the same time?thank you

I have completed a program to realize this task:
  collect some data via RS232C ,and write real time data to  file  as  .txt  format

22:38:27 001  5.736E+2, 002  4.539E+3, 003  No Senso, 004  No Senso, 005  No Senso, 006  No
Senso, 001  2.728E+2, 002  No Senso, 003  No Senso, 004  No Senso, 005  No Senso, 006  No
Senso,
22:38:28 001  5.756E+2, 002  4.544E+3, 003  No Senso, 004  No Senso, 005  No Senso, 006  No
Senso, 001  2.728E+2, 002  No Senso, 003  No Senso, 004  No Senso, 005  No Senso, 006  No
Senso,
we can define this sample PC as "server",  and the completed sample program is named as
"sample main program"

now,there is another task to realize:wirte another program to display the real time data in
other client PC. The client PC and the server PC is connected by ethnet

Now the problem is that: how to realize the data communication between client PC and Server PC? Sharing date file may be a good solution.But there is a problem:if the server PC is writing data to the sharing file, the client PC can not read this file at the same time. How to deal with this problem?
Thank you for helping me
my email:lct0811-1@126.com
 
 
 
 
 


帖子被lct0811在02-02-2008 02:28 AM时编辑过了
0 Kudos
Message 1 of 8
(4,637 Views)
well, all you need to do is write a "real" server.

open a tcp socket on the server side, and listen to incoming connections. on the client side, open a tcp socket and connect to the server. once the server sees the client, output the data to the socket and not to a file.

read the documentation about the TCP support library. also, look in the samples folder in the installation directory of CVI (typically "c:\program files\national instruments\cvi81\samples"). the "tcp" sample would be a good starting point.

if you still need the data written into a file on the server side, then you can write it both to a file and to the socket.
0 Kudos
Message 2 of 8
(4,618 Views)
ok, I will see the samples about TCP&UDP
There are several samples in the "NI Sample finder" ,which is more useful for my task, could you commend the sample project
thanks!
0 Kudos
Message 3 of 8
(4,604 Views)
in NIExampleFinder, in the "Networking/TCP&UDP" category, you should start with "client.prj" and "server.prj": those 2 projects shows the basics of implementing a tcp socket and are plainly sufficient for the task you describe.

later on, if you need multiple clients connecting to one server, you might want to look at "MultiClientServer.prj" (the client do not need any modification to run with a multi-client server).
0 Kudos
Message 4 of 8
(4,595 Views)

Hello,

 

Also from the CVI samples, I use datasocket. While this is all NI non-standard communication, it works very easy when you build the "writer"  as well as the "reader"  wtih CVI. The samples are \samples\datasocket\reader and \samples\datasocket\writer.

Both reader and writer are client programs. The writer starts a (local) server. You will see it - and can access it - as an icon on the taskbar. On this server, it makes a connection for your dataset. And subsequently it updates the values of the dataset on the server.

The reader in (in auto-mode) gets a signal from the server when the dataset is updated. Subsequently it can retrieve the new dataset from the server.

Nice about datasocket is that the server is a stand-alone background-application by NI. For reader as well as writer you have only to programme read/write update. And the server works when there are 2 or 3 readers; or when there is no reader. Note that there maybe no reader; or maybe a network error. Make your log-file as part of the sensor acquisition programme.

 

Succes, Jos

 

 

0 Kudos
Message 5 of 8
(4,581 Views)
I have finished this program using the DataSocket server and realize the task. My program is very simple. The server program can share the data(by means of string) with more than 2 client PC. THe client PC is read-auto attribute.
 
 
 
"Make your log-file as part of the sensor acquisition programme." How can i undetsand this sentense? Could you say something in detail?Thank you very much.
0 Kudos
Message 6 of 8
(4,406 Views)
Hello,
 
You now - probably - have a programme that does the data acquisition and posts the results (as a string) to the data socket server. You have also a second programme - on remote PC's - that reads this string. Maybe this is sufficient for your application.
However you are not sure that these remote PC's are active or that there is never a network error. So if you need to have a log-file with all data, make this logging function as part of the programme that does the data acquisition.
 
Minor additions: If I use datasocket, the string/data that I send always includes a timestamp (YYYY-MM-DD hh:mm:ss ..... ...... .....). If there is an error on the computer that does the data acquistion while the datasocket server works fine, I recognize this as an unexpected-old timestamp.
I do use datasocket to send single data, but mostly send (long) strings with multiple data including the timestamp. As I make writer and reader, I know exactly how to retrieve this timestamp and other data frim this string.
For "general purpose" I have made a set of functions that converts a panel to a BMP-format and send this data to the server. With a BMP-datasocket-reader I display the panel on remote PC's. While the data stream is huge with respect to important data, I have a single tool that works always assuming that the data-acquisition panel shows al relevant information. Because of the huge overhead, I do this only if I have to send data once in 10 seconds or once in a minute.
For dedicated applications with fast data update, it seems the best choice to make also a dedicated datasocket writer and reader. I have noticed in the newest versions of LabWindows, that it is possible to connect a control to datasocket (datasocket binding). I have never used it yet, but I expect that e.g. you can export the data that is send to a graph-control or numerical-control automatically to the datasocket server. And/or maybe it can on the remote PC automatically import data from the datasocket server and display it in a similar control.
 
 
Regards, Jos
 
 
0 Kudos
Message 7 of 8
(4,391 Views)

OK

I have add the timestamp in front of my data string. And the reader PC will check the timestr update using a Timer COntrl..IF the timestr is not updated, the reader PC will Popup a message.

Thank you for your help.

0 Kudos
Message 8 of 8
(4,364 Views)