Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a variable from one program into another

Tags:

c#

Im not even sure how to ask this question, but i'll give it a shot.

I have a program in c# which reads in values from sensors on a manufacturing line that are indicative of the line health. These values update every 500 milisecconds. I have four lines that this is done for. I would like to write a "overview" program which will be able to access these values over the network to give a good summary on how the factory is doing. My question is how do I get the values from the c# programs on the line to the c# overview program realtime?

If my question doesnt make much sense, let me know and I'll try to rephrase it.

Thanks!

like image 303
user1003131 Avatar asked Jan 17 '23 09:01

user1003131


2 Answers

You have several options:

  • MSMQ

Write the messages in MSMQ (Microsoft Message Queuing). This is an (optionally) persistent and fast store for transporting messages between machines. Since you say that you need the messages in the other app in near realtime, then it makes sense to use MSMQ because you do not want to write logic in that app for handling large amounts of incoming messages. Keep the MSMQ in the middle and take out what you need and most importantly when you can.

  • WCF

The other app could expose a WCF service which can be called by your realtime app each time there's data available. The endpoint could be over net.tcp, meaning low overhead, especially if you send small messages.

Other options include what has been said before: database, file, etc. So you can make your choice between a wide variety of options.

like image 157
Marcel N. Avatar answered Jan 28 '23 16:01

Marcel N.


It depends on a number of things, I would say. First of all, is it just the last value of each line that is interesting for the 'overview' application or do you need multiple values to determine line health or do you perhaps want to have a history of values?

If you're only interested in the last value, I would directly communicate this value to the overview app. As suggested by others, you have numerous possibilities here:

  • Raw TCP using TcpClient (may be a bit too low-level).
  • Expose a http endpoint on the overview application (maybe it's a web application) and post new values to this endpoint.
  • Use WCF to expose some endpoint (named pipes, net.tcp, http, etc.) on the overview application and call this endpoint from each client application.
  • Use MSMQ to have each client enqueue messages that are then picked up by the overview app (also directly supported by WCF).

If you need some history of values or you need multiple values to determine line health, I would go with a database solution. Then again you have to choose: does each client write to the database or does each client post to the overview app (using any of the communication means described above) and does the overview app write to the database.

Without knowing any more constraints for your situation, it's hard to decide between any of these.

like image 22
Ronald Wildenberg Avatar answered Jan 28 '23 16:01

Ronald Wildenberg