02-19-2019 02:46 PM
@Mancho00 wrote:
The problem is you are constantly updating client and server with the value of the controls (with a race condition mixed in on the client side). You should only send an update when the value has changed.
Now if someone had warned about that issue...
Quoting from post #5 in this thread
"Treating both A and B as peers will crate the possibility of a race condition if the two fight over what the state of the buttons should be."
Ben
02-19-2019 07:49 PM
Hello, I have tried to make a server/client pair using the TCP connection functions in LabVIEW. In the attached VI's, the top loop is my attempt at establishing a dual connection that I know will not work because of the race that is being run sending the boolean signal between the two programs. I have tried event structures, case structures, and a few other ideas to isolate the read and write of the signal that is being passes but have not been successful. As well, I do not understand how the notifiers and semaphores work so I am hoping someone can help me fix this connection issue.
In the code below, the top while loop is where I would like someone to help me establish the ideal way to get the communication to work.
In the bottom while loop, all it does is if the boolean is true, then the server will begin counting from 1 to 10 and if the boolean is false, the client will count from 1 to 10. The boolean must read the same value at all times (except of course the amount of time for the signal to change the other one). As well, both buttons need to be able to be pressed and the change recognized by the other.
02-19-2019 09:28 PM
You are concentrating on the "how", but have not clearly explained (so that I can understand it, at least) the "what". As in "What are you trying to do?". You obviously have two machines, running two programs. Describe the two programs, say (in "broad strokes") what they do, and describe their interaction. Is one running on a Real-Time system or otherwise connected to the "outside world" (and collecting data or controlling some equipment)? Is the other program a Controller/Displayer/Analyzer/Storer of Data?
Are there important constraints involving the two programs? Describe any timing/frequency/etc. relationships between the two systems.
It is often easier to "Design from the Top Down", rather than from the Bottom Up. I notice your code is developed using LabVIEW 2014 -- is that the LabVIEW Version you want to use for this Project?
Bob Schor
02-19-2019 09:56 PM
Sorry for the lack of the what. As you pointed out, there are two programs on different computers. One of them will be moving around some mechanical pieces and the other one will be collecting data. I have put in the numeric loops for simplicity because the loops that are in my actual programs are extremely large and messy. The most important thing is that when the mechanical VI is running, then collection VI must not be running and when the data collection VI is running, the mechanical VI must not run. This is why I need a way for the Boolean controls to always read the same T/F value regardless of which one is pressed.
Hopefully this clears things up.
Thanks!
02-19-2019 10:10 PM
Is one program more in control than the other one? If both say they want to do something at the same time, which one determines who gets to their job when? It sounds like it has to be a master/slave relationship, or better terminology, a "server" and a "client". Which ever one is more important should be the server. When the client wants to do its job, it needs to request permission from the server. Then the server side can stop what its doing when its ready, and send permission back to the client. When the client gets permission, it does what it needs to and is required to tell the server when its done.
Don't think of it as a race between the two. Let the more significant process be in charge and let it be the server. Don't think of it as a "dual" connection. I'm not even sure what that phrase means.
02-19-2019 10:21 PM
I think this solution sounds like it would work for my setup, but I do not know how to "request permission from the server". I am only aware of how to read/write using the TCP connection which seems like it is enforced rather than requested. Is there a built in function somewhere which would do this in LabVIEW or is it some combination of the TCP options?
Thanks!
02-19-2019 11:53 PM
You determine what that means! All TCP/IP communication is based on strings. So client opens a connection and literally writes "I want to do X". When server is ready, it writes back "OK, Go ahead and do X". When client is done, it writes to server "I am done with X". Server responds "Thanks, I hear you". At each step of the conversation, both sides will know whatever state they are in and can then go about doing their business or not doing their business every step whatever that business may be.
Make the text whatever you want it to actually say.
02-20-2019 09:51 AM
I understand that the race condition is occuring, but I do not know how to have both the client and server send and wait for the signal only at the time when it should be sent. I have tried using event structures, but nothing triggers the event structure on the receiving side. Can you point me to an example of how to do this?
Thanks!
02-20-2019 09:58 AM
Create a User Event and use the ref of that User event to a dynamic event registration terminal for your event structure.
When the "Boolean change" messages is received via TCP, use the User Event ref to fire an event.
The Event structure can react to the event and act as required.
Ben
02-20-2019 10:43 AM
Wait a minute, you've gone and created a whole new thread here when you were already discussing your issue in another thread. This makes me feel like I wasted my time.
I'm going to merge this thread into the original. It seems like some of what I have said was already stated to you in the original thread. I don't know why you didn't pay attention to that advice and decided to create a whole new thread!