LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event call between Two VI - Bidirectional


@Artem.SPb wrote:

You've asked about LV-event and haven't say about "external software".
You can't use user-events for communicate between 2 apps, even if both are LV-apps.
So, say real and full structure of your "system"?


He did mention TCP/IP communication (to another device is implied)... I think it was just a misunderstanding. He's communicating TCP/IP, and taught I advised to use a channel wire in stead of TCPIP. I didn't.

 

You can use a channel wire to communicate between two VIs... Even bi-directional, but you might want to use two directional channel wires. At least some channel wires can be used with event structures.

0 Kudos
Message 11 of 20
(826 Views)

I am attaching the image which should clarify.

0 Kudos
Message 12 of 20
(825 Views)

@Mark_Yedinak wrote:

@Artem.SPb wrote:

I can't open your vi, because I haven't LV18
Here only draft of communicate between two loops. Both of them can be a subVI (except Panel close event)

event.png


Just to clarify, the sequence frames are not actually needed. Other than identifying each section of code they serve no purpose in the code as the wires will control the actual sequencing of code execution.


I just use the While loop label to give it a name and the subdiagram label to explain what it does.  This extends to all structures, except for case structures, where the label describes what is going on with the case selector and each subdiagram labels describes what happens in each case.

Capture.PNG

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 13 of 20
(821 Views)

Hi Again,

 

So after getting some ideas, I tried to create a SubVi. But now somehow my main VI after starting gets unresponsive and does not fire events dedicated for it. I am attaching both my VI's. Please let me know what could be the problem here.

0 Kudos
Message 14 of 20
(806 Views)

Try to wire your timeout value through all event cases. You set it to the default value of 0 in the #1.Server Event case. This will cause your event loop to run as fast as possible which will consume all of the CPU. You should also make sure that your TCP connection reference is wired in all of your event cases as well.

 

Given that, I would avoid splitting your TCP connection across loops. All of your reads/writes should be in the same loop. I have experienced issues when trying to use the same TCP connection reference in multiple loops. I would also avoid placing doing any TCP communications within your event structure. Everything in an event structure should be code that runs very quickly and is not capable of blocking execution.

 

The subVI that you created will block execution of your upper loop because the upper loop is dependent on the output of your subVI. This is normal dataflow. Your subVI will only complete execution when the Exit event is received.

 

In general, this code is kind of a mess. Both literally and figuratively. You have wires running under structures, way too many bends in your wires, wires flowing backwards. Then from a design/architecture standpoint this code is not structured very well and it is not clear what you are trying to accomplish. It is too disjointed to follow. Will you have multiple clients connecting to your server? If so, this code will only work with a single client at a time. Also, is there a specific reason you have limited the size of your queue? If you cannot process messages fast enough in your loop dequeueing the data your producer will not be able to enqueue anymore requests. New messages would get dropped. I also prefer to use an explicit message to exit loops rather than simply exit when a queue has been released.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 15 of 20
(797 Views)

Hi Mark,

 

As per your statement "The subVI that you created will block execution of your upper loop because the upper loop is dependent on the output of your subVI. This is normal dataflow. Your subVI will only complete execution when the Exit event is received." 

 

I know this is the problem, however I need a solution how can I modify it so that both my events (server and subvi events) are always active on a call. Since I am new to Labview your judgement on my design is accepted. But as of this moment I need a running solution. With time, I am going to change my architecture.

 

Thanks

RG

0 Kudos
Message 16 of 20
(773 Views)

@erraunakgupta wrote:

But as of this moment I need a running solution. With time, I am going to change my architecture.

 


Try channel wires.

 

Channel wires don't follow data flow, so you can create them in a running VI, and pass 'it' to another.

 

If you really don't want to use a channel wire (they are made for this, and will fit in just fine), you have to a) initialize the user event before both BIs are started, and pass the refs to both, or b) initialize them in one and put the reference in some sort of global. That will cause race conditions, so you'd need to ensure it's been set before you read it.

0 Kudos
Message 17 of 20
(758 Views)

What purpose does the subVI have? What specifically are you trying to accomplish. This code is very difficult to follow and determine what exactly you are trying to do. Why are you separating the user events? Why are you separating the TCP communications between two loops? Have you looked at the examples for the producer/consumer pattern? Without a clear picture of what you are actually trying to accomplish it is difficult to give you advice on how to fix the code.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 18 of 20
(755 Views)

Hi Mark,

 

I am going to explain you in detail below what my intentions are:

I have an external client which connects to a specific port number. On the other hand I have a separate Measurement Labview VI which accepts messages as string from this external client, perform some measurements and return an acknowledgement string back to this external client. So I am building an interface server between the two which activates a port for clients to listen.

 

This server needs to accept data from both sides. I want my structure to be like a TCP communication between the external client and my server. For the communication between my server and the measurement VI I want a communication between two VI's (no TCP connection).

 

The server reads and writes from/to the external client. And the server sends and received from my measurement VI. This sub VI is acting as the measurement VI which is communicating with the server bidirectional using Event calls.

 

I hope now it is easy for you to suggest me a simplified structure.

 

Thanks once again for your reply.

RG

0 Kudos
Message 19 of 20
(739 Views)

The first think I'd ask myself is this:

Can I get away with simply receiving, handling, and then sending the reply in a sequence? Is this asynchronous construction on the server side really needed? Will the device be sending messages while waiting for a response to it's previous messages?

 

If not, why go though all the trouble? Keep it simple, make a sequence.

 

If it is needed, the 1st reply works. Each sequence structure can be turned into a subVI. The sequence structures can then be deleted.

 

If you want the user even creation in  the subVIs, either use a global buffer or channel wires.

0 Kudos
Message 20 of 20
(730 Views)